CMakeLists.txt 4.7 KB

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