Skip to content

Commit 56a9f9c

Browse files
committed
fix: address review points from @YannickJadoul
1 parent 20ec16c commit 56a9f9c

File tree

4 files changed

+42
-31
lines changed

4 files changed

+42
-31
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ install:
2626
$env:CMAKE_INCLUDE_PATH = "eigen-eigen-67e894c6cd8f;$env:CMAKE_INCLUDE_PATH"
2727
build_script:
2828
- cmake -G "%CMAKE_GENERATOR%" -A "%CMAKE_ARCH%"
29-
-DPYBIND11_CPP_STANDARD=/std:c++14
29+
-DCMAKE_CXX_STANDARD=14
3030
-DPYBIND11_WERROR=ON
3131
-DDOWNLOAD_CATCH=ON
3232
-DCMAKE_SUPPRESS_REGENERATION=1

docs/compiling.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ standard explicitly with
103103

104104
.. code-block:: cmake
105105
106-
# Use just one of these:
107-
set(CMAKE_CXX_STANDARD 14)
108-
set(CMAKE_CXX_STANDARD 17)
106+
set(CMAKE_CXX_STANDARD 14) # or 11, 14, 17, 20
109107
110108
111109
The variables can also be set when calling CMake from the command line using
@@ -120,7 +118,9 @@ For example:
120118
.. code-block:: bash
121119
122120
cmake -DPYBIND11_PYTHON_VERSION=3.6 ..
123-
# or
121+
# Another method:
122+
cmake -DPYTHON_EXECUTABLE=/path/to/python ..
123+
# You will often see this idiom:
124124
cmake -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") ..
125125
126126
find_package vs. add_subdirectory
@@ -144,12 +144,19 @@ the pybind11 repository :
144144

145145
.. code-block:: bash
146146
147+
# Classic CMake
147148
cd pybind11
148149
mkdir build
149150
cd build
150151
cmake ..
151152
make install
152153
154+
# CMake 3.15+
155+
cd pybind11
156+
cmake -S . -B build
157+
cmake --build build -j 2 # Build on 2 cores
158+
cmake --install build
159+
153160
Once detected, the aforementioned ``pybind11_add_module`` can be employed as
154161
before. The function usage and configuration variables are identical no matter
155162
if pybind11 is added as a subdirectory or found as an installed package. You
@@ -198,11 +205,11 @@ to an independently constructed (through ``add_library``, not
198205

199206
.. code-block:: cmake
200207
201-
cmake_minimum_required(3.9)
202208
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
203-
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
209+
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
210+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) # CMake 3.9+ required
204211
205-
or set teh corisponding property (without the ``CMAKE_``) on the targets
212+
or set the corresponding property (without the ``CMAKE_``) on the targets
206213
manually.
207214

208215
Embedding the Python interpreter

tools/pybind11Config.cmake.in

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,15 @@
6060

6161
@PACKAGE_INIT@
6262

63-
set(PN pybind11)
63+
# Location of pybind11/pybind11.h
64+
set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
6465

65-
# location of pybind11/pybind11.h
66-
set(${PN}_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
66+
set(pybind11_LIBRARY "")
67+
set(pybind11_DEFINITIONS USING_pybind11)
6768

68-
set(${PN}_LIBRARY "")
69-
set(${PN}_DEFINITIONS USING_${PN})
69+
check_required_components(pybind11)
7070

71-
check_required_components(${PN})
72-
73-
# make detectable the FindPythonLibsNew.cmake module
71+
# Make the FindPythonLibsNew.cmake module available
7472
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
7573

7674
include(pybind11Tools)
@@ -79,19 +77,20 @@ include(pybind11Tools)
7977
# Don't include targets if this file is being picked up by another
8078
# project which has already built this as a subproject
8179
#-----------------------------------------------------------------------------
82-
if(NOT TARGET ${PN}::pybind11)
83-
include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets.cmake")
80+
if(NOT TARGET pybind11::pybind11)
81+
include("${CMAKE_CURRENT_LIST_DIR}/pybind11Targets.cmake")
8482

8583
find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} MODULE REQUIRED)
86-
set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS})
87-
set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS})
88-
set_property(TARGET ${PN}::embed APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES})
89-
if(WIN32 OR CYGWIN)
90-
set_property(TARGET ${PN}::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES})
91-
endif()
9284

93-
get_property(_iid TARGET ${PN}::pybind11 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
94-
get_property(_ill TARGET ${PN}::module PROPERTY INTERFACE_LINK_LIBRARIES)
95-
set(${PN}_INCLUDE_DIRS ${_iid})
96-
set(${PN}_LIBRARIES ${_ico} ${_ill})
85+
set_property(TARGET pybind11::pybind11 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS})
86+
set_property(TARGET pybind11::pybind11 APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS})
87+
88+
set_property(TARGET pybind11::embed APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES})
89+
set_property(TARGET pybind11::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES
90+
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>")
91+
92+
get_property(_iid TARGET pybind11::pybind11 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
93+
get_property(_ill TARGET pybind11::module PROPERTY INTERFACE_LINK_LIBRARIES)
94+
set(pybind11_INCLUDE_DIRS ${_iid})
95+
set(pybind11_LIBRARIES ${_ico} ${_ill})
9796
endif()

tools/pybind11Tools.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} REQUIRED)
2727
include(CheckCXXCompilerFlag)
2828
include(CMakeParseArguments)
2929

30-
# Use the language standards abstraction if CMake supports it with the current compiler
30+
# Warn or error if old variable name used
3131
if(PYBIND11_CPP_STANDARD)
32-
message(WARNING "USE -DCMAKE_CXX_STANDARD=11 instead of PYBIND11_PYTHON_VERSION")
3332
if(NOT CMAKE_CXX_STANDARD)
3433
string(REGEX MATCH
3534
[=[..^]=]
3635
VAL
3736
"${PYBIND11_CPP_STANDARD}")
38-
set(CMAKE_CXX_STANDARD ${VAL})
37+
set(supported_standards 11 14 17 20)
38+
if("${VAL}" IN_LIST supported_standards)
39+
message(WARNING "USE -DCMAKE_CXX_STANDARD=${VAL} instead of PYBIND11_PYTHON_VERSION")
40+
set(CMAKE_CXX_STANDARD ${VAL})
41+
else()
42+
message(FATAL_ERROR "PYBIND11_CPP_STANDARD should be replaced with CMAKE_CXX_STANDARD")
43+
endif()
3944
endif()
4045
endif()
4146

0 commit comments

Comments
 (0)