CMP0069.rst 2.9 KB

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