Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/tests/CMakeLists.txt
T

248 lines
12 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)
if(QT6_GUI_AVAILABLE)
# Check if targets already exist from parent CMakeLists.txt
if(TARGET Qt6::Core AND TARGET Qt6::Gui AND TARGET Qt6::Widgets AND TARGET Qt6::Test)
# Already found by parent - use existing targets
elseif(NOT TARGET Qt6::Gui OR NOT TARGET Qt6::Widgets)
# Manual fallback: create imported targets when standard find fails due to OpenGL
if(NOT TARGET Qt6::Gui)
add_library(Qt6::Gui SHARED IMPORTED)
set_target_properties(Qt6::Gui PROPERTIES
IMPORTED_LOCATION "/usr/lib/x86_64-linux-gnu/libQt6Gui.so.6"
INTERFACE_INCLUDE_DIRECTORIES "/usr/include/x86_64-linux-gnu/qt6/QtGui;/usr/include/x86_64-linux-gnu/qt6"
)
endif()
if(NOT TARGET Qt6::Widgets)
add_library(Qt6::Widgets SHARED IMPORTED)
set_target_properties(Qt6::Widgets PROPERTIES
IMPORTED_LOCATION "/usr/lib/x86_64-linux-gnu/libQt6Widgets.so.6"
INTERFACE_INCLUDE_DIRECTORIES "/usr/include/x86_64-linux-gnu/qt6/QtWidgets;/usr/include/x86_64-linux-gnu/qt6"
INTERFACE_LINK_LIBRARIES "Qt6::Gui;Qt6::Core"
)
endif()
else()
# Try standard find_package first, fall back to manual targets if OpenGL missing
find_package(Qt6 QUIET COMPONENTS Core Gui Widgets Test)
endif()
# Ensure Core and Test are found
if(NOT TARGET Qt6::Core)
find_package(Qt6 REQUIRED COMPONENTS Core Test)
endif()
else()
if(NOT TARGET Qt6::Core OR NOT TARGET Qt6::Test)
find_package(Qt6 REQUIRED COMPONENTS Core Test)
endif()
endif()
# Nur bauen wenn BUILD_TESTING aktiviert ist
if(BUILD_TESTING)
# 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()
# 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})
# Exclude tests for non-existent or commented-out components
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_lts_app_descriptor_editor\\.cpp")
# test_lts_app_descriptor.cpp utilise QTEST_MAIN (framework QtTest) : il fournit
# son propre main(), qui prend le pas sur GTest::gtest_main et fait echouer la
# decouverte des tests. Un binaire QtTest et un binaire gtest ne se melangent pas.
# A rebatir comme executable QtTest autonome si sa couverture est souhaitee.
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_lts_app_descriptor\\.cpp")
# test_GrantleeParserSmoke.cpp est un doublon-souche : il inclut
# Lts/Common/CodeGen/GrantleeParserSmoke.h, qui n'a jamais existe, et ne contient
# que des EXPECT_TRUE(true). Le vrai smoke test est l'executable autonome
# grantlee_parser_smoke (Lts/Common/CodeGen/tests/GrantleeParserSmoke.cpp,
# add_test NAME GrantleeParserSmoke). Aucune couverture perdue.
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_GrantleeParserSmoke\\.cpp")
# test_migration_stubs.cpp valide les en-tetes STUB (namespace DDS::Core::Interface,
# DDS::DTC, ...) qui n'existent que si BUILD_RTI=OFF. Avec BUILD_RTI=ON les stubs
# sont contournes au profit des vrais en-tetes : ce test ne peut pas compiler.
if(BUILD_RTI)
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_migration_stubs\\.cpp")
# test_build_rti_guards.cpp affirme EXPECT_FALSE(rti_available) : il valide
# le repli BUILD_RTI=OFF et echoue par construction quand RTI est actif.
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_build_rti_guards\\.cpp")
endif()
# Exclude Grantlee-related tests when BUILD_GRANTLEE is OFF
if(NOT BUILD_GRANTLEE)
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_.*Grantlee.*\\.cpp")
message(STATUS "Migration tests: Grantlee support disabled (BUILD_GRANTLEE=OFF), excluded Grantlee tests")
endif()
# Exclude CodeGen tests when CodeGen targets aren't available (MIGRATE_MODULE restricts scope)
if(NOT TARGET codegen_base)
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_StructBuilder\\.cpp")
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_SqlGenerator\\.cpp")
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_XmlReader\\.cpp")
message(STATUS "Migration tests: CodeGen targets not available, excluded CodeGen tests")
endif()
# Exclude LtsTimelineClassic tests when LtsTimelineClassic target isn't available
if(NOT TARGET LtsTimelineClassic)
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_abstracttimelinemodel\\.cpp")
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_ltsclassicdatamodel\\.cpp")
list(FILTER EXISTING_SOURCES EXCLUDE REGEX "test_ltsclassicfilterproxymodel\\.cpp")
message(STATUS "Migration tests: LtsTimelineClassic target not available, excluded LtsTimelineClassic tests")
endif()
if(NOT EXISTING_SOURCES)
message(WARNING "No migration test sources found after filtering - skipping migration_tests target")
return()
endif()
# Le CMakeLists racine pose -DQT_NO_CAST_FROM_ASCII (CMakeLists.txt:546) pour
# interdire les conversions implicites const char* -> QString dans le code de
# production. Plusieurs tests (test_qt6_api_migrations, test_qt6_compatibility)
# ont justement pour objet d'exercer ces conversions : les reecrire en
# QStringLiteral changerait ce qu'ils verifient. On leve donc le garde pour ce
# repertoire de tests uniquement ; le code de production reste protege.
get_directory_property(_migtest_defs COMPILE_DEFINITIONS)
if(_migtest_defs)
list(REMOVE_ITEM _migtest_defs QT_NO_CAST_FROM_ASCII)
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${_migtest_defs}")
endif()
# main() maison : cree la QApplication requise par les tests de widgets
list(APPEND EXISTING_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/gtest_qt_main.cpp")
add_executable(migration_tests ${EXISTING_SOURCES})
# test_export_headers.cpp verifie la presence d'en-tetes generes : il doit
# connaitre le nom reel du repertoire de build (il supposait "build").
target_compile_definitions(migration_tests PRIVATE
MIGRATION_TESTS_BUILD_DIR="${CMAKE_BINARY_DIR}")
# Enable Qt Meta-Object Compiler for tests with Q_OBJECT
set_target_properties(migration_tests PROPERTIES AUTOMOC ON)
target_compile_features(migration_tests PRIVATE cxx_std_23)
target_include_directories(migration_tests PRIVATE
# CMAKE_SOURCE_DIR vaut deja .../qt6-after/qt6-migrated-legatus : les
# variantes prefixees une seconde fois pointaient dans le vide (les deux
# premieres doublonnaient d'ailleurs les lignes ci-dessus).
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/DDS
# En-tetes generes, inclus sous forme qualifiee par service
# (ex. <ProjectDataManagement/pdm_types.h>, <AlarmManagement/alm_dtc.h>).
${CMAKE_SOURCE_DIR}/Lts
${CMAKE_BINARY_DIR}/Lts
${CMAKE_BINARY_DIR}/Lts/Services
${CMAKE_BINARY_DIR}/Lts/Proxies
${CMAKE_BINARY_DIR}/Lts/DDS
${CMAKE_BINARY_DIR}/Lts/Common
${CMAKE_BINARY_DIR}/Lts/Common/CodeGen
${CMAKE_BINARY_DIR}/Lts/Common/LtsTimeline
${CMAKE_BINARY_DIR}/Lts/Common/LtsTimelineClassic
)
# Les en-tetes *_export.h generes sont inclus sous forme nue
# (ex. <ismshared_export.h>) et vivent chacun dans le repertoire de build
# de leur cible : une centaine de repertoires. On les collecte au lieu de
# les enumerer. GLOB est evalue a la configuration, apres generate_export_header.
file(GLOB_RECURSE _migtest_export_headers "${CMAKE_BINARY_DIR}/*_export.h")
set(_migtest_export_dirs "")
foreach(_h IN LISTS _migtest_export_headers)
get_filename_component(_d "${_h}" DIRECTORY)
list(APPEND _migtest_export_dirs "${_d}")
endforeach()
list(REMOVE_DUPLICATES _migtest_export_dirs)
list(LENGTH _migtest_export_dirs _migtest_export_count)
message(STATUS "Migration tests: ${_migtest_export_count} repertoires d'en-tetes _export.h")
target_include_directories(migration_tests PRIVATE ${_migtest_export_dirs})
# NGLLogger exporte Z/src/NGLLogger en PUBLIC : c'est le repertoire de
# NGLLoggerBootstrap.h, inclus par Lts/Common/LtsTimelineClassic/Event.h.
if(TARGET NGLLogger)
target_link_libraries(migration_tests PRIVATE NGLLogger)
else()
message(WARNING "migration_tests: cible NGLLogger absente, "
"les tests LtsTimelineClassic ne compileront pas")
endif()
# Link against Qt6 components
if(QT6_GUI_AVAILABLE)
target_link_libraries(migration_tests PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Widgets
Qt6::Test
GTest::gtest # pas gtest_main : le main() est dans gtest_qt_main.cpp
)
endif()
# Link against LtsTimelineClassic only if it exists (may not exist with MIGRATE_MODULE)
if(TARGET LtsTimelineClassic)
target_link_libraries(migration_tests PRIVATE LtsTimelineClassic)
add_dependencies(migration_tests LtsTimelineClassic)
else()
message(STATUS "LtsTimelineClassic target not available - skipping link (MIGRATE_MODULE may restrict scope)")
endif()
# Grantlee tests require BUILD_GRANTLEE=ON
if(BUILD_GRANTLEE)
target_link_libraries(migration_tests PRIVATE codegen_grantlee)
# KF6::TextTemplate porte les INTERFACE_INCLUDE_DIRECTORIES de
# <ktexttemplate/template.h>, inclus par GeneratorGrantleeBase.h.
# Le FIND_PACKAGE de Lts/Common/CodeGen cree une cible importee limitee
# a ce repertoire : il faut la re-chercher ici pour l'avoir dans ce scope.
find_package(KF6TextTemplate QUIET)
if(TARGET KF6::TextTemplate)
target_link_libraries(migration_tests PRIVATE KF6::TextTemplate)
else()
message(WARNING "migration_tests: KF6::TextTemplate introuvable, "
"les tests Grantlee ne compileront pas")
endif()
# CMAKE_SOURCE_DIR vaut deja .../qt6-after/qt6-migrated-legatus :
# le prefixe repete donnait un chemin inexistant.
target_include_directories(migration_tests PRIVATE
${CMAKE_SOURCE_DIR}/Lts/Common/CodeGen
)
message(STATUS "Migration tests: Grantlee support enabled")
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()