CMakeLists.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. cmake_minimum_required(VERSION 3.25)
  2. project(core)
  3. set(CMAKE_C_STANDARD 23)
  4. set(SRC
  5. "src/Buffer.c"
  6. "src/Logger.c"
  7. "src/Matrix.c"
  8. "src/Plane.c"
  9. "src/Quaternion.c"
  10. "src/Random.c"
  11. "src/Utility.c"
  12. "src/Vector.c"
  13. #"src/BitArray.cpp"
  14. #"src/Box.cpp"
  15. #"src/Frustum.cpp"
  16. #"src/SpinLock.cpp"
  17. #"src/View.cpp"
  18. )
  19. set(SRC_TESTS
  20. "test/Main.c"
  21. "test/Test.c"
  22. "test/modules/BufferTests.c"
  23. "test/modules/MatrixTests.c"
  24. "test/modules/PlaneTests.c"
  25. "test/modules/QuaternionTests.c"
  26. "test/modules/RandomTests.c"
  27. "test/modules/UtilityTests.c"
  28. "test/modules/VectorTests.c"
  29. #"test/modules/BitArrayTests.cpp"
  30. #"test/modules/BoxTests.cpp"
  31. #"test/modules/ComponentsTests.cpp"
  32. #"test/modules/FrustumTests.cpp"
  33. #"test/modules/HashMapTests.cpp"
  34. #"test/modules/LinkedListTests.cpp"
  35. #"test/modules/ListTests.cpp"
  36. #"test/modules/MatrixStackTests.cpp"
  37. #"test/modules/RingBufferTests.cpp"
  38. #"test/modules/StackTests.cpp"
  39. #"test/modules/ThreadTests.cpp"
  40. #"test/modules/ViewTests.cpp"
  41. )
  42. set(SRC_PERFORMANCE
  43. #"performance/Main.cpp"
  44. #"test/Test.cpp"
  45. )
  46. if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
  47. set(COMPILE_OPTIONS -flto)
  48. set(LINK_OPTIONS -flto)
  49. set(LOG_LEVEL 2)
  50. set(DEFINITIONS "")
  51. else()
  52. set(DEFINITIONS ERROR_SIMULATOR CORE_CHECK_MEMORY)
  53. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  54. set(COMPILE_OPTIONS --coverage)
  55. set(LINK_OPTIONS gcov)
  56. elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  57. set(COMPILE_OPTIONS -fprofile-instr-generate -fcoverage-mapping)
  58. set(LINK_OPTIONS ${COMPILE_OPTIONS})
  59. endif()
  60. set(LOG_LEVEL 4)
  61. list(APPEND SRC "src/ErrorSimulator.c")
  62. endif()
  63. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  64. include("cmake/gcc_warnings.cmake")
  65. set(DEFINITIONS ${DEFINITIONS}
  66. bool=_Bool
  67. true=1
  68. false=0
  69. nullptr=0
  70. static_assert=_Static_assert
  71. )
  72. elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  73. include("cmake/clang_warnings.cmake")
  74. endif()
  75. add_library(core STATIC ${SRC})
  76. target_compile_options(core PUBLIC
  77. ${COMPILE_OPTIONS}
  78. ${WARNINGS}
  79. -fdiagnostics-color=always
  80. )
  81. target_compile_definitions(core
  82. PUBLIC CORE_LOG_LEVEL=${LOG_LEVEL}
  83. PRIVATE ${DEFINITIONS}
  84. )
  85. target_link_libraries(core
  86. PRIVATE m ${LINK_OPTIONS}
  87. )
  88. target_sources(core PUBLIC
  89. FILE_SET HEADERS
  90. BASE_DIRS include
  91. FILES
  92. ./include/core/Buffer.h
  93. ./include/core/Check.h
  94. ./include/core/Logger.h
  95. ./include/core/Matrix.h
  96. ./include/core/Plane.h
  97. ./include/core/Quaternion.h
  98. ./include/core/Random.h
  99. ./include/core/Types.h
  100. ./include/core/Utility.h
  101. # ./include/core/BitArray.hpp
  102. # ./include/core/Box.hpp
  103. # ./include/core/Components.hpp
  104. # ./include/core/Frustum.hpp
  105. # ./include/core/HashMap.hpp
  106. # ./include/core/LinkedList.hpp
  107. # ./include/core/List.hpp
  108. # ./include/core/MatrixStack.hpp
  109. # ./include/core/ProbingHashMap.hpp
  110. # ./include/core/RingBuffer.hpp
  111. # ./include/core/Stack.hpp
  112. # ./include/core/Vector.hpp
  113. # ./include/core/View.hpp
  114. )
  115. install(TARGETS core FILE_SET HEADERS)
  116. add_executable(test ${SRC_TESTS})
  117. target_link_libraries(test PRIVATE core)
  118. target_compile_definitions(test PRIVATE ${DEFINITIONS})
  119. #add_executable(performance ${SRC_PERFORMANCE})
  120. #target_link_libraries(performance PRIVATE core)