CMakeLists.txt 5.7 KB

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