File: CMP0083.rst

package info (click to toggle)
cmake 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 152,348 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (70 lines) | stat: -rw-r--r-- 2,133 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
CMP0083
-------

.. versionadded:: 3.14

To control generation of Position Independent Executable (``PIE``) or not, some
flags are required at link time.

CMake 3.13 and lower did not add these link flags when
:prop_tgt:`POSITION_INDEPENDENT_CODE` is set.

The ``OLD`` behavior for this policy is to not manage ``PIE`` link flags. The
``NEW`` behavior is to add link flags if :prop_tgt:`POSITION_INDEPENDENT_CODE`
is set:

* Set to ``TRUE``: flags to produce a position independent executable are
  passed to the linker step. For example ``-pie`` for ``GCC``.
* Set to ``FALSE``: flags not to produce a position independent executable are
  passed to the linker step. For example ``-no-pie`` for ``GCC``.
* Not set: no flags are passed to the linker step.

Since a given linker may not support ``PIE`` flags in all environments in
which it is used, it is the project's responsibility to use the
:module:`CheckPIESupported` module to check for support to ensure that the
:prop_tgt:`POSITION_INDEPENDENT_CODE` target property for executables will be
honored at link time.

.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.14
.. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
.. include:: include/STANDARD_ADVICE.rst

.. Note::

   Android platform has a special handling of ``PIE`` so it is not required
   to use the :module:`CheckPIESupported` module to ensure flags are passed to
   the linker.

.. include:: include/DEPRECATED.rst

Examples
^^^^^^^^

Behave like CMake 3.13 and do not apply any ``PIE`` flags at link stage.

.. code-block:: cmake

  cmake_minimum_required(VERSION 3.13)
  project(foo)

  # ...

  add_executable(foo ...)
  set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE)

Use the :module:`CheckPIESupported` module to detect whether ``PIE`` is
supported by the current linker and environment.  Apply ``PIE`` flags only
if the linker supports them.

.. code-block:: cmake

  cmake_minimum_required(VERSION 3.14) # CMP0083 NEW
  project(foo)

  include(CheckPIESupported)
  check_pie_supported()

  # ...

  add_executable(foo ...)
  set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE)