1CMP0069 2------- 3 4.. versionadded:: 3.9 5 6:prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` is enforced when enabled. 7 8CMake 3.9 and newer prefer to add IPO flags whenever the 9:prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target property is enabled and 10produce an error if flags are not known to CMake for the current compiler. 11Since a given compiler may not support IPO flags in all environments in which 12it is used, it is now the project's responsibility to use the 13:module:`CheckIPOSupported` module to check for support before enabling the 14:prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target property. This approach 15allows a project to conditionally activate IPO when supported. It also 16allows an end user to set the :variable:`CMAKE_INTERPROCEDURAL_OPTIMIZATION` 17variable in an environment known to support IPO even if the project does 18not enable the property. 19 20Since CMake 3.8 and lower only honored :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` 21for the Intel compiler on Linux, some projects may unconditionally enable the 22target property. Policy ``CMP0069`` provides compatibility with such projects. 23 24This policy takes effect whenever the IPO property is enabled. The ``OLD`` 25behavior for this policy is to add IPO flags only for Intel compiler on Linux. 26The ``NEW`` behavior for this policy is to add IPO flags for the current 27compiler or produce an error if CMake does not know the flags. 28 29This policy was introduced in CMake version 3.9. CMake version 30|release| warns when the policy is not set and uses ``OLD`` behavior. 31Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` 32explicitly. 33 34.. include:: DEPRECATED.txt 35 36Examples 37^^^^^^^^ 38 39Behave like CMake 3.8 and do not apply any IPO flags except for Intel compiler 40on Linux: 41 42.. code-block:: cmake 43 44 cmake_minimum_required(VERSION 3.8) 45 project(foo) 46 47 # ... 48 49 set_property(TARGET ... PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) 50 51Use the :module:`CheckIPOSupported` module to detect whether IPO is 52supported by the current compiler, environment, and CMake version. 53Produce a fatal error if support is not available: 54 55.. code-block:: cmake 56 57 cmake_minimum_required(VERSION 3.9) # CMP0069 NEW 58 project(foo) 59 60 include(CheckIPOSupported) 61 check_ipo_supported() 62 63 # ... 64 65 set_property(TARGET ... PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) 66 67Apply IPO flags only if compiler supports it: 68 69.. code-block:: cmake 70 71 cmake_minimum_required(VERSION 3.9) # CMP0069 NEW 72 project(foo) 73 74 include(CheckIPOSupported) 75 76 # ... 77 78 check_ipo_supported(RESULT result) 79 if(result) 80 set_property(TARGET ... PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) 81 endif() 82 83Apply IPO flags without any checks. This may lead to build errors if IPO 84is not supported by the compiler in the current environment. Produce an 85error if CMake does not know IPO flags for the current compiler: 86 87.. code-block:: cmake 88 89 cmake_minimum_required(VERSION 3.9) # CMP0069 NEW 90 project(foo) 91 92 # ... 93 94 set_property(TARGET ... PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) 95