CMP0069.rst 2.9 KB

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