Skip to content

Commit daea113

Browse files
polmeshenryiii
andauthored
fix(cmake): upgrade maximum supported CMake version to 3.27 (#4786)
* Upgrade maximum supported CMake version to 3.27 to fix warning with CMP0148 policy (#4785) * Update `macos_brew_install_llvm` pipeline to use expected Python installation * Fix `Python_EXECUTABLE` Cmake variable typo * Apply suggestions from code review * fix: use FindPython for CMake 3.18+ by default for pybind11's tests Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * tests: fix issues with finding Python Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * tests: also set executable on subdir tests Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * fix(cmake): correct logic for FindPython Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Update ci.yml * Revert "Update ci.yml" This reverts commit 33798ad. --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
1 parent 7d538a4 commit daea113

File tree

13 files changed

+76
-35
lines changed

13 files changed

+76
-35
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,10 @@ jobs:
973973
- name: Configure C++11
974974
# LTO leads to many undefined reference like
975975
# `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&)
976-
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build
976+
run: >-
977+
cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
978+
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
979+
-S . -B build
977980
978981
- name: Build C++11
979982
run: cmake --build build -j 2
@@ -991,7 +994,10 @@ jobs:
991994
run: git clean -fdx
992995

993996
- name: Configure C++14
994-
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build2
997+
run: >-
998+
cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
999+
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
1000+
-S . -B build2
9951001
9961002
- name: Build C++14
9971003
run: cmake --build build2 -j 2
@@ -1009,7 +1015,10 @@ jobs:
10091015
run: git clean -fdx
10101016

10111017
- name: Configure C++17
1012-
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build3
1018+
run: >-
1019+
cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
1020+
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
1021+
-S . -B build3
10131022
10141023
- name: Build C++17
10151024
run: cmake --build build3 -j 2

CMakeLists.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ endif()
1212

1313
cmake_minimum_required(VERSION 3.5)
1414

15-
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
15+
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
1616
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
1717
# the behavior using the following workaround:
18-
if(${CMAKE_VERSION} VERSION_LESS 3.26)
18+
if(${CMAKE_VERSION} VERSION_LESS 3.27)
1919
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
2020
else()
21-
cmake_policy(VERSION 3.26)
21+
cmake_policy(VERSION 3.27)
2222
endif()
2323

2424
if(_pybind11_cmp0148)
@@ -92,9 +92,15 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
9292
set(pybind11_system "")
9393

9494
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
95+
if(CMAKE_VERSION VERSION_LESS "3.18")
96+
set(_pybind11_findpython_default OFF)
97+
else()
98+
set(_pybind11_findpython_default ON)
99+
endif()
95100
else()
96101
set(PYBIND11_MASTER_PROJECT OFF)
97102
set(pybind11_system SYSTEM)
103+
set(_pybind11_findpython_default OFF)
98104
endif()
99105

100106
# Options
@@ -116,9 +122,18 @@ cmake_dependent_option(
116122
"Install pybind11 headers in Python include directory instead of default installation prefix"
117123
OFF "PYBIND11_INSTALL" OFF)
118124

119-
cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" OFF
125+
cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default}
120126
"NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
121127

128+
# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
129+
# (makes transition easier while we support both modes).
130+
if(PYBIND11_MASTER_PROJECT
131+
AND PYBIND11_FINDPYTHON
132+
AND DEFINED PYTHON_EXECUTABLE
133+
AND NOT DEFINED Python_EXECUTABLE)
134+
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
135+
endif()
136+
122137
# NB: when adding a header don't forget to also add it to setup.py
123138
set(PYBIND11_HEADERS
124139
include/pybind11/detail/class.h

docs/advanced/embedding.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ information, see :doc:`/compiling`.
1818

1919
.. code-block:: cmake
2020
21-
cmake_minimum_required(VERSION 3.5...3.26)
21+
cmake_minimum_required(VERSION 3.5...3.27)
2222
project(example)
2323
2424
find_package(pybind11 REQUIRED) # or `add_subdirectory(pybind11)`

docs/compiling.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ extension module can be created with just a few lines of code:
241241

242242
.. code-block:: cmake
243243
244-
cmake_minimum_required(VERSION 3.5...3.26)
244+
cmake_minimum_required(VERSION 3.5...3.27)
245245
project(example LANGUAGES CXX)
246246
247247
add_subdirectory(pybind11)
@@ -498,7 +498,7 @@ You can use these targets to build complex applications. For example, the
498498

499499
.. code-block:: cmake
500500
501-
cmake_minimum_required(VERSION 3.5...3.26)
501+
cmake_minimum_required(VERSION 3.5...3.27)
502502
project(example LANGUAGES CXX)
503503
504504
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
@@ -556,7 +556,7 @@ information about usage in C++, see :doc:`/advanced/embedding`.
556556

557557
.. code-block:: cmake
558558
559-
cmake_minimum_required(VERSION 3.5...3.26)
559+
cmake_minimum_required(VERSION 3.5...3.27)
560560
project(example LANGUAGES CXX)
561561
562562
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)

tests/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
cmake_minimum_required(VERSION 3.5)
99

10-
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
10+
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
1111
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
1212
# the behavior using the following workaround:
13-
if(${CMAKE_VERSION} VERSION_LESS 3.26)
13+
if(${CMAKE_VERSION} VERSION_LESS 3.27)
1414
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
1515
else()
16-
cmake_policy(VERSION 3.26)
16+
cmake_policy(VERSION 3.27)
1717
endif()
1818

1919
# Filter out items; print an optional message if any items filtered. This ignores extensions.

tests/test_cmake_build/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ function(pybind11_add_build_test name)
55

66
set(build_options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
77

8+
list(APPEND build_options "-DPYBIND11_FINDPYTHON=${PYBIND11_FINDPYTHON}")
89
if(PYBIND11_FINDPYTHON)
9-
list(APPEND build_options "-DPYBIND11_FINDPYTHON=${PYBIND11_FINDPYTHON}")
10-
1110
if(DEFINED Python_ROOT_DIR)
1211
list(APPEND build_options "-DPython_ROOT_DIR=${Python_ROOT_DIR}")
1312
endif()

tests/test_cmake_build/installed_embed/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cmake_minimum_required(VERSION 3.5)
22

3-
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
3+
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
44
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
55
# the behavior using the following workaround:
6-
if(${CMAKE_VERSION} VERSION_LESS 3.26)
6+
if(${CMAKE_VERSION} VERSION_LESS 3.27)
77
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
88
else()
9-
cmake_policy(VERSION 3.26)
9+
cmake_policy(VERSION 3.27)
1010
endif()
1111

1212
project(test_installed_embed CXX)

tests/test_cmake_build/installed_function/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
cmake_minimum_required(VERSION 3.5)
22
project(test_installed_module CXX)
33

4-
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
4+
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
55
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
66
# the behavior using the following workaround:
7-
if(${CMAKE_VERSION} VERSION_LESS 3.26)
7+
if(${CMAKE_VERSION} VERSION_LESS 3.27)
88
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
99
else()
10-
cmake_policy(VERSION 3.26)
10+
cmake_policy(VERSION 3.27)
1111
endif()
1212

1313
project(test_installed_function CXX)

tests/test_cmake_build/installed_target/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cmake_minimum_required(VERSION 3.5)
22

3-
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
3+
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
44
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
55
# the behavior using the following workaround:
6-
if(${CMAKE_VERSION} VERSION_LESS 3.26)
6+
if(${CMAKE_VERSION} VERSION_LESS 3.27)
77
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
88
else()
9-
cmake_policy(VERSION 3.26)
9+
cmake_policy(VERSION 3.27)
1010
endif()
1111

1212
project(test_installed_target CXX)

tests/test_cmake_build/subdirectory_embed/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cmake_minimum_required(VERSION 3.5)
22

3-
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
3+
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
44
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
55
# the behavior using the following workaround:
6-
if(${CMAKE_VERSION} VERSION_LESS 3.26)
6+
if(${CMAKE_VERSION} VERSION_LESS 3.27)
77
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
88
else()
9-
cmake_policy(VERSION 3.26)
9+
cmake_policy(VERSION 3.27)
1010
endif()
1111

1212
project(test_subdirectory_embed CXX)
@@ -16,6 +16,12 @@ set(PYBIND11_INSTALL
1616
CACHE BOOL "")
1717
set(PYBIND11_EXPORT_NAME test_export)
1818

19+
# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
20+
# (makes transition easier while we support both modes).
21+
if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE)
22+
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
23+
endif()
24+
1925
add_subdirectory("${pybind11_SOURCE_DIR}" pybind11)
2026

2127
# Test basic target functionality

0 commit comments

Comments
 (0)