Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmake): correctly detect FindPython policy and better warning #4806

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

# Propagate this policy (FindPythonInterp removal) so it can be detected later
if(NOT CMAKE_VERSION VERSION_LESS "3.27")
cmake_policy(GET CMP0148 _pybind11_cmp0148)
endif()

cmake_minimum_required(VERSION 3.5)

# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
Expand All @@ -16,6 +21,11 @@ else()
cmake_policy(VERSION 3.26)
endif()

if(_pybind11_cmp0148)
cmake_policy(SET CMP0148 ${_pybind11_cmp0148})
unset(_pybind11_cmp0148)
endif()

# Avoid infinite recursion if tests include this as a subdirectory
if(DEFINED PYBIND11_MASTER_PROJECT)
return()
Expand Down
16 changes: 16 additions & 0 deletions tools/FindPythonLibsNew.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ if(NOT PythonLibsNew_FIND_VERSION)
set(PythonLibsNew_FIND_VERSION "3.6")
endif()

if(NOT CMAKE_VERSION VERSION_LESS "3.27")
cmake_policy(GET CMP0148 _pybind11_cmp0148)
if(NOT _pybind11_cmp0148)
message(
AUTHOR_WARNING
"Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs "
"modules are removed. Run \"cmake --help-policy CMP0148\" for policy "
"details. Use the cmake_policy command to set the policy and suppress "
"this warning, or preferably upgrade to using FindPython, either by "
"calling it explicitly before pybind11, or by setting "
"PYBIND11_FINDPYTHON ON before pybind11.")
endif()
cmake_policy(SET CMP0148 OLD)
unset(_pybind11_cmp0148)
endif()

find_package(PythonInterp ${PythonLibsNew_FIND_VERSION} ${_pythonlibs_required}
${_pythonlibs_quiet})

Expand Down
Loading