MantisBT - CMake
View Issue Details
0014983CMakeCMakepublic2014-06-20 07:192016-06-10 14:31
Ludwig Nussel 
Kitware Robot 
normalminorhave not tried
closedmoved 
LinuxopenSUSEFactory
CMake 3.0 
 
0014983: POSITION_INDEPENDENT_CODE does not add -pie
I tried to make wodim a position independent executable to comply with distro policies. I did that by adding this to CMakeLists.txt:
SET_TARGET_PROPERTIES(wodim PROPERTIES POSITION_INDEPENDENT_CODE TRUE)

That however does not set -pie for the linker flags so no actual pie binary is
created. An extra "LINK_FLAGS -pie" is necessary. I guess that's not the
intention of the abstraction.
SET_TARGET_PROPERTIES(wodim PROPERTIES POSITION_INDEPENDENT_CODE TRUE)

should result in

$ readelf -h wodim|grep Type:
  Type: DYN (Shared object file)
No tags attached.
Issue History
2014-06-20 07:19Ludwig NusselNew Issue
2014-06-23 10:40Brad KingAssigned To => Stephen Kelly
2014-06-23 10:40Brad KingStatusnew => assigned
2014-06-24 04:55Stephen KellyNote Added: 0036237
2014-06-24 09:39Stephen KellyNote Added: 0036239
2014-06-24 11:32Stephen KellyNote Added: 0036242
2014-06-24 11:32Stephen KellyAssigned ToStephen Kelly =>
2014-06-24 11:32Stephen KellyStatusassigned => backlog
2016-06-10 14:29Kitware RobotNote Added: 0042569
2016-06-10 14:29Kitware RobotStatusbacklog => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0036237)
Stephen Kelly   
2014-06-24 04:55   
http://lfs.osuosl.org/hlfs/view/unstable/glibc/chapter02/pie.html [^]
(0036239)
Stephen Kelly   
2014-06-24 09:39   
This feature was added for the needs of Qt-based executables, as qglobal.h gained a snippet similar to

 #if !defined(__PIC__)
 # error Must compile with -fPIC or -fPIE
 #endif

I followed the lead of qmake, which did not add -pie. I am trying to find out why:

 https://codereview.qt-project.org/88178 [^]
(0036242)
Stephen Kelly   
2014-06-24 11:32   
I don't think I know enough about the issues surrounding this. Changing the behavior of POSITION_INDEPENDENT_CODE affects all users of Qt 4 and 5 imported targets.

The 'safest' way forward is a POSITION_INDEPENDENT_EXECUTABLE property which implies POSITION_INDEPENDENT_CODE.
(0042569)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.