Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a complete CMake update, part 1 of approximately 2.
CMake 3.7 or better is now required
This enables many simplifications, and a more unified approach to targets. Many if statements dropped, though a few more added for enhanced support for later CMake versions.
Reworked C++ support to properly handle C++ version in CMake instead manually
CMake 2.8, which came out three years before 2011, does not have C++11 support (hopefully not a surprise, though given the number of people that seem to want to use a new compiler with a CMake version that significantly predates it, I'm not sure). Now it does, so PyBind11 plays nice with C++ support! FINALLY! Key points:
PYBIND_CPP_STANDARD
is deprecated, and issues a warning. It does still work, though, just grabbing the last two digits and settingCMAKE_CXX_STANDARD
with it.CMAKE_CXX_STANDARD
is not required - CMake knows that pybind requires at least C++11 support, and will automatically add at least the C++11 flag if needed to any target that links to it (via compile features) if the compiler has a default less than C++11.CMAKE_CXX_STANDARD
(global) or CXX_STANDARD (per target, not inherited)Closes pybind#1097
If-less config files
The config file generated will not depend on the host system - this is a requirement for the CMake config files to be distributed in a pure Python wheel - which can't know what the host compiler / python version is beforehand. Generator expressions are used, which are evaluated during the build, rather than before.
Note: there are two ifs that affect the configs: If you generate with CMake 3.13+, it cannot be read by 3.7-3.12. However, this is much better than before, were you couldn't change much of anything after generating a Config file, and crucially, the 3.13+ one has a lower potential for bugs (it enforces that the dynamic lookup does not get de-duplicated accidentally). The main planned user of this feature is PyPI package, and there should be no problem getting CMake 3.13+ using pip.
Key first step for pybind#2266!
SYSTEM changes
The current handling of SYSTEM is not consistent with CMake standards. CMake treats all IMPORTED targets as SYSTEM, so this was/is always on when using configuration mode.Tthis now treats Python always as SYSTEM (may fix the warning we struggled with for a while), and treats PyBind11 as SYSTEM when being used as a subdirectory, so the SYSTEM argument to
pybind11_add_module
is no longer needed and is inconsistent withtarget_link_libraries
. A warning is printed if given. You can always setNO_SYSTEM_FROM_IMPORTED
if you want to make imported targets non-system.Smaller features
pybind11_VERSION*
andPROJECT_VERSION*(
, picked up correctly by CMake wherever it's needed (for example, by CPack)BUILD_TESTING
flag is now supported, along withPYBIND11_TEST
include(CTest)
here, which setsBUILD_TESTING
up for you, but I could.pybind11::module
target; it caused issues (closes pybind11 incorrectly adds "-fvisibility" flag to nvcc pybind/pybind11#1710, combined with flto change closes CXX flags passed to nvcc using CMake make compilation fail pybind/pybind11#1991), it went against the description (simplest possible flags), it clashes with the correct way to do this in thepybind11_add_module
function, and is better handled by a nice example (added to the docs).PYPBIND11_CLASSIC_LTO
to force the old search method and manual flags-DPy_DEBUG
with cmake pybind/pybind11#2018This has gotten large enough, so I'll be working on new FindPython support in the next PR. Also, we currently might be a bit sloppy about putting build produces in the source tree - I'll investigate that in the near future, too. This also should enable CMake configs in the python wheel, which when mixed with PEP 518 builds and scikit-build, could make something truly beautiful. :)
As a further test, I dropped this into boost-histogram (CMake mode) and awkward1 (both submodule systems) and verified that no changes were needed, it is backward compatible and still builds correctly locally.