Brad King wrote:

> On 5/5/2012 4:27 PM, Stephen Kelly wrote:
>>> Ok. Then factoring out how it is set is the first step. Looking at the
>>> output of 'git grep -i " \?pic\b"' and 'git grep -wi +Z', there are many
>>> different ways of telling the compiler that we want this property. Most
>>> of them are ancient unix which I can't test. Should I change those at
>>> all?
>>
>> This issue is the subject of a TODO comment in my wip branch on this
>> topic.
> 
> They all set the CMAKE_SHARED_LIBRARY_${lang}_FLAGS one way or
> another.  AFAIK CMake platform files use that variable exclusively
> for -fPIC or equivalent flag.  

It appears so to me too, yes.

> It is possible that projects set
> the value to add their own flags though.  I also know there are
> projects that *read* the variable to get the flag so it can be
> used in a static library (working around the lack of the feature
> you're adding).
> 
> I think the most compatible way to do this is:
> 
> (1) Define a new platform variable named specifically to hold this
> flag, like CMAKE_${lang}_PIC_FLAG or something.

I've done something similar already.

> (2) Document the property as using that flag *and* suppressing
> use of CMAKE_SHARED_LIBRARY_${lang}_FLAGS altogether.

Hmm, I don't think I understand why this is necessary.

> (3) Leave the property undefined even for shared libs and let
> the project set the property to get new behavior.

That's not compatible with people thinking they'll get PIC shared libraries 
by default already though. I don't see why changing that is necessary.

>> https://gitorious.org/~steveire/cmake/steveires-cmake/commits/position-
independent-targets
> 
> Good start.  I'd like to amend my suggested property name to be
> "POSITION_INDEPENDENT_CODE".

Done.

> How should this interact with OBJECT library support?  If I compile
> a set of objects meant for use in an executable shouldn't they use
> -fPIE instead of -fPIC?  CMake cannot know where $<TARGET_OBJECTS:...>
> will be used when it compiles an object library.

My understanding is that it is ok to link objects compiled with -fPIC (ie, 
not -fPIE) into an executable, but you don't get all the position 
independence benefit by using that instead of -fPIE. So it is probably ok to 
use -fPIC for OBJECT_LIBRARY compilations.

Thanks,

Steve.



--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to