Adding logic to CMake for -fPIE and -fPIC

2012-05-03 Thread Stephen Kelly

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.
 

___
Kde-buildsystem mailing list
Kde-buildsystem@kde.org
https://mail.kde.org/mailman/listinfo/kde-buildsystem


Re: Adding logic to CMake for -fPIE and -fPIC

2012-05-03 Thread Brad King

On 5/3/2012 12:02 PM, Stephen Kelly wrote:

* Make set(CMAKE_POSITION_INDEPENDENT_BINARIES True) set the appropriate flags.


This is the right choice IMO, though the variable should just
initialize a POSITION_INDEPENDENT target property.  The target
property would then map to the right flag.  You'll need to factor
out and generalize the CMAKE_SHARED_LIBRARY_${lang}_FLAGS platform
information variable:

 
http://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/Compiler/GNU.cmake;hb=v2.8.8#l24

currently used to add -fPIC to compilation of objects in shared
libraries.  Make its use based on the new property, and simply
make the property true by default for shared libraries.

-Brad
___
Kde-buildsystem mailing list
Kde-buildsystem@kde.org
https://mail.kde.org/mailman/listinfo/kde-buildsystem