CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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/Quaternion.c"
  9. "src/Random.c"
  10. "src/Utility.c"
  11. "src/Vector.c"
  12. #"src/BitArray.cpp"
  13. #"src/Box.cpp"
  14. #"src/Frustum.cpp"
  15. #"src/Plane.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/QuaternionTests.c"
  25. "test/modules/RandomTests.c"
  26. "test/modules/UtilityTests.c"
  27. "test/modules/VectorTests.c"
  28. #"test/modules/BitArrayTests.cpp"
  29. #"test/modules/BoxTests.cpp"
  30. #"test/modules/ComponentsTests.cpp"
  31. #"test/modules/FrustumTests.cpp"
  32. #"test/modules/HashMapTests.cpp"
  33. #"test/modules/LinkedListTests.cpp"
  34. #"test/modules/ListTests.cpp"
  35. #"test/modules/MatrixStackTests.cpp"
  36. #"test/modules/PlaneTests.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. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  51. set(DEFINITIONS bool=_Bool true=1 false=0 nullptr=0 static_assert=_Static_assert)
  52. else()
  53. set(DEFINITIONS "")
  54. endif()
  55. else()
  56. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  57. set(COMPILE_OPTIONS --coverage)
  58. set(LINK_OPTIONS gcov)
  59. set(DEFINITIONS ERROR_SIMULATOR CORE_CHECK_MEMORY bool=_Bool true=1 false=0 nullptr=0 static_assert=_Static_assert)
  60. else()
  61. set(COMPILE_OPTIONS -fprofile-instr-generate -fcoverage-mapping)
  62. set(LINK_OPTIONS ${COMPILE_OPTIONS})
  63. set(DEFINITIONS ERROR_SIMULATOR CORE_CHECK_MEMORY)
  64. endif()
  65. set(LOG_LEVEL 4)
  66. list(APPEND SRC "src/ErrorSimulator.c")
  67. endif()
  68. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  69. set(MORE_WARNINGS
  70. -Walloc-zero
  71. -Wanalyzer-too-complex
  72. -Warith-conversion
  73. -Warray-bounds=2
  74. -Wattribute-alias=2
  75. -Wbidi-chars=any
  76. -Wcast-align=strict
  77. -Wduplicated-branches
  78. -Wduplicated-cond
  79. -Wformat-overflow=2
  80. -Wformat-signedness
  81. -Wformat-truncation=2
  82. -Wimplicit-fallthrough=5
  83. -Wjump-misses-init
  84. -Wlogical-op
  85. -Wnormalized=nfkc
  86. -Wshift-overflow=2
  87. -Wstack-usage=8388608
  88. -Wstringop-overflow=4
  89. -Wtrampolines
  90. -Wtrivial-auto-var-init
  91. -Wunused-const-variable=2
  92. -Wuse-after-free=3
  93. )
  94. endif()
  95. add_library(core STATIC ${SRC})
  96. target_compile_options(core PUBLIC
  97. ${COMPILE_OPTIONS}
  98. -Wall
  99. -Walloca
  100. -Warray-parameter
  101. -Wbad-function-cast
  102. -Wcast-qual
  103. -Wconversion
  104. -Wdate-time
  105. -Wdisabled-optimization
  106. -Wdouble-promotion
  107. -Wenum-compare
  108. -Wenum-conversion
  109. -Werror
  110. -Wextra
  111. -Wfloat-equal
  112. -Wformat=2
  113. -Wframe-larger-than=8388608
  114. -Winfinite-recursion
  115. -Winit-self
  116. -Winvalid-pch
  117. -Wlarger-than=1073741824
  118. -Wmissing-braces
  119. -Wmissing-declarations
  120. -Wmissing-include-dirs
  121. -Wmissing-prototypes
  122. -Wmultichar
  123. -Wnarrowing
  124. -Wnested-externs
  125. -Wnull-dereference
  126. -Wold-style-definition
  127. -Woverlength-strings
  128. -Wredundant-decls
  129. -Wshadow
  130. -Wsign-conversion
  131. -Wstack-protector
  132. -Wstrict-overflow=2
  133. -Wstrict-prototypes
  134. -Wswitch-enum
  135. -Wundef
  136. -Wunreachable-code
  137. -Wvla
  138. -Wwrite-strings
  139. -fdiagnostics-color=always
  140. -pedantic
  141. -pedantic-errors
  142. ${MORE_WARNINGS}
  143. )
  144. target_compile_definitions(core
  145. PUBLIC CORE_LOG_LEVEL=${LOG_LEVEL}
  146. PRIVATE ${DEFINITIONS}
  147. )
  148. target_link_libraries(core
  149. PRIVATE m ${LINK_OPTIONS}
  150. )
  151. target_sources(core PUBLIC
  152. FILE_SET HEADERS
  153. BASE_DIRS include
  154. FILES
  155. ./include/core/Buffer.h
  156. ./include/core/Check.h
  157. ./include/core/Logger.h
  158. ./include/core/Matrix.h
  159. ./include/core/Quaternion.h
  160. ./include/core/Random.h
  161. ./include/core/Types.h
  162. ./include/core/Utility.h
  163. # ./include/core/BitArray.hpp
  164. # ./include/core/Box.hpp
  165. # ./include/core/Components.hpp
  166. # ./include/core/Frustum.hpp
  167. # ./include/core/HashMap.hpp
  168. # ./include/core/LinkedList.hpp
  169. # ./include/core/List.hpp
  170. # ./include/core/MatrixStack.hpp
  171. # ./include/core/Plane.hpp
  172. # ./include/core/ProbingHashMap.hpp
  173. # ./include/core/RingBuffer.hpp
  174. # ./include/core/Stack.hpp
  175. # ./include/core/Vector.hpp
  176. # ./include/core/View.hpp
  177. )
  178. install(TARGETS core FILE_SET HEADERS)
  179. add_executable(test ${SRC_TESTS})
  180. target_link_libraries(test PRIVATE core)
  181. target_compile_definitions(test PRIVATE ${DEFINITIONS})
  182. #add_executable(performance ${SRC_PERFORMANCE})
  183. #target_link_libraries(performance PRIVATE core)