mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-16 13:47:53 +00:00
Make C++ standard configurable
This commit is contained in:
parent
9fb50c56d0
commit
c3c27c4259
@ -21,12 +21,28 @@ option(PYBIND11_TEST "Build tests?" ${PYBIND11_MASTER_PROJECT})
|
|||||||
# Add a CMake parameter for choosing a desired Python version
|
# Add a CMake parameter for choosing a desired Python version
|
||||||
set(PYBIND11_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling the example application")
|
set(PYBIND11_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling the example application")
|
||||||
|
|
||||||
include(CheckCXXCompilerFlag)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools")
|
||||||
set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6 3.7)
|
set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6 3.7)
|
||||||
find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} REQUIRED)
|
find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} REQUIRED)
|
||||||
|
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
|
if(NOT MSVC AND NOT PYBIND11_CPP_STANDARD)
|
||||||
|
check_cxx_compiler_flag("-std=c++14" HAS_CPP14_FLAG)
|
||||||
|
check_cxx_compiler_flag("-std=c++11" HAS_CPP11_FLAG)
|
||||||
|
|
||||||
|
if (HAS_CPP14_FLAG)
|
||||||
|
set(PYBIND11_CPP_STANDARD -std=c++14)
|
||||||
|
elseif (HAS_CPP11_FLAG)
|
||||||
|
set(PYBIND11_CPP_STANDARD -std=c++11)
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unsupported compiler -- pybind11 requires C++11 support!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(PYBIND11_CPP_STANDARD ${PYBIND11_CPP_STANDARD} CACHE STRING
|
||||||
|
"C++ standard flag, e.g. -std=c++11 or -std=c++14. Defaults to latest available.")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Cache variables so pybind11_add_module can be used in parent projects
|
# Cache variables so pybind11_add_module can be used in parent projects
|
||||||
set(PYBIND11_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/include" CACHE INTERNAL "")
|
set(PYBIND11_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/include" CACHE INTERNAL "")
|
||||||
set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} CACHE INTERNAL "")
|
set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} CACHE INTERNAL "")
|
||||||
@ -67,16 +83,7 @@ function(pybind11_add_module target_name)
|
|||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
# Make sure C++11/14 are enabled
|
# Make sure C++11/14 are enabled
|
||||||
check_cxx_compiler_flag("-std=c++14" HAS_CPP14_FLAG)
|
target_compile_options(${target_name} PUBLIC ${PYBIND11_CPP_STANDARD})
|
||||||
check_cxx_compiler_flag("-std=c++11" HAS_CPP11_FLAG)
|
|
||||||
|
|
||||||
if (HAS_CPP14_FLAG)
|
|
||||||
target_compile_options(${target_name} PUBLIC "-std=c++14")
|
|
||||||
elseif (HAS_CPP11_FLAG)
|
|
||||||
target_compile_options(${target_name} PUBLIC "-std=c++11")
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Unsupported compiler -- pybind11 requires C++11 support!")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Enable link time optimization and set the default symbol
|
# Enable link time optimization and set the default symbol
|
||||||
# visibility to hidden (very important to obtain small binaries)
|
# visibility to hidden (very important to obtain small binaries)
|
||||||
|
Loading…
Reference in New Issue
Block a user