Skip to content

Docs: CMake LTO honor global flag #3006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,26 @@ You can use these targets to build complex applications. For example, the
set_target_properties(example PROPERTIES CXX_VISIBILITY_PRESET "hidden"
CUDA_VISIBILITY_PRESET "hidden")

Since prior to CMake 3.18 the ``INTERPROCEDURAL_OPTIMIZATION`` property exists but is not working reliably, a manual user section around linking the legacy ``pybind11::lto`` target should look like this:

.. code-block:: cmake

# LTO/IPO: CMake target properties work well for 3.18+ and are buggy before
set(_USE_PY_LTO ON) # default shall be ON
if(DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION) # overwrite default if defined
if(NOT CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(_USE_PY_LTO OFF)
endif()
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
set_target_properties(example PROPERTIES
INTERPROCEDURAL_OPTIMIZATION ${_USE_PY_LTO})
else()
if(_USE_PY_LTO)
target_link_libraries(example PRIVATE pybind11::lto)
endif()
endif()

Instead of setting properties, you can set ``CMAKE_*`` variables to initialize these correctly.

.. warning::
Expand Down