No. CMAKE_<lang>_LINK_OPTIONS_NO_PIE
is not used by default. If POSITION_INDEPENDENT_CODE
is not set (TRUE
or FALSE
), no flags are applied to link step.
PIE
flag (-fpie
or -fno_pie
) is applied only if property POSITION_INDEPENDENT_CODE
is set (‘TRUE’ or ‘FALSE’).
To ensure consistency for the link step, define the variable CMAKE_POSITION_INDEPENDENT_CODE
and include module CheckPIESupport
in the root CMakelist.txt
and call check_pie_supported()
.
variable CMAKE_POSITION_INDEPENDENT_CODE
can take TRUE
or FALSE
:
- set to
FALSE
:gcc
andispc
will compile in their default mode (PIC
for gcc andNO_PIC
for ispc) but the linker will specify-fno_pie
so link will succeed. - set to
TRUE
:gcc
andispc
will compile with option-fPIC
and the linker will use option-fpie
and the link will succeed.