Require CMake 3.0, enable C++11

Let’s see what this breaks.
This commit is contained in:
James Turner 2016-10-24 22:52:51 +02:00
parent 202571386b
commit 51e7d95bf2

View File

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8.11) cmake_minimum_required (VERSION 3.0)
if(COMMAND cmake_policy) if(COMMAND cmake_policy)
if(POLICY CMP0054) if(POLICY CMP0054)
@ -9,10 +9,6 @@ if(COMMAND cmake_policy)
endif() endif()
endif() endif()
if(CMAKE_VERSION VERSION_LESS "3.1")
message(WARNING "CMake 3.1 will be required soon, please upgrade")
endif()
include (CheckFunctionExists) include (CheckFunctionExists)
include (CheckIncludeFile) include (CheckIncludeFile)
include (CheckLibraryExists) include (CheckLibraryExists)
@ -20,24 +16,21 @@ include (CheckCXXSourceCompiles)
include (CheckCXXCompilerFlag) include (CheckCXXCompilerFlag)
include (GenerateExportHeader) 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 # only relevant for building shared libs but let's set it regardless
set(CMAKE_OSX_RPATH 1) set(CMAKE_OSX_RPATH 1)
# Set the C++ standard to C++98 to avoid compilation errors on GCC 6 (which # let's use & require C++11 - note these are only functional with CMake 3.1
# defaults to C++14). # we do manual fallbacks for CMake 3.0 in the compilers section
if(CMAKE_VERSION VERSION_LESS "3.1") set(CMAKE_CXX_STANDARD 11)
if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_STANDARD_REQUIRED YES)
set (CMAKE_CXX_FLAGS "-std=gnu++98 ${CMAKE_CXX_FLAGS}")
endif()
else()
set (CMAKE_CXX_STANDARD 98)
endif()
project(SimGear) project(SimGear)
# using 10.7 because boost requires libc++ and 10.6 doesn't include it
# Cmake documentation says we must set this before calling project(), but
# it only seems to be picked up setting it /after/ the call to project()
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.7")
# read 'version' file into a variable (stripping any newlines or spaces) # read 'version' file into a variable (stripping any newlines or spaces)
file(READ version versionFile) file(READ version versionFile)
string(STRIP ${versionFile} SIMGEAR_VERSION) string(STRIP ${versionFile} SIMGEAR_VERSION)
@ -196,15 +189,9 @@ endif (MSVC AND MSVC_3RDPARTY_ROOT)
if(APPLE) if(APPLE)
find_library(COCOA_LIBRARY Cocoa) find_library(COCOA_LIBRARY Cocoa)
# this should be handled by setting CMAKE_OSX_DEPLOYMENT_TARGET
# but it's not working reliably, so forcing it for now
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.7")
endif() endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
endif() endif()
@ -354,6 +341,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(WARNING_FLAGS_CXX "-Wall") set(WARNING_FLAGS_CXX "-Wall")
set(WARNING_FLAGS_C "-Wall") set(WARNING_FLAGS_C "-Wall")
if (CMAKE_VERSION VERSION_LESS 3.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
message(WARNING "GCC 4.4 will be required soon, please upgrade") message(WARNING "GCC 4.4 will be required soon, please upgrade")
endif() endif()
@ -366,13 +357,17 @@ if(CMAKE_COMPILER_IS_GNUCXX)
GCC_ATOMIC_BUILTINS_FOUND) GCC_ATOMIC_BUILTINS_FOUND)
endif(CMAKE_COMPILER_IS_GNUCXX) endif(CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# Boost redeclares class members # Boost redeclares class members
set(WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual -Wno-redeclared-class-member") set(WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual -Wno-redeclared-class-member")
set(WARNING_FLAGS_C "-Wall") set(WARNING_FLAGS_C "-Wall")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11") # fix Boost compilation :(
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
if (CMAKE_VERSION VERSION_LESS 3.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif() endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")