]> git.mxchange.org Git - simgear.git/blobdiff - CMakeLists.txt
Switch to c++11
[simgear.git] / CMakeLists.txt
index f11c07afc3b3a20f59afa4a643a3899741e907f6..0f6a84d0d13e99ba1a1fdadba4c7c8c15f1a0d08 100644 (file)
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 2.6.4)
+cmake_minimum_required (VERSION 2.8.11)
 
 if(COMMAND cmake_policy)
    if(POLICY CMP0054)
@@ -11,8 +11,26 @@ endif()
 
 include (CheckFunctionExists)
 include (CheckIncludeFile)
+include (CheckLibraryExists)
 include (CheckCXXSourceCompiles)
 include (CheckCXXCompilerFlag)
+include (GenerateExportHeader)
+
+# using 10.7 because boost requires libc++ and 10.6 doesn't include it
+set(CMAKE_OSX_DEPLOYMENT_TARGET 10.7)
+
+# only relevant for building shared libs but let's set it regardless
+set(CMAKE_OSX_RPATH 1)
+
+# Set the C++ standard to C++11 to avoid compilation errors on GCC 6 (which
+# defaults to C++14).
+if(CMAKE_VERSION VERSION_LESS "3.1")
+  if(CMAKE_COMPILER_IS_GNUCXX)
+    set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
+  endif()
+else()
+  set (CMAKE_CXX_STANDARD 11)
+endif()
 
 project(SimGear)
 
@@ -72,12 +90,7 @@ endif(NOT CMAKE_BUILD_TYPE)
 # Determine name of library installation directory, i.e. "lib" vs "lib64", which
 # differs between all Debian-based vs all other Linux distros.
 # See cmake bug #11964, http://cmake.org/gitweb?p=cmake.git;a=commit;h=126c993d
-# GNUInstallDirs requires CMake >= 2.8.5, use own file for older cmake
-if(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
-  include(GNUInstallDirs)
-else(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
-  include(OldGNUInstallDirs)
-endif(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
+include(GNUInstallDirs)
 message(STATUS "Library installation directory: ${CMAKE_INSTALL_LIBDIR}")
 
 #####################################################################################
@@ -114,6 +127,7 @@ option(ENABLE_RTI       "Set to ON to build SimGear with RTI support" OFF)
 option(ENABLE_TESTS     "Set to OFF to disable building SimGear's test applications" ON)
 option(ENABLE_SOUND     "Set to OFF to disable building SimGear's sound support" ON)
 option(ENABLE_PKGUTIL   "Set to ON to build the sg_pkgutil application (default)" ON)
+option(ENABLE_DNS       "Set to ON to use udns library and DNS service resolver" ON)
 
 if (MSVC)
   GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_BINARY_DIR} PATH)
@@ -171,11 +185,16 @@ endif (MSVC AND MSVC_3RDPARTY_ROOT)
 
 if(APPLE)
   find_library(COCOA_LIBRARY Cocoa)
-  
+
   # using 10.7 because boost requires libc++ and 10.6 doesn't include it
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
 endif()
 
+if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR
+       ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
+    find_package(Threads REQUIRED)
+endif()
+
 # Somehow this only works if included before searching for Boost...
 include(BoostTestTargets)
 
@@ -198,7 +217,7 @@ else()
 endif(SIMGEAR_HEADLESS)
 
 find_package(ZLIB REQUIRED)
-find_package(Threads REQUIRED)
+find_package(CURL REQUIRED)
 
 if (SYSTEM_EXPAT)
     message(STATUS "Requested to use system Expat library, forcing SIMGEAR_SHARED to true")
@@ -365,6 +384,7 @@ include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
     ${Boost_INCLUDE_DIRS}
     ${ZLIB_INCLUDE_DIR}
     ${OPENAL_INCLUDE_DIR}
+    ${CURL_INCLUDE_DIRS}
 )
 
 add_definitions(-DHAVE_CONFIG_H)
@@ -393,7 +413,8 @@ set(TEST_LIBS_INTERNAL_CORE
     ${WINSOCK_LIBRARY}
     ${RT_LIBRARY}
     ${DL_LIBRARY}
-    ${COCOA_LIBRARY})
+    ${COCOA_LIBRARY}
+    ${CURL_LIBRARIES})
 set(TEST_LIBS SimGearCore ${TEST_LIBS_INTERNAL_CORE})
 
 if(NOT SIMGEAR_HEADLESS)
@@ -403,10 +424,51 @@ endif()
 install (FILES ${PROJECT_BINARY_DIR}/simgear/simgear_config.h  DESTINATION include/simgear/)
 
 include_directories(3rdparty/utf8/source)
+if (ENABLE_DNS)
+    message(STATUS "DNS resolver: ENABLED")
+    include_directories(3rdparty/udns)
+else()
+    message(STATUS "DNS resolver: DISABLED")
+endif()
+
 
 add_subdirectory(3rdparty)
 add_subdirectory(simgear)
 
+#-----------------------------------------------------------------------------
+### Export stuff, see https://cmake.org/cmake/help/v3.2/manual/cmake-packages.7.html#creating-packages
+#-----------------------------------------------------------------------------
+
+generate_export_header(SimGearCore)
+if(NOT SIMGEAR_HEADLESS)
+  generate_export_header(SimGearScene)
+endif()
+
+include(CMakePackageConfigHelpers)
+
+write_basic_package_version_file(
+  "${CMAKE_CURRENT_BINARY_DIR}/SimGear/SimGearConfigVersion.cmake"
+  VERSION ${SIMGEAR_VERSION}
+  COMPATIBILITY AnyNewerVersion
+)
+
+configure_file(SimGearConfig.cmake.in
+  "${CMAKE_CURRENT_BINARY_DIR}/SimGear/SimGearConfig.cmake"
+  @ONLY
+)
+
+set(ConfigPackageLocation lib/cmake/SimGear)
+install(EXPORT SimGearTargets
+  DESTINATION ${ConfigPackageLocation}
+)
+install(
+  FILES
+    "${CMAKE_CURRENT_BINARY_DIR}/SimGear/SimGearConfig.cmake"
+    "${CMAKE_CURRENT_BINARY_DIR}/SimGear/SimGearConfigVersion.cmake"
+  DESTINATION ${ConfigPackageLocation}
+  COMPONENT Devel
+)
+
 #-----------------------------------------------------------------------------
 ### uninstall target
 #-----------------------------------------------------------------------------
@@ -416,5 +478,3 @@ CONFIGURE_FILE(
   IMMEDIATE @ONLY)
 ADD_CUSTOM_TARGET(uninstall
   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
-
-