Files
qt6-migration-pipeline/Lts/DDS/DdsUnitTestsPlaceholder/CMakeLists.txt
T

85 lines
3.6 KiB
CMake

# Smoke-test executables for Lts/DDS during migration.
# If the real test executables are not built (e.g. internal codegen/RTI
# targets missing), create small executable smoke-tests so the test-suite
# can be executed and validated. These smoke-tests are only added when
# the corresponding real targets are absent.
# Option to force-building smoke-tests even when real test targets exist.
option(BUILD_SMOKE_TESTS "Build smoke-tests even if real test executables are present" OFF)
option(BUILD_GTEST_SMOKE "Build GoogleTest-based smoke-tests for core logic" OFF)
# Try to find GoogleTest if requested
if(BUILD_GTEST_SMOKE)
find_package(GTest QUIET)
if(NOT GTest_FOUND)
message(STATUS "GoogleTest not found via find_package; will attempt to use FetchContent fallback if enabled later.")
endif()
endif()
if(BUILD_TESTING)
include(CTest)
# Generic data tests smoke (QtTest)
if(BUILD_SMOKE_TESTS OR NOT TARGET ddsGenericDataTests)
add_executable(ddsGenericDataTests_smoke ddsGenericDataTests_smoke.cpp)
target_link_libraries(ddsGenericDataTests_smoke PRIVATE Qt5::Core Qt5::Test)
add_test(NAME ddsGenericDataTests COMMAND $<TARGET_FILE:ddsGenericDataTests_smoke>)
endif()
# Data topic tests smoke (QtTest)
if(BUILD_SMOKE_TESTS OR NOT TARGET ddsDataTopicTests)
add_executable(ddsDataTopicTests_smoke ddsDataTopicTests_smoke.cpp)
target_link_libraries(ddsDataTopicTests_smoke PRIVATE Qt5::Core Qt5::Test)
add_test(NAME ddsDataTopicTests COMMAND $<TARGET_FILE:ddsDataTopicTests_smoke>)
endif()
# Function topic tests smoke (QtTest)
if(BUILD_SMOKE_TESTS OR NOT TARGET ddsFunctionTopicTests)
add_executable(ddsFunctionTopicTests_smoke ddsFunctionTopicTests_smoke.cpp)
target_link_libraries(ddsFunctionTopicTests_smoke PRIVATE Qt5::Core Qt5::Test)
add_test(NAME ddsFunctionTopicTests COMMAND $<TARGET_FILE:ddsFunctionTopicTests_smoke>)
endif()
# GoogleTest-based smoke-tests for core logic (optional)
if(BUILD_GTEST_SMOKE)
if(NOT GTest_FOUND)
# FetchContent fallback if GTest not found on system
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
endif()
if(TARGET GTest::gtest_main OR TARGET gtest_main)
# Generic data tests gtest
if(NOT TARGET ddsGenericDataTests)
add_executable(ddsGenericDataTests_gtest ddsGenericDataTests_gtest.cpp mocks/MockDDS.cpp)
target_link_libraries(ddsGenericDataTests_gtest PRIVATE GTest::gtest_main)
add_test(NAME ddsGenericDataTests_gtest COMMAND $<TARGET_FILE:ddsGenericDataTests_gtest>)
endif()
if(NOT TARGET ddsDataTopicTests)
add_executable(ddsDataTopicTests_gtest ddsDataTopicTests_gtest.cpp mocks/MockDDS.cpp)
target_link_libraries(ddsDataTopicTests_gtest PRIVATE GTest::gtest_main)
add_test(NAME ddsDataTopicTests_gtest COMMAND $<TARGET_FILE:ddsDataTopicTests_gtest>)
endif()
if(NOT TARGET ddsFunctionTopicTests)
add_executable(ddsFunctionTopicTests_gtest ddsFunctionTopicTests_gtest.cpp mocks/MockDDS.cpp)
target_link_libraries(ddsFunctionTopicTests_gtest PRIVATE GTest::gtest_main)
add_test(NAME ddsFunctionTopicTests_gtest COMMAND $<TARGET_FILE:ddsFunctionTopicTests_gtest>)
endif()
else()
message(WARNING "GTest targets not available even after fallback; skipping GTest smoke-tests.")
endif()
endif()
endif()