1
0
Fork 0

Cmake Improve Finder for CppUnit

Define an imported target for the system CppUnit, so we can
correctly pass includes locations to FgfsTestSuite
This commit is contained in:
James Turner 2023-01-08 19:35:29 +00:00
parent 4c42600898
commit dc467ebdfa
3 changed files with 15 additions and 4 deletions

View file

@ -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_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_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_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 # additional utilities
option(ENABLE_FGELEV "Set to ON to build the fgelev application (default)" ON) option(ENABLE_FGELEV "Set to ON to build the fgelev application (default)" ON)
@ -266,6 +266,7 @@ endif(EVENT_INPUT)
include(SetupSwiftLibraries) include(SetupSwiftLibraries)
if (SYSTEM_CPPUNIT) if (SYSTEM_CPPUNIT)
message(STATUS "Looking for system CppUnit")
find_package(CppUnit REQUIRED) find_package(CppUnit REQUIRED)
endif() endif()

View file

@ -4,6 +4,8 @@
# CPPUNIT_FOUND # CPPUNIT_FOUND
# CPPUNIT_LIBRARIES # CPPUNIT_LIBRARIES
# CPPUNIT_INCLUDE_DIR # CPPUNIT_INCLUDE_DIR
#
# And defines the imported target CppUnitLib
# Find CppUnit. # Find CppUnit.
if (NOT CPPUNIT_LIBRARIES AND NOT CPPUNIT_INCLUDE_DIR) if (NOT CPPUNIT_LIBRARIES AND NOT CPPUNIT_INCLUDE_DIR)
@ -39,4 +41,12 @@ if (CPPUNIT_LIBRARIES AND CPPUNIT_INCLUDE_DIR)
set(CPPUNIT_FOUND TRUE) set(CPPUNIT_FOUND TRUE)
message(STATUS "CppUnit library found: ${CPPUNIT_LIBRARIES}") message(STATUS "CppUnit library found: ${CPPUNIT_LIBRARIES}")
message(STATUS "CppUnit include directory found: ${CPPUNIT_INCLUDE_DIR}") 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 () endif ()

View file

@ -54,8 +54,8 @@ if (NOT SYSTEM_CPPUNIT)
add_library(CppUnitLib STATIC ${CPPUNIT_SOURCES} ${CPPUNIT_HEADERS}) add_library(CppUnitLib STATIC ${CPPUNIT_SOURCES} ${CPPUNIT_HEADERS})
target_include_directories(CppUnitLib PUBLIC "${PROJECT_SOURCE_DIR}/3rdparty/cppunit/include") target_include_directories(CppUnitLib PUBLIC "${PROJECT_SOURCE_DIR}/3rdparty/cppunit/include")
elseif(NOT TARGET CppUnitLib)
set(CPPUNIT_LIBRARIES CppUnitLib) message(FATAL_ERROR "CppUnit: system CppUnit library not found correctly")
else() else()
message(STATUS "CppUnit: Linking to the system supplied CppUnit library") message(STATUS "CppUnit: Linking to the system supplied CppUnit library")
endif() endif()
@ -151,7 +151,7 @@ target_include_directories(fgfs_test_suite PUBLIC ${PROJECT_SOURCE_DIR})
target_compile_definitions(fgfs_test_suite PUBLIC BUILDING_TESTSUITE) target_compile_definitions(fgfs_test_suite PUBLIC BUILDING_TESTSUITE)
# Additional libraries just for the test suite. # 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 # target to run the tests
if (MSVC) if (MSVC)