diff --git a/CMakeLists.txt b/CMakeLists.txt index 38c51f64c..267778e20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,19 +50,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version") -if(${CMAKE_VERSION} VERSION_LESS "3.11.0") - # override add_library to work around a missing feature in CMake 3.10 - # see https://stackoverflow.com/questions/45401212/how-to-make-imported-target-global-afterwards - # for discussion of why we need this - function(add_library) - set(_args ${ARGN}) - if ("${_args}" MATCHES ";IMPORTED") - list(APPEND _args GLOBAL) - endif() - _add_library(${_args}) - endfunction() -endif() - project(FlightGear) # Define SRC_PARENT_DIR as the parent directory of the project source directory diff --git a/CMakeModules/FindDBus.cmake b/CMakeModules/FindDBus.cmake index 9e5aa88e3..46f7c2b4d 100644 --- a/CMakeModules/FindDBus.cmake +++ b/CMakeModules/FindDBus.cmake @@ -3,6 +3,8 @@ # DBUS_LIBRARY # DBUS_INCLUDE_DIR +set(dbus_target "_no_target_") + if(WIN32) FIND_PATH(DBUS_INCLUDE_DIRS dbus/dbus.h PATH_SUFFIXES include HINTS ${ADDITIONAL_LIBRARY_PATHS}) FIND_LIBRARY(DBUS_LIBRARIES NAMES dbus-1 PATH_SUFFIXES lib HINTS ${ADDITIONAL_LIBRARY_PATHS}) @@ -14,22 +16,22 @@ if(WIN32) INTERFACE_INCLUDE_DIRECTORIES "${DBUS_INCLUDE_DIRS}" IMPORTED_LOCATION "${DBUS_LIBRARIES}" ) + + set(HAVE_DBUS 1) + set(dbus_target "DBus") endif() else() find_package(PkgConfig QUIET) - if(PKG_CONFIG_FOUND) pkg_check_modules(DBUS IMPORTED_TARGET dbus-1) endif (PKG_CONFIG_FOUND) if(DBUS_FOUND) - if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.11.0") - set_target_properties(PkgConfig::DBUS PROPERTIES IMPORTED_GLOBAL TRUE) - endif() - set(HAVE_DBUS 1) - # alias the PkgConfig name to standard one - add_library(DBus ALIAS PkgConfig::DBUS) + + # can't use an ALIAS here, needs CMake 3.11 + # use a global property instead + set(dbus_target "PkgConfig::DBUS") endif(DBUS_FOUND) endif(WIN32) diff --git a/CMakeModules/FindLibEvent.cmake b/CMakeModules/FindLibEvent.cmake index c0898fcf4..b245b1a0c 100644 --- a/CMakeModules/FindLibEvent.cmake +++ b/CMakeModules/FindLibEvent.cmake @@ -3,6 +3,8 @@ # LIBEVENT_LIB # LIBEVENT_INCLUDE_DIR +set(libEvent_target "_no_target_") + if(WIN32) FIND_PATH(LIBEVENT_INCLUDE_DIR event2/event.h PATH_SUFFIXES include HINTS ${ADDITIONAL_LIBRARY_PATHS}) FIND_LIBRARY(LIBEVENT_LIB NAMES event_core PATH_SUFFIXES lib HINTS ${ADDITIONAL_LIBRARY_PATHS}) @@ -14,19 +16,18 @@ if(WIN32) IMPORTED_LOCATION "${LIBEVENT_LIB}" ) endif() + + else() find_package(PkgConfig QUIET) if(PKG_CONFIG_FOUND) - pkg_check_modules(libEvent QUIET IMPORTED_TARGET libevent) + pkg_check_modules(libEvent IMPORTED_TARGET libevent) endif() if(libEvent_FOUND) - if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.11.0") - set_target_properties(PkgConfig::libEvent PROPERTIES IMPORTED_GLOBAL TRUE) - endif() - - # alias the PkgConfig name to standard one - add_library(libEvent ALIAS PkgConfig::libEvent) + # can't use an ALIAS here, needs CMake 3.11 + # use a global property instead + set(libEvent_target "PkgConfig::libEvent") endif() endif(WIN32) diff --git a/CMakeModules/SetupFGFSLibraries.cmake b/CMakeModules/SetupFGFSLibraries.cmake index d92597d57..d40f5ec66 100644 --- a/CMakeModules/SetupFGFSLibraries.cmake +++ b/CMakeModules/SetupFGFSLibraries.cmake @@ -18,8 +18,10 @@ function(setup_fgfs_libraries target) target_link_libraries(${target} iaxclient_lib) endif() - if(TARGET DBus) - target_link_libraries(${target} DBus) + if(HAVE_DBUS) + # ALIAS doesn't work with CMake 3.10, so we need + # variable to store the target name + target_link_libraries(${target} ${dbus_target}) endif() if(X11_FOUND) @@ -41,7 +43,9 @@ function(setup_fgfs_libraries target) ) if (ENABLE_SWIFT) - target_link_libraries(${target} DBus libEvent) + # ALIAS doesn't work with CMake 3.10, so we need + # variable to store the target name + target_link_libraries(${target} ${dbus_target} ${libEvent_target}) endif() if (ENABLE_PLIB_JOYSTICK) diff --git a/CMakeModules/SetupSwiftLibraries.cmake b/CMakeModules/SetupSwiftLibraries.cmake index a3d271d5e..2227241cc 100644 --- a/CMakeModules/SetupSwiftLibraries.cmake +++ b/CMakeModules/SetupSwiftLibraries.cmake @@ -10,7 +10,7 @@ if (ENABLE_SWIFT) find_package(DBus) find_package(LibEvent) - if (TARGET DBus AND TARGET libEvent) + if (TARGET ${dbus_target} AND TARGET ${libEvent_target}) message(STATUS "SWIFT support enabled") else() message(STATUS "SWIFT support disabled, dbus and/or LibEvent not found")