From 6e42c8fc5716839bf246bf12734d251281d621ba Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 9 Mar 2021 10:46:46 +0000 Subject: [PATCH] Restore compatibility with CMake < 3.12 --- CMakeLists.txt | 23 +++++--- CMakeModules/SetupFGFSLibraries.cmake | 75 +++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 746ecf095..9fed70ab4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -312,7 +312,7 @@ if (ENABLE_QT) endif() set(CMAKE_AUTOMOC OFF) - + message(STATUS "Qt GUI enabled, found Qt at: ${FG_QT_ROOT_DIR}") else() message(STATUS "Qt GUI disabled, Qt/qmake not found in PATH/CMAKE_PREFIX_PATH") @@ -378,6 +378,12 @@ if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG") set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG") + + if(HAVE_QT) + # if Qt is built with reduce-relocations, applicatino code + # needs to be compiled with -fPIC to match + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() endif(CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" ) @@ -482,15 +488,15 @@ include(SetupFGFSLibraries) # create an object library target to hold all our sources # subdirectories will append sources to this target, and we'll # link it into our real executable targets +# use of 'flightgear-version' text file here is a dummy; CMake 3.10 +# requries at least one direct source file for targets, even though +# we use target_sources() later + +add_library(fgfsObjects OBJECT flightgear-version) -add_library(fgfsObjects OBJECT) -# Set up the include search paths for the object library -setup_fgfs_libraries(fgfsObjects) -setup_fgfs_includes(fgfsObjects) ######################################################################## - add_subdirectory(3rdparty) add_subdirectory(utils) @@ -500,6 +506,11 @@ add_subdirectory(man) add_subdirectory(package) add_subdirectory(scripts) +# Set up the include search paths for the object library : has to be done +# after targets are fully defined +setup_fgfs_library_includes(fgfsObjects) +setup_fgfs_includes(fgfsObjects) + #---------------------------------------------------------------------------- ### MSVC startup project - ensure you can just hit build & run in MSVC set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT fgfs) diff --git a/CMakeModules/SetupFGFSLibraries.cmake b/CMakeModules/SetupFGFSLibraries.cmake index 54bb76c4a..a8d7e3bcc 100644 --- a/CMakeModules/SetupFGFSLibraries.cmake +++ b/CMakeModules/SetupFGFSLibraries.cmake @@ -67,3 +67,78 @@ function(setup_fgfs_libraries target) target_link_libraries(${target} sentry::sentry) endif() endfunction() + + +# CMake < 3.12 can't define a link to an OBJECT library to specify its include +# paths, so we have to essentially duplicate the above and configure the paths manually. +# Once we require CMake 3.12, delete all this and use the function above. + +function (_apply_target_includes dest target) + if (NOT TARGET ${target}) + return() + endif() + + # retrieve the list of includes from the target + get_target_property(includes ${target} INTERFACE_INCLUDE_DIRECTORIES) + + foreach(i ${includes}) + # skip any invalid includes + if (NOT i) + return() + endif() + + target_include_directories(${dest} PUBLIC ${i}) + endforeach() +endfunction() + +function (_apply_all_target_includes dest) + foreach(arg IN LISTS ARGN) + _apply_target_includes(${dest} ${arg}) + endforeach() +endfunction() + +function (setup_fgfs_library_includes target) + + _apply_all_target_includes(${target} + SimGearCore + SimGearScene + Boost::boost + ${EVENT_INPUT_LIBRARIES} + ${HLA_LIBRARIES} + ${OPENGL_LIBRARIES} + ${OPENSCENEGRAPH_LIBRARIES} + ${PLATFORM_LIBS} + ${PLIB_LIBRARIES} + ) + + if(ENABLE_JSBSIM) + _apply_target_includes(${target} JSBSim) + endif() + + _apply_target_includes(${target} fgsqlite3) + _apply_target_includes(${target} fgvoicesynth) + _apply_target_includes(${target} fgembeddedresources) + + if (HAVE_QT) + _apply_all_target_includes(${target} Qt5::Core Qt5::Widgets Qt5::Gui) + endif() + + if(ENABLE_IAX) + _apply_target_includes(${target} iaxclient_lib) + endif() + + if (ENABLE_SWIFT) + _apply_all_target_includes(${target} ${dbus_target}) + endif() + + if (ENABLE_PLIB_JOYSTICK) + _apply_target_includes(${target} PLIBJoystick) + endif() + + _apply_target_includes(${target} PLIBFont) + + if (TARGET sentry::sentry) + _apply_target_includes(${target} sentry::sentry) + endif() + +endfunction() \ No newline at end of file