diff options
| author | Mateusz Łoskot <mateusz@loskot.net> | 2019-02-13 19:47:04 +0100 |
|---|---|---|
| committer | Mateusz Łoskot <mateusz@loskot.net> | 2019-02-13 21:04:46 +0100 |
| commit | 90080a9c0fcffb6912da8c0f3d4cceea709fbe43 (patch) | |
| tree | 2cc5c839dbedd252f03ca82c222861316bf3daab | |
| parent | 4d1f5486f6453300bdb35c2607e126f6c526c243 (diff) | |
| download | PROJ-90080a9c0fcffb6912da8c0f3d4cceea709fbe43.tar.gz PROJ-90080a9c0fcffb6912da8c0f3d4cceea709fbe43.zip | |
Set CMake variable CXX_STANDARD with C++11 as default
Set required C++ standard version with CMake variable
instead of hand-rolled compiler-specific flags.
Allow user to override the default with -DCMAKE_CXX_STANDARD={98,11,14,17,20}
Closes #1118
| -rw-r--r-- | CMakeLists.txt | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 66a0d4cf..e71d662e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ ################################################################################# # General settings ################################################################################# -cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) # For historic reasons, the CMake PROJECT-NAME is PROJ4 project(PROJ4 LANGUAGES C CXX) @@ -21,6 +21,14 @@ endif () add_definitions(-DPROJ_COMPILATION=1) +# Set C++ version +# Make CMAKE_CXX_STANDARD available as cache option overridable by user +set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard version to use (default is 11)") +message(STATUS "Requiring C++${CMAKE_CXX_STANDARD}") +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +message(STATUS "Requiring C++${CMAKE_CXX_STANDARD} - done") + # Set warnings if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") # Suppress warning 4706 about assignment within conditional expression @@ -29,10 +37,10 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /W4 /wd4706 /wd4996 /D_CRT_SECURE_NO_WARNINGS") elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -Wall -Wextra -Wswitch -Wshadow -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wformat -Wformat-security") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -std=c++11 -Wall -Wextra -Wswitch -Wshadow -Wunused-parameter -Wmissing-declarations -Wformat -Wformat-security") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -Wall -Wextra -Wswitch -Wshadow -Wunused-parameter -Wmissing-declarations -Wformat -Wformat-security") elseif("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -Wall -Wextra -Wswitch -Wshadow -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wformat -Wformat-security -Wfloat-conversion -Wc99-extensions -Wc11-extensions") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -std=c++11 -Wall -Wextra -Wswitch -Wshadow -Wunused-parameter -Wmissing-declarations -Wformat -Wformat-security -Wfloat-conversion") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -Wall -Wextra -Wswitch -Wshadow -Wunused-parameter -Wmissing-declarations -Wformat -Wformat-security -Wfloat-conversion") endif() # Tell Intel compiler to do arithmetic accurately. This is needed to @@ -42,10 +50,9 @@ endif() if (CMAKE_C_COMPILER_ID STREQUAL "Intel") if (MSVC) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fp:precise") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qstd=c++11") else () set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fp-model precise") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -std=c++11") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") endif () endif () |
