CMakeLists.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. cmake_minimum_required(VERSION 3.25)
  2. project(core)
  3. set(CMAKE_C_STANDARD 23)
  4. set(SRC
  5. "src/BitArray.c"
  6. "src/Box.c"
  7. "src/Buffer.c"
  8. "src/Frustum.c"
  9. "src/LinkedList.c"
  10. "src/List.c"
  11. "src/Logger.c"
  12. "src/Matrix.c"
  13. "src/Plane.c"
  14. "src/Quaternion.c"
  15. "src/Random.c"
  16. "src/SpinLock.c"
  17. "src/Utility.c"
  18. "src/Vector.c"
  19. "src/View.c"
  20. )
  21. set(SRC_TESTS
  22. "test/Main.c"
  23. "test/Test.c"
  24. "test/modules/BitArrayTests.c"
  25. "test/modules/BoxTests.c"
  26. "test/modules/BufferTests.c"
  27. "test/modules/FrustumTests.c"
  28. "test/modules/LinkedListTests.c"
  29. "test/modules/ListTests.c"
  30. "test/modules/MatrixTests.c"
  31. "test/modules/PlaneTests.c"
  32. "test/modules/QuaternionTests.c"
  33. "test/modules/RandomTests.c"
  34. "test/modules/SpinLockTests.c"
  35. "test/modules/UtilityTests.c"
  36. "test/modules/VectorTests.c"
  37. "test/modules/ViewTests.c"
  38. #"test/modules/ComponentsTests.cpp"
  39. #"test/modules/HashMapTests.cpp"
  40. #"test/modules/RingBufferTests.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. set(DEFINITIONS "")
  51. else()
  52. set(DEFINITIONS ERROR_SIMULATOR CORE_CHECK_MEMORY)
  53. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  54. set(COMPILE_OPTIONS --coverage)
  55. set(LINK_OPTIONS gcov)
  56. elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  57. set(COMPILE_OPTIONS -fprofile-instr-generate -fcoverage-mapping)
  58. set(LINK_OPTIONS ${COMPILE_OPTIONS})
  59. endif()
  60. set(LOG_LEVEL 4)
  61. list(APPEND SRC "src/ErrorSimulator.c")
  62. endif()
  63. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  64. include("cmake/gcc_warnings.cmake")
  65. set(DEFINITIONS ${DEFINITIONS}
  66. bool=_Bool
  67. true=1
  68. false=0
  69. nullptr=0
  70. static_assert=_Static_assert
  71. )
  72. elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  73. include("cmake/clang_warnings.cmake")
  74. endif()
  75. add_library(core STATIC ${SRC})
  76. target_compile_options(core PUBLIC
  77. ${COMPILE_OPTIONS}
  78. ${WARNINGS}
  79. -fdiagnostics-color=always
  80. )
  81. target_compile_definitions(core
  82. PUBLIC CORE_LOG_LEVEL=${LOG_LEVEL}
  83. PRIVATE ${DEFINITIONS}
  84. )
  85. target_link_libraries(core
  86. PRIVATE m ${LINK_OPTIONS}
  87. )
  88. target_sources(core PUBLIC
  89. FILE_SET HEADERS
  90. BASE_DIRS include
  91. FILES
  92. ./include/core/BitArray.h
  93. ./include/core/Box.h
  94. ./include/core/Buffer.h
  95. ./include/core/Check.h
  96. ./include/core/Frustum.h
  97. ./include/core/LinkedList.h
  98. ./include/core/List.h
  99. ./include/core/Logger.h
  100. ./include/core/Matrix.h
  101. ./include/core/Plane.h
  102. ./include/core/Quaternion.h
  103. ./include/core/Random.h
  104. ./include/core/SpinLock.h
  105. ./include/core/Types.h
  106. ./include/core/Utility.h
  107. ./include/core/Vector.h
  108. ./include/core/View.h
  109. # ./include/core/Components.hpp
  110. # ./include/core/HashMap.hpp
  111. # ./include/core/ProbingHashMap.hpp
  112. # ./include/core/RingBuffer.hpp
  113. )
  114. install(TARGETS core FILE_SET HEADERS)
  115. add_executable(test ${SRC_TESTS})
  116. target_link_libraries(test PRIVATE core)
  117. target_compile_definitions(test PRIVATE ${DEFINITIONS})
  118. #add_executable(performance ${SRC_PERFORMANCE})
  119. #target_link_libraries(performance PRIVATE core)