From dc8b3bae5d2e0519ecac0ad08799d0056cbca7b0 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 13 Jul 2016 17:43:12 +0800 Subject: [PATCH] cmake: use CMAKE_CXX_STANDARD for enabling C++11 hope we can drop the crufts when moving to cmake 3.1+ Signed-off-by: Kefu Chai --- src/CMakeLists.txt | 16 ++++++++++------ src/test/CMakeLists.txt | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 429af422524f..42382b6be1b6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,15 +98,19 @@ endif(no_yasm) set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -ftemplate-depth-1024 -Wno-invalid-offsetof -Wnon-virtual-dtor -Wno-invalid-offsetof -Wstrict-null-sentinel -Woverloaded-virtual") # require c++11 -include(CheckCXXCompilerFlag) -CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) -if (COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +if(CMAKE_VERSION VERSION_LESS "3.1") + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) + if(COMPILER_SUPPORTS_CXX11) + list(APPEND CMAKE_CXX_FLAGS -std=c++11) + else() + message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.") + endif() else() - message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.") + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_EXTENSIONS OFF) endif() - ## Handle diagnostics color if compiler supports them. CHECK_C_COMPILER_FLAG("-fdiagnostics-color=always" diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index f8b50aa40c0a..8e065aa156f6 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -357,7 +357,7 @@ add_executable(ceph_perf_local perf_local.cc perf_helper.cc) #INTEL_SSE & INTEL_SSE2 flags -set(PERF_LOCAL_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2") +set(PERF_LOCAL_FLAGS "-msse -msse2") set_target_properties(ceph_perf_local PROPERTIES COMPILE_FLAGS ${PERF_LOCAL_FLAGS}) target_link_libraries(ceph_perf_local os global ${UNITTEST_LIBS}) -- 2.47.3