1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 11:18:40 +08:00

CheckIPOSupported: Extend documentation

- Added intro code block showing how to include this module.
- Added brief description about IPO and LTO and how it is enabled in
  CMake.
- Used "command" instead of "function".
- Reworded few descriptions.
- Synced indentation for items related to the command section.
- Added "See Also" sections to related target properties and variables.
This commit is contained in:
Peter Kokot
2025-05-18 23:56:31 +02:00
parent e33692e625
commit 294b30b27e
5 changed files with 75 additions and 22 deletions

View File

@@ -15,3 +15,9 @@ target is created.
There is also the per-configuration :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION_<CONFIG>` There is also the per-configuration :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION_<CONFIG>`
target property, which overrides :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target property, which overrides :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION`
if it is set. if it is set.
See Also
^^^^^^^^
* The :module:`CheckIPOSupported` module to check whether the compiler
supports interprocedural optimization before enabling this target property.

View File

@@ -10,3 +10,9 @@ configuration.
This property is initialized by the This property is initialized by the
:variable:`CMAKE_INTERPROCEDURAL_OPTIMIZATION_<CONFIG>` variable if it is set :variable:`CMAKE_INTERPROCEDURAL_OPTIMIZATION_<CONFIG>` variable if it is set
when a target is created. when a target is created.
See Also
^^^^^^^^
* The :module:`CheckIPOSupported` module to check whether the compiler
supports interprocedural optimization before enabling this target property.

View File

@@ -8,3 +8,8 @@ Default value for :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` of targets.
This variable is used to initialize the :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` This variable is used to initialize the :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION`
property on all the targets. See that target property for additional property on all the targets. See that target property for additional
information. information.
See Also
^^^^^^^^
* The :variable:`CMAKE_INTERPROCEDURAL_OPTIMIZATION_<CONFIG>` variable.

View File

@@ -8,3 +8,8 @@ Default value for :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION_<CONFIG>` of targets.
This variable is used to initialize the :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION_<CONFIG>` This variable is used to initialize the :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION_<CONFIG>`
property on all the targets. See that target property for additional property on all the targets. See that target property for additional
information. information.
See Also
^^^^^^^^
* The :variable:`CMAKE_INTERPROCEDURAL_OPTIMIZATION` variable.

View File

@@ -7,25 +7,56 @@ CheckIPOSupported
.. versionadded:: 3.9 .. versionadded:: 3.9
This module provides a function to check whether the compiler supports an This module provides a command to check whether the compiler supports
interprocedural optimization (IPO/LTO). Use this module before enabling the interprocedural optimization (IPO/LTO).
:prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target property.
Load this module in a CMake project with:
.. code-block:: cmake
include(CheckIPOSupported)
Interprocedural optimization is a compiler technique that performs
optimizations across translation units (i.e., across source files), allowing
the compiler to analyze and optimize the entire program as a whole rather
than file-by-file. This can improve performance by enabling more aggressive
inlining and dead code elimination. When these optimizations are applied at
link time, the process is typically referred to as link-time optimization
(LTO), which is a common form of IPO.
In CMake, interprocedural optimization can be enabled on a per-target basis
using the :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target property, or
for all targets in the current scope using the
:variable:`CMAKE_INTERPROCEDURAL_OPTIMIZATION` variable.
Use this module before enabling the interprocedural optimization on targets
to ensure the compiler supports IPO/LTO.
Commands
^^^^^^^^
This module provides the following command:
.. command:: check_ipo_supported .. command:: check_ipo_supported
Checks whether the compiler supports interprocedural optimization (IPO/LTO):
.. code-block:: cmake .. code-block:: cmake
check_ipo_supported([RESULT <result>] [OUTPUT <output>] check_ipo_supported(
[LANGUAGES <lang>...]) [RESULT <result-var>]
[OUTPUT <output-var>]
[LANGUAGES <lang>...]
)
Options are: Options are:
``RESULT <result>`` ``RESULT <result-var>``
Set ``<result>`` variable to ``YES`` if IPO is supported by the Set ``<result-var>`` variable to ``YES`` if IPO is supported by the
compiler and ``NO`` otherwise. If this option is not given then compiler and ``NO`` otherwise. If this option is not given then
the command will issue a fatal error if IPO is not supported. the command will issue a fatal error if IPO is not supported.
``OUTPUT <output>`` ``OUTPUT <output-var>``
Set ``<output>`` variable with details about any error. Set ``<output-var>`` variable with details about any error.
``LANGUAGES <lang>...`` ``LANGUAGES <lang>...``
Specify languages whose compilers to check. Specify languages whose compilers to check.
@@ -44,18 +75,18 @@ interprocedural optimization (IPO/LTO). Use this module before enabling the
If this option is not given, the default languages are picked from If this option is not given, the default languages are picked from
the current :prop_gbl:`ENABLED_LANGUAGES` global property. the current :prop_gbl:`ENABLED_LANGUAGES` global property.
.. note:: .. note::
To use ``check_ipo_supported()``, policy :policy:`CMP0069` must be set to To use ``check_ipo_supported()``, policy :policy:`CMP0069` must be set to
``NEW``; otherwise, a fatal error will occur. ``NEW``; otherwise, a fatal error will occur.
.. versionadded:: 3.13 .. versionadded:: 3.13
Support for Visual Studio generators. Support for Visual Studio generators.
.. versionadded:: 3.24 .. versionadded:: 3.24
The check uses the caller's :variable:`CMAKE_<LANG>_FLAGS` The check uses the caller's :variable:`CMAKE_<LANG>_FLAGS`
and :variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` values. and :variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` values.
See policy :policy:`CMP0138`. See policy :policy:`CMP0138`.
Examples Examples
^^^^^^^^ ^^^^^^^^
@@ -69,10 +100,10 @@ not supported:
check_ipo_supported() # fatal error if IPO is not supported check_ipo_supported() # fatal error if IPO is not supported
set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
The following example demonstrates how to use the ``CheckIPOSupported`` module The following example demonstrates how to use this module to enable IPO for
to enable IPO for the target only when supported by the compiler and to issue a the target only when supported by the compiler and to issue a warning if it
warning if it is not. Additionally, projects may want to provide a is not. Additionally, projects may want to provide a configuration option
configuration option to control when IPO is enabled. For example: to control when IPO is enabled. For example:
.. code-block:: cmake .. code-block:: cmake