1
0
Fork 0

CMake: different fix for ALIAS issues with 3.10

ALIAS is not really functional in 3.10, so use a variable to approximate
the same behaviour. Not elegant but it seems to work.
This commit is contained in:
James Turner 2020-08-27 22:33:08 +01:00
parent 37d820120d
commit 740193a378
5 changed files with 25 additions and 31 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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")