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
POSITION_INDEPENDENT_CODE is set.
OLD behavior for this policy is to not manage
PIE link flags. The
NEW behavior is to add link flags if
POSITION_INDEPENDENT_CODE is set:
TRUE: flags to produce a position independent executable are passed to the linker step. For example
FALSE: flags not to produce a position independent executable are passed to the linker step. For example
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
CheckPIESupported module to check for support to ensure that the
POSITION_INDEPENDENT_CODE target property for executables will be honored at link time.
This policy was introduced in CMake version 3.14. Use the
cmake_policy() command to set it to
NEW explicitly. Unlike most policies, CMake version 3.15.2 does not warn when this policy is not set and simply uses
Android platform has a special handling of
PIE so it is not required to use the
CheckPIESupported module to ensure flags are passed to the linker.
OLD behavior of a policy is
deprecated by definition and may be removed in a future version of CMake.
Behave like CMake 3.13 and do not apply any
PIE flags at link stage.
cmake_minimum_required(VERSION 3.13) project(foo) # ... add_executable(foo ...) set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE)
CheckPIESupported module to detect whether
PIE is supported by the current linker and environment. Apply
PIE flags only if the linker supports them.
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)
© 2000–2019 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.