Merge topic 'patch-CheckIPOSupported'

a04fd272c2 CheckIPOSupported: Update documentation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10443
This commit is contained in:
Brad King 2025-03-11 13:50:12 +00:00 committed by Kitware Robot
commit d8242c2d46

View File

@ -7,9 +7,9 @@ CheckIPOSupported
.. versionadded:: 3.9
Check whether the compiler supports an interprocedural optimization (IPO/LTO).
Use this before enabling the :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target
property.
This module provides a function to check whether the compiler supports an
interprocedural optimization (IPO/LTO). Use this module before enabling the
:prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target property.
.. command:: check_ipo_supported
@ -60,21 +60,33 @@ property.
Examples
^^^^^^^^
Checking whether the compiler supports IPO and emitting a fatal error if it is
not supported:
.. code-block:: cmake
include(CheckIPOSupported)
check_ipo_supported() # fatal error if IPO is not supported
set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
The following example demonstrates how to use the ``CheckIPOSupported`` module
to enable IPO for the target only when supported by the compiler and to issue a
warning if it is not. Additionally, projects may want to provide a
configuration option to control when IPO is enabled. For example:
.. code-block:: cmake
# Optional IPO. Do not use IPO if it's not supported by compiler.
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported: ${output}")
endif()
option(FOO_ENABLE_IPO "Enable IPO/LTO")
if(FOO_ENABLE_IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported: ${output}")
endif()
endif()
#]=======================================================================]
# X_RESULT - name of the final result variable