[cmake-developers] Adding logic to CMake for -fPIE and -fPIC

Brad King brad.king at kitware.com
Thu May 31 11:32:55 EDT 2012


On 05/30/2012 02:45 PM, Brad King wrote:
> Thanks for your patience with so many rounds of review.
> I think the topic is in good shape other than for Xcode.
> I'll try to look at Xcode when I get a chance.

The current implementation can be refactored in a way that
should make Xcode easy.  Instead of hard-coding duplicate
code in the Makefile and Ninja generators to call the

 cmLocalGenerator::GetShouldUseOldFlags
 cmLocalGenerator::AddSharedFlags
 cmLocalGenerator::AddPositionIndependentFlags

methods factor that logic out into a new

 cmLocalGenerator::AddCMP0018Flags(
   std::string& flags,
   cmTarget* target,
   std::string const& language);

method.  Then the above-three methods can be made *private*
inside cmLocalGenerator.  Please squash this approach back
into the current commits in the topic.

Then simply use the patch below for Xcode.

Thanks,
-Brad


diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 522f3da..5a5ce01 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -1594,14 +1594,14 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     if(strcmp(lang, "CXX") == 0)
       {
       this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
-      this->CurrentLocalGenerator->AddSharedFlags(cflags, lang, shared);
+      this->CurrentLocalGenerator->AddCMP0018Flags(flags, &target, "C");
       }

     // Add language-specific flags.
     this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);

     // Add shared-library flags if needed.
-    this->CurrentLocalGenerator->AddSharedFlags(flags, lang, shared);
+    this->CurrentLocalGenerator->AddCMP0018Flags(flags, &target, lang);
     }
   else if(binary)
   {



More information about the cmake-developers mailing list