CMP0083.rst 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. CMP0083
  2. -------
  3. .. versionadded:: 3.14
  4. To control generation of Position Independent Executable (``PIE``) or not, some
  5. flags are required at link time.
  6. CMake 3.13 and lower did not add these link flags when
  7. :prop_tgt:`POSITION_INDEPENDENT_CODE` is set.
  8. The ``OLD`` behavior for this policy is to not manage ``PIE`` link flags. The
  9. ``NEW`` behavior is to add link flags if :prop_tgt:`POSITION_INDEPENDENT_CODE`
  10. is set:
  11. * Set to ``TRUE``: flags to produce a position independent executable are
  12. passed to the linker step. For example ``-pie`` for ``GCC``.
  13. * Set to ``FALSE``: flags not to produce a position independent executable are
  14. passed to the linker step. For example ``-no-pie`` for ``GCC``.
  15. * Not set: no flags are passed to the linker step.
  16. Since a given linker may not support ``PIE`` flags in all environments in
  17. which it is used, it is the project's responsibility to use the
  18. :module:`CheckPIESupported` module to check for support to ensure that the
  19. :prop_tgt:`POSITION_INDEPENDENT_CODE` target property for executables will be
  20. honored at link time.
  21. This policy was introduced in CMake version 3.14. Use the
  22. :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
  23. Unlike most policies, CMake version |release| does not warn when this policy is
  24. not set and simply uses ``OLD`` behavior.
  25. .. Note::
  26. Android platform has a special handling of ``PIE`` so it is not required
  27. to use the :module:`CheckPIESupported` module to ensure flags are passed to
  28. the linker.
  29. .. include:: DEPRECATED.txt
  30. Examples
  31. ^^^^^^^^
  32. Behave like CMake 3.13 and do not apply any ``PIE`` flags at link stage.
  33. .. code-block:: cmake
  34. cmake_minimum_required(VERSION 3.13)
  35. project(foo)
  36. # ...
  37. add_executable(foo ...)
  38. set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE)
  39. Use the :module:`CheckPIESupported` module to detect whether ``PIE`` is
  40. supported by the current linker and environment. Apply ``PIE`` flags only
  41. if the linker supports them.
  42. .. code-block:: cmake
  43. cmake_minimum_required(VERSION 3.14) # CMP0083 NEW
  44. project(foo)
  45. include(CheckPIESupported)
  46. check_pie_supported()
  47. # ...
  48. add_executable(foo ...)
  49. set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE)