From d5e918b61f941a26267a2e8a34738f901ed96606 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 28 Sep 2017 08:46:47 -0700 Subject: [PATCH] Detect C++14 compiler support --- CMakeLists.txt | 4 +- fmt/CMakeLists.txt | 2 +- support/cmake/{cxx11.cmake => cxx14.cmake} | 44 +++++++++++----------- test/CMakeLists.txt | 12 +++--- test/add-subdirectory-test/CMakeLists.txt | 4 +- test/compile-test/CMakeLists.txt | 2 +- test/find-package-test/CMakeLists.txt | 4 +- 7 files changed, 36 insertions(+), 36 deletions(-) rename support/cmake/{cxx11.cmake => cxx14.cmake} (64%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 353940f8..47319e1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF) option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT}) option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT}) option(FMT_TEST "Generate the test target." ${MASTER_PROJECT}) -option(FMT_USE_CPP11 "Enable the addition of C++11 compiler flags." ON) +option(FMT_USE_CPP14 "Enable the addition of C++14 compiler flags." ON) project(FMT) @@ -43,7 +43,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake") -include(cxx11) +include(cxx14) if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wshadow -pedantic) diff --git a/fmt/CMakeLists.txt b/fmt/CMakeLists.txt index c2c7f0fe..ac3ad4ea 100644 --- a/fmt/CMakeLists.txt +++ b/fmt/CMakeLists.txt @@ -16,7 +16,7 @@ if (FMT_CPPFORMAT) endif () # Starting with cmake 3.1 the CXX_STANDARD property can be used instead. -target_compile_options(fmt PUBLIC ${CPP11_FLAG}) +target_compile_options(fmt PUBLIC ${CPP14_FLAG}) if (FMT_PEDANTIC) target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS}) endif () diff --git a/support/cmake/cxx11.cmake b/support/cmake/cxx14.cmake similarity index 64% rename from support/cmake/cxx11.cmake rename to support/cmake/cxx14.cmake index 21d12543..7b427a37 100644 --- a/support/cmake/cxx11.cmake +++ b/support/cmake/cxx14.cmake @@ -1,55 +1,55 @@ -# C++11 feature support detection +# C++14 feature support detection -if (NOT FMT_USE_CPP11) +if (NOT FMT_USE_CPP14) return() endif () include(CheckCXXCompilerFlag) -if (FMT_USE_CPP11) - check_cxx_compiler_flag(-std=c++11 HAVE_STD_CPP11_FLAG) - if (HAVE_STD_CPP11_FLAG) - # Check if including cmath works with -std=c++11 and -O3. +if (FMT_USE_CPP14) + check_cxx_compiler_flag(-std=c++14 HAVE_STD_CPP14_FLAG) + if (HAVE_STD_CPP14_FLAG) + # Check if including cmath works with -std=c++14 and -O3. # It may not in MinGW due to bug http://ehc.ac/p/mingw/bugs/2250/. - set(CMAKE_REQUIRED_FLAGS "-std=c++11 -O3") + set(CMAKE_REQUIRED_FLAGS "-std=c++14 -O3") check_cxx_source_compiles(" #include - int main() {}" FMT_CPP11_CMATH) - # Check if including works with -std=c++11. + int main() {}" FMT_CPP14_CMATH) + # Check if including works with -std=c++14. # It may not in MinGW due to bug http://sourceforge.net/p/mingw/bugs/2024/. check_cxx_source_compiles(" #include - int main() {}" FMT_CPP11_UNISTD_H) - # Check if snprintf works with -std=c++11. It may not in MinGW. + int main() {}" FMT_CPP14_UNISTD_H) + # Check if snprintf works with -std=c++14. It may not in MinGW. check_cxx_source_compiles(" #include int main() { char buffer[10]; snprintf(buffer, 10, \"foo\"); - }" FMT_CPP11_SNPRINTF) - if (FMT_CPP11_CMATH AND FMT_CPP11_UNISTD_H AND FMT_CPP11_SNPRINTF) - set(CPP11_FLAG -std=c++11) + }" FMT_CPP14_SNPRINTF) + if (FMT_CPP14_CMATH AND FMT_CPP14_UNISTD_H AND FMT_CPP14_SNPRINTF) + set(CPP14_FLAG -std=c++14) else () - check_cxx_compiler_flag(-std=gnu++11 HAVE_STD_GNUPP11_FLAG) - if (HAVE_STD_CPP11_FLAG) - set(CPP11_FLAG -std=gnu++11) + check_cxx_compiler_flag(-std=gnu++14 HAVE_STD_GNUPP14_FLAG) + if (HAVE_STD_CPP14_FLAG) + set(CPP14_FLAG -std=gnu++14) endif () endif () set(CMAKE_REQUIRED_FLAGS ) else () - check_cxx_compiler_flag(-std=c++0x HAVE_STD_CPP0X_FLAG) - if (HAVE_STD_CPP0X_FLAG) - set(CPP11_FLAG -std=c++0x) + check_cxx_compiler_flag(-std=c++1y HAVE_STD_CPP1Y_FLAG) + if (HAVE_STD_CPP1Y_FLAG) + set(CPP14_FLAG -std=c++1y) endif () endif () endif () if (CMAKE_CXX_STANDARD) # Don't use -std compiler flag if CMAKE_CXX_STANDARD is specified. - set(CPP11_FLAG ) + set(CPP14_FLAG ) endif () -set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG}) +set(CMAKE_REQUIRED_FLAGS ${CPP14_FLAG}) # Check if variadic templates are working and not affected by GCC bug 39653: # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 459a77dd..b99925fa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,7 +7,7 @@ # at http://code.google.com/p/googletest/wiki/FAQ for more details. add_library(gmock STATIC gmock-gtest-all.cc gmock/gmock.h gtest/gtest.h gtest/gtest-spi.h) -target_compile_options(gmock PUBLIC ${CPP11_FLAG}) +target_compile_options(gmock PUBLIC ${CPP14_FLAG}) target_compile_definitions(gmock PUBLIC GTEST_HAS_STD_WSTRING=1) target_include_directories(gmock PUBLIC .) @@ -120,7 +120,7 @@ endif () check_cxx_compiler_flag(-fno-exceptions HAVE_FNO_EXCEPTIONS_FLAG) if (HAVE_FNO_EXCEPTIONS_FLAG) add_library(noexception-test ../fmt/format.cc) - target_compile_options(noexception-test PUBLIC ${CPP11_FLAG}) + target_compile_options(noexception-test PUBLIC ${CPP14_FLAG}) target_include_directories(noexception-test PRIVATE ${PROJECT_SOURCE_DIR}) target_compile_options(noexception-test PRIVATE -fno-exceptions) endif () @@ -129,7 +129,7 @@ if (FMT_PEDANTIC) # Test that the library compiles without windows.h. if (CMAKE_SYSTEM_NAME STREQUAL "Windows") add_library(no-windows-h-test ../fmt/format.cc) - target_compile_options(no-windows-h-test PUBLIC ${CPP11_FLAG}) + target_compile_options(no-windows-h-test PUBLIC ${CPP14_FLAG}) target_include_directories(no-windows-h-test PRIVATE ${PROJECT_SOURCE_DIR}) target_compile_definitions(no-windows-h-test PRIVATE FMT_USE_WINDOWS_H=0) endif () @@ -142,7 +142,7 @@ if (FMT_PEDANTIC) --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCPP11_FLAG=${CPP11_FLAG}" + "-DCPP14_FLAG=${CPP14_FLAG}" "-DSUPPORTS_USER_DEFINED_LITERALS=${SUPPORTS_USER_DEFINED_LITERALS}") # test if the targets are findable from the build directory @@ -155,7 +155,7 @@ if (FMT_PEDANTIC) --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCPP11_FLAG=${CPP11_FLAG}" + "-DCPP14_FLAG=${CPP14_FLAG}" "-DFMT_DIR=${PROJECT_BINARY_DIR}" "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") @@ -169,6 +169,6 @@ if (FMT_PEDANTIC) --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCPP11_FLAG=${CPP11_FLAG}" + "-DCPP14_FLAG=${CPP14_FLAG}" "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") endif () diff --git a/test/add-subdirectory-test/CMakeLists.txt b/test/add-subdirectory-test/CMakeLists.txt index e99bc673..bb02888a 100644 --- a/test/add-subdirectory-test/CMakeLists.txt +++ b/test/add-subdirectory-test/CMakeLists.txt @@ -5,11 +5,11 @@ project(fmt-test) add_subdirectory(../.. fmt) add_executable(library-test "main.cc") -target_compile_options(library-test PUBLIC ${CPP11_FLAG}) +target_compile_options(library-test PUBLIC ${CPP14_FLAG}) target_link_libraries(library-test fmt) if (TARGET fmt-header-only) add_executable(header-only-test "main.cc") - target_compile_options(header-only-test PUBLIC ${CPP11_FLAG}) + target_compile_options(header-only-test PUBLIC ${CPP14_FLAG}) target_link_libraries(header-only-test fmt-header-only) endif () diff --git a/test/compile-test/CMakeLists.txt b/test/compile-test/CMakeLists.txt index 4e90fb1f..775b4067 100644 --- a/test/compile-test/CMakeLists.txt +++ b/test/compile-test/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.8) include(CheckCXXSourceCompiles) set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../..) -set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG}) +set(CMAKE_REQUIRED_FLAGS ${CPP14_FLAG}) function (generate_source result fragment) set(${result} " diff --git a/test/find-package-test/CMakeLists.txt b/test/find-package-test/CMakeLists.txt index 54180419..a57de003 100644 --- a/test/find-package-test/CMakeLists.txt +++ b/test/find-package-test/CMakeLists.txt @@ -5,11 +5,11 @@ project(fmt-test) find_package(FMT REQUIRED) add_executable(library-test main.cc) -target_compile_options(library-test PUBLIC ${CPP11_FLAG}) +target_compile_options(library-test PUBLIC ${CPP14_FLAG}) target_link_libraries(library-test fmt) if (TARGET fmt-header-only) add_executable(header-only-test main.cc) - target_compile_options(header-only-test PUBLIC ${CPP11_FLAG}) + target_compile_options(header-only-test PUBLIC ${CPP14_FLAG}) target_link_libraries(header-only-test fmt-header-only) endif ()