Docs: CMake LTO honor global flag

In this example, the IPO/LTO flags should not be added if the
general property is already set for all targets via
`CMAKE_INTERPROCEDURAL_OPTIMIZATION`.

Also, if `CMAKE_INTERPROCEDURAL_OPTIMIZATION` is set to `OFF`, LTO
flags should also not be added. This is sometimes needed when working
around compiler bugs with IPO/LTO, e.g. on ppc64le with some
toolchains.
This commit is contained in:
Axel Huebl 2021-05-14 13:59:15 -07:00
parent f61855b9d8
commit 07d6f352a2
No known key found for this signature in database
GPG Key ID: 472D2C364E21D94B
1 changed files with 4 additions and 1 deletions

View File

@ -500,7 +500,10 @@ You can use these targets to build complex applications. For example, the
add_library(example MODULE main.cpp)
target_link_libraries(example PRIVATE pybind11::module pybind11::lto pybind11::windows_extras)
target_link_libraries(example PRIVATE pybind11::module pybind11::windows_extras)
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
target_link_libraries(example PRIVATE pybind11::lto)
endif()
pybind11_extension(example)
pybind11_strip(example)