- Grantlee-Tests nur bauen wenn BUILD_GRANTLEE=ON - Vermeidet Build-Fehler durch fehlenden codegen_base_export.h bei BUILD_GRANTLEE=OFF - Ermöglicht Build ohne Qt5-basierte Grantlee-Dependency für Qt6-Migration
95 lines
3.7 KiB
CMake
95 lines
3.7 KiB
CMake
# CMakeLists.txt für Qt6-Migrationstests
|
|
# Diese Tests validieren BUILD_RTI Guards, Qt6-Kompatibilität und RTI-Integration
|
|
|
|
cmake_minimum_required(VERSION 3.16)
|
|
|
|
# Qt6 finden (wird vom Hauptprojekt gesetzt, aber sicherheitshalber hier auch)
|
|
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Test)
|
|
|
|
# Try to find system-wide GTest first, fallback to FetchContent
|
|
find_package(GTest QUIET)
|
|
if(NOT TARGET GTest::gtest_main)
|
|
include(FetchContent)
|
|
FetchContent_Declare(
|
|
googletest
|
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
|
GIT_TAG v1.13.0
|
|
)
|
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
FetchContent_MakeAvailable(googletest)
|
|
endif()
|
|
|
|
# Nur bauen wenn BUILD_TESTING aktiviert ist
|
|
if(BUILD_TESTING)
|
|
# Collect all test source files dynamically
|
|
file(GLOB MIGRATION_TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp")
|
|
|
|
if(MIGRATION_TEST_SOURCES)
|
|
set(EXISTING_SOURCES ${MIGRATION_TEST_SOURCES})
|
|
|
|
add_executable(migration_tests ${EXISTING_SOURCES})
|
|
|
|
target_compile_features(migration_tests PRIVATE cxx_std_23)
|
|
|
|
target_include_directories(migration_tests PRIVATE
|
|
${CMAKE_SOURCE_DIR}
|
|
${CMAKE_SOURCE_DIR}/include
|
|
${CMAKE_SOURCE_DIR}/qt6-after/qt6-migrated-legatus
|
|
${CMAKE_SOURCE_DIR}/qt6-after/qt6-migrated-legatus/include
|
|
${CMAKE_BINARY_DIR}/Lts/Common
|
|
)
|
|
|
|
# Link against Qt6 components
|
|
target_link_libraries(migration_tests PRIVATE
|
|
Qt6::Core
|
|
Qt6::Gui
|
|
Qt6::Widgets
|
|
Qt6::Test
|
|
GTest::gtest_main
|
|
)
|
|
|
|
# Grantlee tests require BUILD_GRANTLEE=ON
|
|
if(BUILD_GRANTLEE)
|
|
target_link_libraries(migration_tests PRIVATE codegen_grantlee)
|
|
target_include_directories(migration_tests PRIVATE
|
|
${CMAKE_SOURCE_DIR}/qt6-after/qt6-migrated-legatus/Lts/Common/CodeGen
|
|
)
|
|
message(STATUS "Migration tests: Grantlee support enabled")
|
|
else()
|
|
# Exclude Grantlee-related tests when BUILD_GRANTLEE is OFF
|
|
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_.*Grantlee.*\\.cpp")
|
|
message(STATUS "Migration tests: Grantlee support disabled (BUILD_GRANTLEE=OFF), excluded Grantlee tests")
|
|
# Re-create executable with filtered sources
|
|
if(EXISTING_SOURCES)
|
|
set_target_properties(migration_tests PROPERTIES
|
|
SOURCES "${EXISTING_SOURCES}"
|
|
)
|
|
else()
|
|
message(WARNING "No non-Grantlee migration tests found - skipping migration_tests target")
|
|
return()
|
|
endif()
|
|
endif()
|
|
|
|
# RTI libraries if BUILD_RTI is ON
|
|
if(BUILD_RTI)
|
|
find_package(RTI QUIET)
|
|
if(RTI_FOUND)
|
|
target_include_directories(migration_tests PRIVATE ${RTI_INCLUDE_DIRS})
|
|
target_link_libraries(migration_tests PRIVATE ${RTI_LIBRARIES})
|
|
target_compile_definitions(migration_tests PRIVATE BUILD_RTI=1)
|
|
message(STATUS "RTI found: ${RTI_LIBRARIES}")
|
|
else()
|
|
message(STATUS "BUILD_RTI=ON but RTI not found - building tests without RTI")
|
|
endif()
|
|
endif()
|
|
|
|
# Register with CTest
|
|
include(GoogleTest)
|
|
gtest_discover_tests(migration_tests)
|
|
|
|
message(STATUS "Migration tests enabled: ${EXISTING_SOURCES}")
|
|
else()
|
|
message(WARNING "No migration test sources found in ${CMAKE_CURRENT_SOURCE_DIR}")
|
|
endif()
|
|
endif() |