@@ -96,12 +96,32 @@ regular LTO if ``-flto=thin`` is not available.
9696Configuration 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
120140call to ``add_subdirectory `` or ``find_package ``. The variables can also be set
121141when 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+
123147The target Python version can be selected by setting ``PYBIND11_PYTHON_VERSION ``
124148or an exact Python installation can be specified with ``PYTHON_EXECUTABLE ``.
125149For example:
0 commit comments