CMakeLists.txt 3.3 KB

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