From dc467ebdfa24ebbd1db62e07a3961ebb4a90fb74 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 8 Jan 2023 19:35:29 +0000 Subject: [PATCH] Cmake Improve Finder for CppUnit Define an imported target for the system CppUnit, so we can correctly pass includes locations to FgfsTestSuite --- CMakeLists.txt | 3 ++- CMakeModules/FindCppUnit.cmake | 10 ++++++++++ test_suite/CMakeLists.txt | 6 +++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1500a1d41..889ecb9ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,7 +183,7 @@ option(SYSTEM_SPEEX "Set to ON to build IAXClient with the system's speex a option(SYSTEM_GSM "Set to ON to build IAXClient with the system's GSM library" ${SYSTEM_GSM_DEFAULT}) option(SYSTEM_FLITE "Set to ON to build Flightgear with the system's Flite library" ${SYSTEM_FLITE_DEFAULT}) option(SYSTEM_HTS_ENGINE "Set to ON to build Flightgear with the system's HTS Engine library" ${SYSTEM_HTS_ENGINE_DEFAULT}) -option(SYSTEM_CPPUNIT "Set to ON to build Flightgear with the system's CppUnit library") +option(SYSTEM_CPPUNIT "Set to ON to build Flightgear with the system's CppUnit library" OFF) # additional utilities option(ENABLE_FGELEV "Set to ON to build the fgelev application (default)" ON) @@ -266,6 +266,7 @@ endif(EVENT_INPUT) include(SetupSwiftLibraries) if (SYSTEM_CPPUNIT) + message(STATUS "Looking for system CppUnit") find_package(CppUnit REQUIRED) endif() diff --git a/CMakeModules/FindCppUnit.cmake b/CMakeModules/FindCppUnit.cmake index 3b9b638d3..7b5593868 100644 --- a/CMakeModules/FindCppUnit.cmake +++ b/CMakeModules/FindCppUnit.cmake @@ -4,6 +4,8 @@ # CPPUNIT_FOUND # CPPUNIT_LIBRARIES # CPPUNIT_INCLUDE_DIR +# +# And defines the imported target CppUnitLib # Find CppUnit. if (NOT CPPUNIT_LIBRARIES AND NOT CPPUNIT_INCLUDE_DIR) @@ -39,4 +41,12 @@ if (CPPUNIT_LIBRARIES AND CPPUNIT_INCLUDE_DIR) set(CPPUNIT_FOUND TRUE) message(STATUS "CppUnit library found: ${CPPUNIT_LIBRARIES}") message(STATUS "CppUnit include directory found: ${CPPUNIT_INCLUDE_DIR}") + + if(NOT TARGET CppUnitLib) + add_library(CppUnitLib UNKNOWN IMPORTED) + set_target_properties(CppUnitLib PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CPPUNIT_INCLUDE_DIR}" + IMPORTED_LOCATION "${CPPUNIT_LIBRARIES}") + endif() endif () + diff --git a/test_suite/CMakeLists.txt b/test_suite/CMakeLists.txt index 15f8153e5..188b35cc0 100644 --- a/test_suite/CMakeLists.txt +++ b/test_suite/CMakeLists.txt @@ -54,8 +54,8 @@ if (NOT SYSTEM_CPPUNIT) add_library(CppUnitLib STATIC ${CPPUNIT_SOURCES} ${CPPUNIT_HEADERS}) target_include_directories(CppUnitLib PUBLIC "${PROJECT_SOURCE_DIR}/3rdparty/cppunit/include") - - set(CPPUNIT_LIBRARIES CppUnitLib) +elseif(NOT TARGET CppUnitLib) + message(FATAL_ERROR "CppUnit: system CppUnit library not found correctly") else() message(STATUS "CppUnit: Linking to the system supplied CppUnit library") endif() @@ -151,7 +151,7 @@ target_include_directories(fgfs_test_suite PUBLIC ${PROJECT_SOURCE_DIR}) target_compile_definitions(fgfs_test_suite PUBLIC BUILDING_TESTSUITE) # Additional libraries just for the test suite. -target_link_libraries(fgfs_test_suite ${CPPUNIT_LIBRARIES}) +target_link_libraries(fgfs_test_suite CppUnitLib) # target to run the tests if (MSVC)