diff --git a/tools/pybind11Config.cmake.in b/tools/pybind11Config.cmake.in index 6f0a406fb..3dd1b2c1a 100644 --- a/tools/pybind11Config.cmake.in +++ b/tools/pybind11Config.cmake.in @@ -90,7 +90,6 @@ if(NOT TARGET ${PN}::pybind11) set_property(TARGET ${PN}::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES}) endif() - select_cxx_standard() set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "${PYBIND11_CPP_STANDARD}") get_property(_iid TARGET ${PN}::pybind11 PROPERTY INTERFACE_INCLUDE_DIRECTORIES) diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index 62de9c9fd..86ccd58d3 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -18,27 +18,27 @@ find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} REQUIRED) include(CheckCXXCompilerFlag) include(CMakeParseArguments) -function(select_cxx_standard) - if(NOT PYBIND11_CPP_STANDARD) - if(NOT MSVC) - check_cxx_compiler_flag("-std=c++14" HAS_CPP14_FLAG) - check_cxx_compiler_flag("-std=c++11" HAS_CPP11_FLAG) +if(NOT PYBIND11_CPP_STANDARD) + if(NOT MSVC) + check_cxx_compiler_flag("-std=c++14" HAS_CPP14_FLAG) - if (HAS_CPP14_FLAG) - set(PYBIND11_CPP_STANDARD -std=c++14) - elseif (HAS_CPP11_FLAG) + if (HAS_CPP14_FLAG) + set(PYBIND11_CPP_STANDARD -std=c++14) + else() + check_cxx_compiler_flag("-std=c++11" HAS_CPP11_FLAG) + if (HAS_CPP11_FLAG) set(PYBIND11_CPP_STANDARD -std=c++11) else() message(FATAL_ERROR "Unsupported compiler -- pybind11 requires C++11 support!") endif() - elseif(MSVC) - set(PYBIND11_CPP_STANDARD /std:c++14) endif() - - set(PYBIND11_CPP_STANDARD ${PYBIND11_CPP_STANDARD} CACHE STRING - "C++ standard flag, e.g. -std=c++11, -std=c++14, /std:c++14. Defaults to C++14 mode." FORCE) + elseif(MSVC) + set(PYBIND11_CPP_STANDARD /std:c++14) endif() -endfunction() + + set(PYBIND11_CPP_STANDARD ${PYBIND11_CPP_STANDARD} CACHE STRING + "C++ standard flag, e.g. -std=c++11, -std=c++14, /std:c++14. Defaults to C++14 mode." FORCE) +endif() # Checks whether the given CXX/linker flags can compile and link a cxx file. cxxflags and # linkerflags are lists of flags to use. The result variable is a unique variable name for each set @@ -165,7 +165,6 @@ function(pybind11_add_module target_name) endif() endif() - select_cxx_standard() # Make sure C++11/14 are enabled target_compile_options(${target_name} PUBLIC ${PYBIND11_CPP_STANDARD})