Skip to content

Commit 9b8cb02

Browse files
authored
fix: respect PYTHON_VERSION if set in classic mode (#2414)
* fix: respect PYTHON_VERSION if set in classic mode * fix: add warning when using PYTHON_VERSION
1 parent 03b3d59 commit 9b8cb02

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

tools/pybind11Common.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ if(PYBIND11_CPP_STANDARD)
147147
else()
148148
set(supported_standards 11 14 17 20)
149149
if("${VAL}" IN_LIST supported_standards)
150-
message(WARNING "USE -DCMAKE_CXX_STANDARD=${VAL} instead of PYBIND11_PYTHON_VERSION")
150+
message(WARNING "USE -DCMAKE_CXX_STANDARD=${VAL} instead of PYBIND11_CPP_STANDARD")
151151
set(CMAKE_CXX_STANDARD
152152
${VAL}
153153
CACHE STRING "From PYBIND11_CPP_STANDARD")

tools/pybind11Tools.cmake

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@ if(pybind11_FIND_QUIETLY)
1212
set(_pybind11_quiet QUIET)
1313
endif()
1414

15-
# Add a CMake parameter for choosing a desired Python version
16-
if(NOT PYBIND11_PYTHON_VERSION)
15+
# If this is the first run, PYTHON_VERSION can stand in for PYBIND11_PYTHON_VERSION
16+
if(NOT DEFINED PYBIND11_PYTHON_VERSION AND DEFINED PYTHON_VERSION)
17+
message(WARNING "Set PYBIND11_PYTHON_VERSION to search for a specific version, not "
18+
"PYTHON_VERSION (which is an output). Assuming that is what you "
19+
"meant to do and continuing anyway.")
1720
set(PYBIND11_PYTHON_VERSION
18-
""
21+
"${PYTHON_VERSION}"
22+
CACHE STRING "Python version to use for compiling modules")
23+
unset(PYTHON_VERSION)
24+
unset(PYTHON_VERSION CACHE)
25+
else()
26+
# If this is set as a normal variable, promote it, otherwise, make an empty cache variable.
27+
set(PYBIND11_PYTHON_VERSION
28+
"${PYBIND11_PYTHON_VERSION}"
1929
CACHE STRING "Python version to use for compiling modules")
2030
endif()
2131

0 commit comments

Comments
 (0)