CMakeLists.txt 3.3 KB

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