Commit d5e918b6 authored by Victor Zverovich's avatar Victor Zverovich

Detect C++14 compiler support

parent be5b4552
...@@ -23,7 +23,7 @@ option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF) ...@@ -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_DOC "Generate the doc target." ${MASTER_PROJECT})
option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT}) option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT})
option(FMT_TEST "Generate the test 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) project(FMT)
...@@ -43,7 +43,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) ...@@ -43,7 +43,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/support/cmake") "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake")
include(cxx11) include(cxx14)
if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wshadow -pedantic) set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wshadow -pedantic)
......
...@@ -16,7 +16,7 @@ if (FMT_CPPFORMAT) ...@@ -16,7 +16,7 @@ if (FMT_CPPFORMAT)
endif () endif ()
# Starting with cmake 3.1 the CXX_STANDARD property can be used instead. # 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) if (FMT_PEDANTIC)
target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS}) target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS})
endif () endif ()
......
# C++11 feature support detection # C++14 feature support detection
if (NOT FMT_USE_CPP11) if (NOT FMT_USE_CPP14)
return() return()
endif () endif ()
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
if (FMT_USE_CPP11) if (FMT_USE_CPP14)
check_cxx_compiler_flag(-std=c++11 HAVE_STD_CPP11_FLAG) check_cxx_compiler_flag(-std=c++14 HAVE_STD_CPP14_FLAG)
if (HAVE_STD_CPP11_FLAG) if (HAVE_STD_CPP14_FLAG)
# Check if including cmath works with -std=c++11 and -O3. # 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/. # 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(" check_cxx_source_compiles("
#include <cmath> #include <cmath>
int main() {}" FMT_CPP11_CMATH) int main() {}" FMT_CPP14_CMATH)
# Check if including <unistd.h> works with -std=c++11. # Check if including <unistd.h> works with -std=c++14.
# It may not in MinGW due to bug http://sourceforge.net/p/mingw/bugs/2024/. # It may not in MinGW due to bug http://sourceforge.net/p/mingw/bugs/2024/.
check_cxx_source_compiles(" check_cxx_source_compiles("
#include <unistd.h> #include <unistd.h>
int main() {}" FMT_CPP11_UNISTD_H) int main() {}" FMT_CPP14_UNISTD_H)
# Check if snprintf works with -std=c++11. It may not in MinGW. # Check if snprintf works with -std=c++14. It may not in MinGW.
check_cxx_source_compiles(" check_cxx_source_compiles("
#include <stdio.h> #include <stdio.h>
int main() { int main() {
char buffer[10]; char buffer[10];
snprintf(buffer, 10, \"foo\"); snprintf(buffer, 10, \"foo\");
}" FMT_CPP11_SNPRINTF) }" FMT_CPP14_SNPRINTF)
if (FMT_CPP11_CMATH AND FMT_CPP11_UNISTD_H AND FMT_CPP11_SNPRINTF) if (FMT_CPP14_CMATH AND FMT_CPP14_UNISTD_H AND FMT_CPP14_SNPRINTF)
set(CPP11_FLAG -std=c++11) set(CPP14_FLAG -std=c++14)
else () else ()
check_cxx_compiler_flag(-std=gnu++11 HAVE_STD_GNUPP11_FLAG) check_cxx_compiler_flag(-std=gnu++14 HAVE_STD_GNUPP14_FLAG)
if (HAVE_STD_CPP11_FLAG) if (HAVE_STD_CPP14_FLAG)
set(CPP11_FLAG -std=gnu++11) set(CPP14_FLAG -std=gnu++14)
endif () endif ()
endif () endif ()
set(CMAKE_REQUIRED_FLAGS ) set(CMAKE_REQUIRED_FLAGS )
else () else ()
check_cxx_compiler_flag(-std=c++0x HAVE_STD_CPP0X_FLAG) check_cxx_compiler_flag(-std=c++1y HAVE_STD_CPP1Y_FLAG)
if (HAVE_STD_CPP0X_FLAG) if (HAVE_STD_CPP1Y_FLAG)
set(CPP11_FLAG -std=c++0x) set(CPP14_FLAG -std=c++1y)
endif () endif ()
endif () endif ()
endif () endif ()
if (CMAKE_CXX_STANDARD) if (CMAKE_CXX_STANDARD)
# Don't use -std compiler flag if CMAKE_CXX_STANDARD is specified. # Don't use -std compiler flag if CMAKE_CXX_STANDARD is specified.
set(CPP11_FLAG ) set(CPP14_FLAG )
endif () 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: # Check if variadic templates are working and not affected by GCC bug 39653:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# at http://code.google.com/p/googletest/wiki/FAQ for more details. # at http://code.google.com/p/googletest/wiki/FAQ for more details.
add_library(gmock STATIC add_library(gmock STATIC
gmock-gtest-all.cc gmock/gmock.h gtest/gtest.h gtest/gtest-spi.h) 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_compile_definitions(gmock PUBLIC GTEST_HAS_STD_WSTRING=1)
target_include_directories(gmock PUBLIC .) target_include_directories(gmock PUBLIC .)
...@@ -120,7 +120,7 @@ endif () ...@@ -120,7 +120,7 @@ endif ()
check_cxx_compiler_flag(-fno-exceptions HAVE_FNO_EXCEPTIONS_FLAG) check_cxx_compiler_flag(-fno-exceptions HAVE_FNO_EXCEPTIONS_FLAG)
if (HAVE_FNO_EXCEPTIONS_FLAG) if (HAVE_FNO_EXCEPTIONS_FLAG)
add_library(noexception-test ../fmt/format.cc) 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_include_directories(noexception-test PRIVATE ${PROJECT_SOURCE_DIR})
target_compile_options(noexception-test PRIVATE -fno-exceptions) target_compile_options(noexception-test PRIVATE -fno-exceptions)
endif () endif ()
...@@ -129,7 +129,7 @@ if (FMT_PEDANTIC) ...@@ -129,7 +129,7 @@ if (FMT_PEDANTIC)
# Test that the library compiles without windows.h. # Test that the library compiles without windows.h.
if (CMAKE_SYSTEM_NAME STREQUAL "Windows") if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_library(no-windows-h-test ../fmt/format.cc) 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_include_directories(no-windows-h-test PRIVATE ${PROJECT_SOURCE_DIR})
target_compile_definitions(no-windows-h-test PRIVATE FMT_USE_WINDOWS_H=0) target_compile_definitions(no-windows-h-test PRIVATE FMT_USE_WINDOWS_H=0)
endif () endif ()
...@@ -142,7 +142,7 @@ if (FMT_PEDANTIC) ...@@ -142,7 +142,7 @@ if (FMT_PEDANTIC)
--build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options --build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCPP11_FLAG=${CPP11_FLAG}" "-DCPP14_FLAG=${CPP14_FLAG}"
"-DSUPPORTS_USER_DEFINED_LITERALS=${SUPPORTS_USER_DEFINED_LITERALS}") "-DSUPPORTS_USER_DEFINED_LITERALS=${SUPPORTS_USER_DEFINED_LITERALS}")
# test if the targets are findable from the build directory # test if the targets are findable from the build directory
...@@ -155,7 +155,7 @@ if (FMT_PEDANTIC) ...@@ -155,7 +155,7 @@ if (FMT_PEDANTIC)
--build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options --build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCPP11_FLAG=${CPP11_FLAG}" "-DCPP14_FLAG=${CPP14_FLAG}"
"-DFMT_DIR=${PROJECT_BINARY_DIR}" "-DFMT_DIR=${PROJECT_BINARY_DIR}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
...@@ -169,6 +169,6 @@ if (FMT_PEDANTIC) ...@@ -169,6 +169,6 @@ if (FMT_PEDANTIC)
--build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options --build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCPP11_FLAG=${CPP11_FLAG}" "-DCPP14_FLAG=${CPP14_FLAG}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
endif () endif ()
...@@ -5,11 +5,11 @@ project(fmt-test) ...@@ -5,11 +5,11 @@ project(fmt-test)
add_subdirectory(../.. fmt) add_subdirectory(../.. fmt)
add_executable(library-test "main.cc") 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) target_link_libraries(library-test fmt)
if (TARGET fmt-header-only) if (TARGET fmt-header-only)
add_executable(header-only-test "main.cc") 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) target_link_libraries(header-only-test fmt-header-only)
endif () endif ()
...@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.8) ...@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.8)
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../..) 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) function (generate_source result fragment)
set(${result} " set(${result} "
......
...@@ -5,11 +5,11 @@ project(fmt-test) ...@@ -5,11 +5,11 @@ project(fmt-test)
find_package(FMT REQUIRED) find_package(FMT REQUIRED)
add_executable(library-test main.cc) 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) target_link_libraries(library-test fmt)
if (TARGET fmt-header-only) if (TARGET fmt-header-only)
add_executable(header-only-test main.cc) 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) target_link_libraries(header-only-test fmt-header-only)
endif () endif ()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment