Adding logic to CMake for -fPIE and -fPIC

Stephen Kelly steveire at gmail.com
Thu May 3 16:02:09 UTC 2012


Hi there,

By default Qt is configured with a reduce-relocations flag to its configure 
script.

If that flag is enabled, then an #error in the preprocessor is hit if users 
of Qt do not compile with -fPIE or -fPIC in that case.

http://qt.gitorious.org/qt/qtbase/blobs/HEAD/src/corelib/global/qglobal.h

Compiling with -fPIE or -fPIC is not needed if Qt is configured with the 
flag -no-reduce-relocations as I do, so I didn't notice until now the extent 
of the problems this causes. 

In qmake the problem we see in cmake doesn't occur, because qmake knows 
whether it is building an executable or a shared library.

In cmake we need to set (exclusively) either -fPIE or -fPIC at directory 
level, and if we have executables and shared libraries in the same directory 
scope, we can't use them with the directory-level set() command.

There are a few ways to solve this, including 

* Wrapping all invokations of add_library and add_executable, which we would 
prefer not to.
* Adding logic to CMake so that it would do s/fPIE/PIC/ when building 
libraries and the opposite when building executables. This is what libtool 
does apparently (http://lists.debian.org/debian-
devel/2012/01/msg00784.html).
* Make set(CMAKE_POSITION_INDEPENDENT_BINARIES True) set the appropriate 
flags.

Any comments on those options?

Thanks,

Steve.
 



More information about the Kde-buildsystem mailing list