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