CMP0083.rst 2.2 KB

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