From 07d6f352a2b3bfdc8de0fb7f0fc58346502e0ee1 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 14 May 2021 13:59:15 -0700 Subject: [PATCH] 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. --- docs/compiling.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/compiling.rst b/docs/compiling.rst index 3a8a270d5..b8bb65ce7 100644 --- a/docs/compiling.rst +++ b/docs/compiling.rst @@ -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)