CMakeLists.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. cmake_minimum_required(VERSION 3.28)
  2. project(core LANGUAGES CXX)
  3. set(CMAKE_CXX_STANDARD 23)
  4. set(PRIVATE_MODULES
  5. "src/ErrorSimulator.cppm"
  6. )
  7. set(SRC
  8. "src/BitArray.cpp"
  9. "src/Box.cpp"
  10. "src/Buffer.cpp"
  11. "src/Clock.cpp"
  12. "src/CustomNewDelete.cpp"
  13. "src/File.cpp"
  14. "src/Frustum.cpp"
  15. "src/Logger.cpp"
  16. "src/Matrix.cpp"
  17. "src/Plane.cpp"
  18. "src/Quaternion.cpp"
  19. "src/Random.cpp"
  20. "src/ReadLine.cpp"
  21. "src/Terminal.cpp"
  22. "src/Test.cpp"
  23. "src/Thread.cpp"
  24. "src/ToString.cpp"
  25. "src/Unicode.cpp"
  26. "src/Utility.cpp"
  27. "src/Vector.cpp"
  28. "src/View.cpp"
  29. )
  30. set(SRC_TESTS
  31. "test/Main.cpp"
  32. "test/modules/ArrayListTests.cpp"
  33. "test/modules/ArrayTests.cpp"
  34. "test/modules/BitArrayTests.cpp"
  35. "test/modules/BoxTests.cpp"
  36. "test/modules/BufferTests.cpp"
  37. "test/modules/ClockTests.cpp"
  38. "test/modules/ColorTests.cpp"
  39. "test/modules/ComponentsTests.cpp"
  40. "test/modules/FileTests.cpp"
  41. "test/modules/FrustumTests.cpp"
  42. "test/modules/HashMapTests.cpp"
  43. "test/modules/HashedStringTests.cpp"
  44. "test/modules/ListTests.cpp"
  45. "test/modules/MathTests.cpp"
  46. "test/modules/MatrixTests.cpp"
  47. "test/modules/PlaneTests.cpp"
  48. "test/modules/QuaternionTests.cpp"
  49. "test/modules/QueueTests.cpp"
  50. "test/modules/RandomTests.cpp"
  51. "test/modules/ReadLineTests.cpp"
  52. "test/modules/TerminalTests.cpp"
  53. "test/modules/TestTests.cpp"
  54. "test/modules/ThreadTests.cpp"
  55. "test/modules/UnicodeTests.cpp"
  56. "test/modules/UniquePointerTests.cpp"
  57. "test/modules/UtilityTests.cpp"
  58. "test/modules/VectorTests.cpp"
  59. "test/modules/ViewTests.cpp"
  60. )
  61. set(SRC_PERFORMANCE
  62. "performance/Main.cpp"
  63. )
  64. if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
  65. set(COMPILE_OPTIONS "")
  66. set(LINK_OPTIONS "")
  67. set(LOG_LEVEL 2)
  68. set(DEFINITIONS CHECK_MEMORY)
  69. elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
  70. set(COMPILE_OPTIONS "")
  71. set(LINK_OPTIONS "")
  72. set(LOG_LEVEL 3)
  73. set(DEFINITIONS CHECK_MEMORY)
  74. else()
  75. set(DEFINITIONS ERROR_SIMULATOR CHECK_MEMORY)
  76. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  77. set(COMPILE_OPTIONS --coverage)
  78. set(LINK_OPTIONS gcov)
  79. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  80. set(COMPILE_OPTIONS -fprofile-instr-generate -fcoverage-mapping)
  81. set(LINK_OPTIONS ${COMPILE_OPTIONS})
  82. endif()
  83. set(LOG_LEVEL 4)
  84. endif()
  85. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  86. include("cmake/gcc_warnings.cmake")
  87. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  88. include("cmake/clang_warnings.cmake")
  89. endif()
  90. include("cmake/add_modules.cmake")
  91. add_library(core STATIC ${SRC})
  92. target_compile_options(core PUBLIC
  93. ${COMPILE_OPTIONS}
  94. ${WARNINGS}
  95. -fdiagnostics-color=always
  96. )
  97. add_modules(
  98. TARGET core
  99. NAME public_modules
  100. FILES ${core_modules}
  101. )
  102. target_sources(core PUBLIC
  103. FILE_SET private_modules
  104. TYPE CXX_MODULES
  105. FILES ${PRIVATE_MODULES}
  106. )
  107. target_compile_definitions(core
  108. PRIVATE LOG_LEVEL=${LOG_LEVEL}
  109. PRIVATE ${DEFINITIONS}
  110. )
  111. target_link_libraries(core
  112. PRIVATE m ${LINK_OPTIONS}
  113. )
  114. install(TARGETS core FILE_SET public_modules DESTINATION .)
  115. install(FILES cmake/add_modules.cmake DESTINATION cmake)
  116. add_executable(test ${SRC_TESTS})
  117. target_sources(test PUBLIC
  118. FILE_SET CXX_MODULES
  119. FILES test/Tests.cppm
  120. )
  121. target_link_libraries(test PRIVATE core)
  122. target_compile_definitions(test PRIVATE ${DEFINITIONS})
  123. target_compile_definitions(test
  124. PRIVATE LOG_LEVEL=4
  125. )
  126. add_executable(performance ${SRC_PERFORMANCE})
  127. target_link_libraries(performance PRIVATE core)
  128. target_compile_definitions(performance PRIVATE ${DEFINITIONS})
  129. target_compile_definitions(performance
  130. PRIVATE LOG_LEVEL=4
  131. )