[CMake] POSITION_INDEPENDENT_CODE's [un]expected behaviour

Oleksii Vilchanskyi alexvilchansky at yahoo.com
Fri Jul 21 13:01:16 EDT 2017


Hello,

I would like to ask about POSITION_INDEPENDENT_CODE target property. As
of CMake 3.8.2 POSITION_INDEPENDENT_CODE appends -fPIE or -fPIC to
CMAKE_<LANG>_FLAGS and CMAKE_EXE_LINKER_FLAGS when building an
executable or a library respectively. However, to build a PIE -pie
linker flag is additionally required. Thus POSITION_INDEPENDENT_CODE is
not behaving as expected being a really easy to fix for someone aware
with CMake codebase.

Is there any reason why it wasn't added when the property was
introduced? Somebody proposed introducing
POSITION_INDEPENDENT_EXECUTABLE later on in addition to
POSITION_INDEPENDENT_CODE to maintain backwards compatibility (I suppose
policies are also a solution?).

This email is the result of the thread
<https://github.com/arsenm/sanitizers-cmake/issues/13> and the message
<https://github.com/arsenm/sanitizers-cmake/issues/13#issuecomment-315532253>
by Juan Navarro (big thanks to him), which fully summarizes CMake's
POSITION_INDEPENDENT_CODE treatment and links to multiple bugs: this one
<https://cmake.org/Bug/view.php?id=14983>, so far without attention, and
this one <https://gitlab.kitware.com/cmake/cmake/issues/16382>, resolved
for Android.

Thank you.

Regards,
Oleksii Vilchanskyi

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170721/3b78399c/attachment.html>


More information about the CMake mailing list