fix: better handling of PYBIND11_CPP_STANDARD

This commit is contained in:
Henry Schreiner 2020-08-03 11:44:16 -04:00 committed by Henry Schreiner
parent c664d55757
commit 227170dc2f

View File

@ -25,14 +25,23 @@ include(CheckCXXCompilerFlag)
# Warn or error if old variable name used
if(PYBIND11_CPP_STANDARD)
if(NOT CMAKE_CXX_STANDARD)
string(REGEX MATCH [=[..^]=] VAL "${PYBIND11_CPP_STANDARD}")
string(REGEX MATCH [[..$]] VAL "${PYBIND11_CPP_STANDARD}")
if(CMAKE_CXX_STANDARD)
if(NOT CMAKE_CXX_STANDARD STREQUAL VAL)
message(WARNING "CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} does not match "
"PYBIND11_CPP_STANDARD=${PYBIND11_CPP_STANDARD}, "
"please remove PYBIND11_CPP_STANDARD from your cache")
endif()
else()
set(supported_standards 11 14 17 20)
if("${VAL}" IN_LIST supported_standards)
message(WARNING "USE -DCMAKE_CXX_STANDARD=${VAL} instead of PYBIND11_PYTHON_VERSION")
set(CMAKE_CXX_STANDARD ${VAL})
set(CMAKE_CXX_STANDARD
${VAL}
CACHE STRING "From PYBIND11_CPP_STANDARD")
else()
message(FATAL_ERROR "PYBIND11_CPP_STANDARD should be replaced with CMAKE_CXX_STANDARD")
message(FATAL_ERROR "PYBIND11_CPP_STANDARD should be replaced with CMAKE_CXX_STANDARD "
"(last two chars: ${VAL} not understood as a valid CXX std)")
endif()
endif()
endif()