mirror of
https://github.com/shadps4-emu/ext-fmt.git
synced 2024-11-23 09:49:42 +00:00
Detect C++14 compiler support
This commit is contained in:
parent
be5b4552d9
commit
d5e918b61f
@ -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)
|
||||
|
@ -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 ()
|
||||
|
@ -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 <cmath>
|
||||
int main() {}" FMT_CPP11_CMATH)
|
||||
# Check if including <unistd.h> works with -std=c++11.
|
||||
int main() {}" FMT_CPP14_CMATH)
|
||||
# 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/.
|
||||
check_cxx_source_compiles("
|
||||
#include <unistd.h>
|
||||
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 <stdio.h>
|
||||
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
|
@ -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 ()
|
||||
|
@ -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 ()
|
||||
|
@ -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} "
|
||||
|
@ -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 ()
|
||||
|
Loading…
Reference in New Issue
Block a user