CMakeLists.txt 3.6 KB

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