From a82a13b70c667393098e29d4e6877144b5110b3c Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Sun, 23 Aug 2020 22:25:03 +0100
Subject: [PATCH] Cmake: fix compat with CMake 3.10

Thankfully StackOverflow had an evil solution to this missing feature
in 3.10.
---
 CMakeLists.txt                  | 13 +++++++++++++
 CMakeModules/FindDBus.cmake     |  5 ++++-
 CMakeModules/FindLibEvent.cmake |  4 +++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f0f3c1270..71f4c8589 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -50,6 +50,19 @@ 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 2df20f869..9e5aa88e3 100644
--- a/CMakeModules/FindDBus.cmake
+++ b/CMakeModules/FindDBus.cmake
@@ -18,12 +18,15 @@ if(WIN32)
 else()
 	find_package(PkgConfig QUIET)
 
+
 	if(PKG_CONFIG_FOUND)
 		pkg_check_modules(DBUS IMPORTED_TARGET dbus-1)
 	endif (PKG_CONFIG_FOUND)
 
 	if(DBUS_FOUND)
-		set_target_properties(PkgConfig::DBUS PROPERTIES IMPORTED_GLOBAL TRUE)
+		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
diff --git a/CMakeModules/FindLibEvent.cmake b/CMakeModules/FindLibEvent.cmake
index 664f2385d..c0898fcf4 100644
--- a/CMakeModules/FindLibEvent.cmake
+++ b/CMakeModules/FindLibEvent.cmake
@@ -22,7 +22,9 @@ else()
 	endif()
 
 	if(libEvent_FOUND)
-		set_target_properties(PkgConfig::libEvent PROPERTIES IMPORTED_GLOBAL TRUE)
+		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)