Skip to content

Commit

Permalink
fix: better handling of PYBIND11_CPP_STANDARD
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Aug 6, 2020
1 parent c664d55 commit 227170d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tools/pybind11Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 227170d

Please sign in to comment.