Skip to content

Commit b1d212c

Browse files
committed
Adding docs and change log entry
1 parent 9d663ce commit b1d212c

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ v2.3.0 (Not yet released)
1515
for non-MSVC compilers).
1616
`#934 <https://github.com/pybind/pybind11/pull/934>`_.
1717

18+
* Improved CMake C++ standard discovery for CMake 3.8+, and allow compiler features
19+
to be used on CMake 3.1+. Added C++17 standard check.
20+
`#1098 <https://github.com/pybind/pybind11/pull/1098>`_.
21+
1822
v2.2.1 (September 14, 2017)
1923
-----------------------------------------------------
2024

docs/compiling.rst

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,32 @@ regular LTO if ``-flto=thin`` is not available.
9696
Configuration variables
9797
-----------------------
9898

99-
By default, pybind11 will compile modules with the C++14 standard, if available
100-
on the target compiler, falling back to C++11 if C++14 support is not
101-
available. Note, however, that this default is subject to change: future
102-
pybind11 releases are expected to migrate to newer C++ standards as they become
103-
available. To override this, the standard flag can be given explicitly in
104-
``PYBIND11_CPP_STANDARD``:
99+
By default, pybind11 will compile modules with the highest C++ standard available
100+
on the target compiler, from the set C++17, C++14, and C++11. With CMake 3.8+, this
101+
uses CMake's compile features mechinism and meta-features to detect your compiler's
102+
abilities. Older CMake versions fall back to manually trying to compile a mini-program
103+
with each flag.
104+
105+
If you want to override this behavior, you have three options:
106+
107+
CMake 3.1+: If you set ``CMAKE_CXX_STANDARD`` before including pybind11, it will be respected and no
108+
futher action will be taken by pybind11.
109+
110+
CMake 3.1+: If you explicitly set a list of compile features in ``PYBIND11_CXX_FEATURES``, that will be used.
111+
See `CMAKE_CXX_KNOWN_FEATURES <https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html>`_
112+
for your CMake version.
113+
114+
.. code-block:: cmake
115+
116+
# These meta-features were added in CMake 3.8:
117+
set(PYBIND11_CXX_FEATURES cxx_std_11)
118+
set(PYBIND11_CXX_FEATURES cxx_std_14)
119+
set(PYBIND11_CXX_FEATURES cxx_std_17) # Experimental C++17 support
120+
121+
add_subdirectory(pybind11) # or find_package(pybind11)
122+
123+
CMake 2.8+: If neither of the above is set and you want to explicitly control the flag,
124+
the standard flag can be given as ``PYBIND11_CPP_STANDARD``:
105125

106126
.. code-block:: cmake
107127
@@ -116,10 +136,14 @@ available. To override this, the standard flag can be given explicitly in
116136
117137
add_subdirectory(pybind11) # or find_package(pybind11)
118138
119-
Note that this and all other configuration variables must be set **before** the
139+
Note that these and all other configuration variables must be set **before** the
120140
call to ``add_subdirectory`` or ``find_package``. The variables can also be set
121141
when calling CMake from the command line using the ``-D<variable>=<value>`` flag.
122142

143+
Mixed C and C++ projects should use the ``PYBIND11_CXX_FEATURES`` mechanism to avoid
144+
adding flags to the C compiler. If you need the latest version of CMake, it is trivial
145+
to install; try ``pip install cmake`` or ``pip install --user cmake``.
146+
123147
The target Python version can be selected by setting ``PYBIND11_PYTHON_VERSION``
124148
or an exact Python installation can be specified with ``PYTHON_EXECUTABLE``.
125149
For example:

0 commit comments

Comments
 (0)