|
1 | | -# CMakeLists.txt for CxxReflectionTests |
2 | 1 | cmake_minimum_required(VERSION 3.20) |
| 2 | +project(CxxRTLTestApplication LANGUAGES CXX) |
3 | 3 |
|
4 | 4 | set(CMAKE_CXX_STANDARD 20) |
| 5 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
5 | 6 |
|
6 | | -project(CxxRTLTestApplication) |
7 | | - |
8 | | -set(CXX_EXE_NAME CxxRTLTestApplication) |
9 | | -add_executable(${CXX_EXE_NAME} "") |
10 | | - |
11 | | - |
| 7 | +# =============================== |
| 8 | +# Dependencies (GoogleTest) |
| 9 | +# =============================== |
12 | 10 | include(FetchContent) |
| 11 | + |
13 | 12 | FetchContent_Declare( |
14 | 13 | googletest |
15 | 14 | URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip |
16 | 15 | ) |
17 | | -# For Windows: Prevent overriding the parent project's compiler/linker settings |
| 16 | + |
| 17 | +# Prevent GTest from overriding CRT settings on Windows |
18 | 18 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 19 | + |
| 20 | +# Avoid GTest adding its own tests into the solution |
| 21 | +set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) |
| 22 | +set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) |
| 23 | +set(BUILD_GTEST ON CACHE BOOL "" FORCE) |
| 24 | + |
19 | 25 | FetchContent_MakeAvailable(googletest) |
20 | 26 |
|
21 | | -include_directories(inc) |
22 | | -include_directories("${CMAKE_SOURCE_DIR}/CxxTestUtils/inc") |
23 | | -include_directories("${CMAKE_SOURCE_DIR}/CxxRTLTypeRegistration/inc") |
24 | | -include_directories("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/common") |
25 | | -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/detail/inc") |
26 | | -include_directories("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/access/inc") |
27 | | -include_directories("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/builder/inc") |
| 27 | +# =============================== |
| 28 | +# Common Include Paths |
| 29 | +# =============================== |
| 30 | +set(RTL_INCLUDE_DIRS |
| 31 | + inc |
| 32 | + "${CMAKE_SOURCE_DIR}/CxxTestUtils/inc" |
| 33 | + "${CMAKE_SOURCE_DIR}/CxxRTLTypeRegistration/inc" |
| 34 | + "${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/common" |
| 35 | + "${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/detail/inc" |
| 36 | + "${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/access/inc" |
| 37 | + "${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/builder/inc" |
| 38 | +) |
| 39 | + |
| 40 | +# =============================== |
| 41 | +# Test Executable |
| 42 | +# =============================== |
| 43 | +set(CXX_EXE_NAME CxxRTLTestApplication) |
| 44 | + |
| 45 | +# Add all test sources (either glob or include your src/CMakeLists.txt) |
| 46 | +file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS src/*.cpp) |
| 47 | +add_executable(${CXX_EXE_NAME} ${TEST_SOURCES}) |
28 | 48 |
|
29 | | -target_link_libraries(${CXX_EXE_NAME} CxxTestUtils) |
30 | | -target_link_libraries(${CXX_EXE_NAME} GTest::gtest_main) |
31 | | -target_link_libraries(${CXX_EXE_NAME} ReflectionTemplateLib) |
32 | | -target_link_libraries(${CXX_EXE_NAME} CxxRTLTypeRegistration) |
| 49 | +target_include_directories(${CXX_EXE_NAME} PRIVATE ${RTL_INCLUDE_DIRS}) |
33 | 50 |
|
34 | | -# Add the source directory |
35 | | -include(src/CMakeLists.txt) |
| 51 | +target_link_libraries(${CXX_EXE_NAME} |
| 52 | + PRIVATE |
| 53 | + CxxTestUtils |
| 54 | + ReflectionTemplateLib |
| 55 | + CxxRTLTypeRegistration |
| 56 | + GTest::gtest_main |
| 57 | +) |
36 | 58 |
|
| 59 | +# =============================== |
| 60 | +# GoogleTest Integration |
| 61 | +# =============================== |
37 | 62 | include(GoogleTest) |
38 | 63 | gtest_discover_tests(${CXX_EXE_NAME}) |
0 commit comments