CMakeLists.txt 5.3 KB

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