CMakeLists.txt 3.3 KB

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