From 0a8d0b53db30667b9dfbe006a707cdbf7f5c98b9 Mon Sep 17 00:00:00 2001 From: Fred Hornsey Date: Fri, 9 Feb 2024 12:56:24 -0600 Subject: [PATCH] Simplify Test CMake --- CMakeLists.txt | 11 ++++++++- test/CMakeLists.txt | 54 +++++++++------------------------------------ 2 files changed, 20 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f57f8f9..9c4aeee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,4 +139,13 @@ target_include_directories(monitor PRIVATE configure_file(opendds.ini . COPYONLY) -add_subdirectory(test EXCLUDE_FROM_ALL) +if(BUILD_TESTING) + set(_OPENDSS_MONITOR_BUILD_TESTS_DEFAULT TRUE) +else() + set(_OPENDSS_MONITOR_BUILD_TESTS_DEFAULT FALSE) +endif() +set(OPENDSS_MONITOR_BUILD_TESTS ${_OPENDSS_MONITOR_BUILD_TESTS_DEFAULT} + CACHE BOOL "Build OpenDDS Monitor Tests") +if(OPENDSS_MONITOR_BUILD_TESTS) + add_subdirectory(test) +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 908bd3d..982aefa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,56 +2,22 @@ cmake_minimum_required(VERSION 3.20) project(opendds-monitor-tests VERSION 0.0.1 LANGUAGES CXX) -if ("$ENV{RAPIDJSON_ROOT}" STREQUAL "") - set(RAPIDJSON_ROOT $ENV{DDS_ROOT}/tools/rapidjson) -else() - set(RAPIDJSON_ROOT $ENV{RAPIDJSON_ROOT}) -endif() -set(RAPIDJSON_INCLUDE_DIR ${RAPIDJSON_ROOT}/include) - -add_executable(managed_testapp - managed.cpp -) - +add_library(test_common INTERFACE) +target_compile_options(test_common INTERFACE $<$,$,$>: -Wall -Wpedantic -Wno-unused -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wundef -Werror> $<$: /W4>) if (MSVC) - target_compile_definitions(managed_testapp PRIVATE _CRT_SECURE_NO_WARNINGS) + target_compile_definitions(test_common INTERFACE _CRT_SECURE_NO_WARNINGS) else() - target_compile_features(managed_testapp PRIVATE cxx_std_17) + target_compile_features(test_common INTERFACE cxx_std_17) endif() - -target_compile_options(managed_testapp PRIVATE $<$,$,$>: -Wall -Wpedantic -Wno-unused -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wundef -Werror> $<$: /W4>) - -OPENDDS_TARGET_SOURCES(managed_testapp test.idl OPENDDS_IDL_OPTIONS "-Gxtypes-complete" SUPPRESS_ANYS OFF) - -target_link_libraries(managed_testapp - OpenDDW - OpenDDS::Dcps -) - -target_include_directories(managed_testapp PRIVATE +target_include_directories(test_common INTERFACE ../src - ${RAPIDJSON_INCLUDE_DIR} ) -add_executable(unmanaged_testapp - unmanaged.cpp -) -if (MSVC) - target_compile_definitions(unmanaged_testapp PRIVATE _CRT_SECURE_NO_WARNINGS) -else () - target_compile_features(unmanaged_testapp PRIVATE cxx_std_17) -endif() +add_executable(managed_testapp managed.cpp) +OPENDDS_TARGET_SOURCES(managed_testapp test.idl OPENDDS_IDL_OPTIONS "-Gxtypes-complete" SUPPRESS_ANYS OFF) +target_link_libraries(managed_testapp OpenDDW test_common) +add_executable(unmanaged_testapp unmanaged.cpp) OPENDDS_TARGET_SOURCES(unmanaged_testapp test.idl OPENDDS_IDL_OPTIONS "-Gxtypes-complete" SUPPRESS_ANYS OFF) - -target_compile_options(unmanaged_testapp PRIVATE $<$,$,$>: -Wall -Wpedantic -Wno-unused -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wundef -Werror> $<$: /W4>) - -target_link_libraries(unmanaged_testapp - OpenDDS::Dcps -) - -target_include_directories(unmanaged_testapp PRIVATE - ../src - ${RAPIDJSON_INCLUDE_DIR} -) +target_link_libraries(unmanaged_testapp OpenDDS::Dcps test_common)