CMakeLists.txt 3.5 KB

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