From 0604fe67ece7679b0360e7c16adfdbf435461002 Mon Sep 17 00:00:00 2001 From: Martin Hierholzer <martin.hierholzer@desy.de> Date: Tue, 20 Sep 2016 13:43:36 +0200 Subject: [PATCH] added script to enable the C++ 11 support --- cmake/enable_cxx11_support.cmake | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 cmake/enable_cxx11_support.cmake diff --git a/cmake/enable_cxx11_support.cmake b/cmake/enable_cxx11_support.cmake new file mode 100644 index 0000000..848fac3 --- /dev/null +++ b/cmake/enable_cxx11_support.cmake @@ -0,0 +1,37 @@ +####################################################################################################################### +# enable_cxx11_support.cmake +# +# Enable C++-11 support by selecting the appropriate compiler flag. The flag will be appended to all of the following +# cmake variables: +# - CMAKE_CXX_FLAGS +# - ${PROJECT_NAME}_CXX_FLAGS +# - ${PROJECT_NAME}_CMAKE_CXX_FLAGS +# +####################################################################################################################### + +####################################################################################################################### +# +# IMPORTANT NOTE: +# +# DO NOT MODIFY THIS FILE inside a project. Instead update the project-template repository and pull the change from +# there. Make sure to keep the file generic, since it will be used by other projects, too. +# +# If you have modified this file inside a project despite this warning, make sure to cherry-pick all your changes +# into the project-template repository immediately. +# +####################################################################################################################### + +include(CheckCXXCompilerFlag) +CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) +CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) +if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(${PROJECT_NAME}_CXX_FLAGS "${${PROJECT_NAME}_CXX_FLAGS} -std=c++11") + set(${PROJECT_NAME}_CMAKE_CXX_FLAGS "${${PROJECT_NAME}_CMAKE_CXX_FLAGS} -std=c++11") +elseif(COMPILER_SUPPORTS_CXX0X) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + set(${PROJECT_NAME}_CXX_FLAGS "${${PROJECT_NAME}_CXX_FLAGS} -std=c++0x") + set(${PROJECT_NAME}_CMAKE_CXX_FLAGS "${${PROJECT_NAME}_CMAKE_CXX_FLAGS} -std=c++0x") +else() + message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") +endif() -- GitLab