[Cmake-commits] CMake branch, next, updated. v2.8.8-2986-g396e39c

Stephen Kelly steveire at gmail.com
Mon Jun 4 17:47:55 EDT 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  396e39cd274459d40070e1ec486e3cafb843dbac (commit)
       via  b7e082d70506a887e89a6ff76d682c9e34bf4874 (commit)
       via  5fb6ce7d915abd0c346e0e372fa2c6fddb0ef38a (commit)
       via  db27637685087f267c5337dcd8de6cf7ac2346d3 (commit)
       via  c22b8ee5a8d99c13ccc227fc50a351a3f649b65e (commit)
       via  07be743afb7281317ab8b330027d1b4e958426d6 (commit)
       via  5c6c7decc721c1d7220a0dd81d9e680c83a18aea (commit)
      from  62616267883c53ffadd8b8846a40473402e0a9a4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=396e39cd274459d40070e1ec486e3cafb843dbac
commit 396e39cd274459d40070e1ec486e3cafb843dbac
Merge: 6261626 b7e082d
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Mon Jun 4 17:47:52 2012 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Mon Jun 4 17:47:52 2012 -0400

    Merge topic 'position-independent-targets' into next
    
    b7e082d Don't use CMAKE_${lang}_SHARED_FLAGS in cmLocalGenerator::GetTargetFlags
    5fb6ce7 Initialize POSITION_INDEPENDENT_CODE property from global.
    db27637 Use replacement variables for SHARED_LIBRARY flags.
    c22b8ee Create the POSITION_INDEPENDENT_CODE property to initialize flags.
    07be743 Add a COMPILE_OPTIONS_DLL variable to replace using _FLAGS for that.
    5c6c7de Add compiler specific position independent flags.


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b7e082d70506a887e89a6ff76d682c9e34bf4874
commit b7e082d70506a887e89a6ff76d682c9e34bf4874
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed May 30 20:13:09 2012 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Jun 4 23:47:01 2012 +0200

    Don't use CMAKE_${lang}_SHARED_FLAGS in cmLocalGenerator::GetTargetFlags
    
    It shouldn't be needed here.

diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 36bac38..c3df658 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1549,12 +1549,6 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
         return;
         }
       this->AddLanguageFlags(flags, linkLanguage, buildType.c_str());
-      std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
-      sharedFlagsVar += linkLanguage;
-      sharedFlagsVar += "_FLAGS";
-      flags += " ";
-      flags += this->Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
-      flags += " ";
       cmOStringStream linklibs;
       this->OutputLinkLibraries(linklibs, target, false);
       linkLibs = linklibs.str();

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5fb6ce7d915abd0c346e0e372fa2c6fddb0ef38a
commit 5fb6ce7d915abd0c346e0e372fa2c6fddb0ef38a
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat May 5 22:19:23 2012 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Jun 4 23:47:01 2012 +0200

    Initialize POSITION_INDEPENDENT_CODE property from global.
    
    Also consume the global property when running try_compile commands.

diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index ed485e3..1ae7035 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -281,6 +281,10 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
       flag += this->Makefile->GetSafeDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
       cmakeFlags.push_back(flag);
       }
+    if(this->Makefile->GetDefinition("CMAKE_POSITION_INDEPENDENT_CODE")!=0)
+      {
+      fprintf(fout, "SET(CMAKE_POSITION_INDEPENDENT_CODE \"ON\")\n");
+      }
 
     /* Use a random file name to avoid rapid creation and deletion
        of the same executable name (some filesystems fail on that).  */
diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index 9e33d75..592d931 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -1350,6 +1350,14 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
      "See that target property for additional information.",
      false,
      "Variables that Control the Build");
+  cm->DefineProperty
+    ("CMAKE_POSITION_INDEPENDENT_FLAGS", cmProperty::VARIABLE,
+     "Default value for POSITION_INDEPENDENT_CODE of targets.",
+     "This variable is used to initialize the "
+     "POSITION_INDEPENDENT_CODE property on all the targets. "
+     "See that target property for additional information.",
+     false,
+     "Variables that Control the Build");
 
 //   Variables defined when the a language is enabled These variables will
 // also be defined whenever CMake has loaded its support for compiling (LANG)
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index b40f4ee..4f3f2c5 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -1318,6 +1318,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
     {
     this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
     }
+  this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
 
   // Record current policies for later use.
   this->PolicyStatusCMP0003 =
diff --git a/Tests/PositionIndependentTargets/CMakeLists.txt b/Tests/PositionIndependentTargets/CMakeLists.txt
index 89369fb..eec893d 100644
--- a/Tests/PositionIndependentTargets/CMakeLists.txt
+++ b/Tests/PositionIndependentTargets/CMakeLists.txt
@@ -7,6 +7,7 @@ include(CheckCXXSourceCompiles)
 
 include_directories("${CMAKE_CURRENT_SOURCE_DIR}") # For pic_test.h
 
+add_subdirectory(global)
 add_subdirectory(targets)
 
 add_executable(PositionIndependentTargets main.cpp)
diff --git a/Tests/PositionIndependentTargets/global/CMakeLists.txt b/Tests/PositionIndependentTargets/global/CMakeLists.txt
new file mode 100644
index 0000000..5f9fe13
--- /dev/null
+++ b/Tests/PositionIndependentTargets/global/CMakeLists.txt
@@ -0,0 +1,30 @@
+
+set(CMAKE_POSITION_INDEPENDENT_CODE True)
+
+add_executable(test_target_executable_global
+  "${CMAKE_CURRENT_SOURCE_DIR}/../pic_main.cpp"
+)
+
+add_library(test_target_shared_library_global
+  SHARED "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp"
+)
+
+add_library(test_target_static_library_global
+  STATIC "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp"
+)
+
+file(READ
+  "${CMAKE_CURRENT_SOURCE_DIR}/../pic_test.h"
+  PIC_HEADER_CONTENT
+)
+
+check_cxx_source_compiles(
+  "
+${PIC_HEADER_CONTENT}
+int main(int,char**) { return 0; }\n"
+  PIC_TRY_COMPILE_RESULT
+)
+
+if (NOT PIC_TRY_COMPILE_RESULT)
+  message(SEND_ERROR "TRY_COMPILE with content requiring __PIC__ failed.")
+endif()

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=db27637685087f267c5337dcd8de6cf7ac2346d3
commit db27637685087f267c5337dcd8de6cf7ac2346d3
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Thu May 17 13:14:48 2012 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Jun 4 23:47:01 2012 +0200

    Use replacement variables for SHARED_LIBRARY flags.
    
    AddCMP0018Flags is added to cmLocalGenerator, replacing AddSharedFlags,
    and allowing making it private.

diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 522f3da..938977b 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(cflags, &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)
   {
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 59db51c..36bac38 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1963,6 +1963,33 @@ void cmLocalGenerator::AddSharedFlags(std::string& flags,
 }
 
 //----------------------------------------------------------------------------
+void cmLocalGenerator::AddCMP0018Flags(std::string &flags, cmTarget* target,
+                                       std::string const& lang)
+{
+  int targetType = target->GetType();
+
+  bool shared = ((targetType == cmTarget::SHARED_LIBRARY) ||
+                  (targetType == cmTarget::MODULE_LIBRARY));
+
+  if (this->GetShouldUseOldFlags(shared, lang))
+    {
+    this->AddSharedFlags(flags, lang.c_str(), shared);
+    }
+  else
+    {
+    // Add position independendent flags, if needed.
+    if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE"))
+      {
+      this->AddPositionIndependentFlags(flags, lang, targetType);
+      }
+    if (shared)
+      {
+      this->AppendFeatureOptions(flags, lang.c_str(), "DLL");
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
 bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
                                             const std::string &lang) const
 {
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 027d340..1d8a7d1 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -140,7 +140,8 @@ public:
 
   void AddLanguageFlags(std::string& flags, const char* lang,
                         const char* config);
-  void AddSharedFlags(std::string& flags, const char* lang, bool shared);
+  void AddCMP0018Flags(std::string &flags, cmTarget* target,
+                       std::string const& lang);
   void AddConfigVariableFlags(std::string& flags, const char* var,
                               const char* config);
   ///! Append flags to a string.
@@ -426,6 +427,7 @@ private:
   std::string ConvertToOutputForExistingCommon(const char* remote,
                                                std::string const& result);
 
+  void AddSharedFlags(std::string& flags, const char* lang, bool shared);
   bool GetShouldUseOldFlags(bool shared, const std::string &lang) const;
   void AddPositionIndependentFlags(std::string& flags, std::string const& l,
                                    int targetType);
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index 408f287..df89275 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -245,9 +245,6 @@ std::string cmMakefileTargetGenerator::GetFlags(const std::string &l)
     std::string flags;
     const char *lang = l.c_str();
 
-    bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) ||
-                   (this->Target->GetType() == cmTarget::MODULE_LIBRARY));
-
     // Add language feature flags.
     this->AddFeatureFlags(flags, lang);
 
@@ -260,8 +257,7 @@ std::string cmMakefileTargetGenerator::GetFlags(const std::string &l)
       this->AddFortranFlags(flags);
       }
 
-    // Add shared-library flags if needed.
-    this->LocalGenerator->AddSharedFlags(flags, lang, shared);
+    this->LocalGenerator->AddCMP0018Flags(flags, this->Target, lang);
 
     // Add include directory flags.
     this->AddIncludeFlags(flags, lang);
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 80007f1..b3394bb 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -140,11 +140,8 @@ cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source,
   //   }
 
   // Add shared-library flags if needed.
-  {
-  bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) ||
-                 (this->Target->GetType() == cmTarget::MODULE_LIBRARY));
-  this->GetLocalGenerator()->AddSharedFlags(flags, language.c_str(), shared);
-  }
+  this->LocalGenerator->AddCMP0018Flags(flags, this->Target,
+                                        language.c_str());
 
   // TODO: Handle response file.
   // Add include directory flags.
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 5972c19..76c45fa 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -315,6 +315,8 @@ IF(BUILD_TESTING)
 
   ADD_TEST_MACRO(Module.GenerateExportHeader GenerateExportHeader)
 
+  ADD_TEST_MACRO(PositionIndependentTargets PositionIndependentTargets)
+
   ADD_TEST(LinkFlags-prepare
     ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
     --build-and-test
diff --git a/Tests/PositionIndependentTargets/CMakeLists.txt b/Tests/PositionIndependentTargets/CMakeLists.txt
new file mode 100644
index 0000000..89369fb
--- /dev/null
+++ b/Tests/PositionIndependentTargets/CMakeLists.txt
@@ -0,0 +1,12 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(PositionIndependentTargets)
+
+include(CheckCXXSourceCompiles)
+
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}") # For pic_test.h
+
+add_subdirectory(targets)
+
+add_executable(PositionIndependentTargets main.cpp)
diff --git a/Tests/PositionIndependentTargets/main.cpp b/Tests/PositionIndependentTargets/main.cpp
new file mode 100644
index 0000000..e72cef7
--- /dev/null
+++ b/Tests/PositionIndependentTargets/main.cpp
@@ -0,0 +1,2 @@
+
+int main(int,char**) { return 0; }
diff --git a/Tests/PositionIndependentTargets/pic_lib.cpp b/Tests/PositionIndependentTargets/pic_lib.cpp
new file mode 100644
index 0000000..085b189
--- /dev/null
+++ b/Tests/PositionIndependentTargets/pic_lib.cpp
@@ -0,0 +1,2 @@
+
+#include "pic_test.h"
diff --git a/Tests/PositionIndependentTargets/pic_main.cpp b/Tests/PositionIndependentTargets/pic_main.cpp
new file mode 100644
index 0000000..6a41a7a
--- /dev/null
+++ b/Tests/PositionIndependentTargets/pic_main.cpp
@@ -0,0 +1,4 @@
+
+#include "pic_test.h"
+
+int main(int,char**) { return 0; }
diff --git a/Tests/PositionIndependentTargets/pic_test.h b/Tests/PositionIndependentTargets/pic_test.h
new file mode 100644
index 0000000..5c88670
--- /dev/null
+++ b/Tests/PositionIndependentTargets/pic_test.h
@@ -0,0 +1,6 @@
+
+#if defined(__ELF__)
+#  if !defined(__PIC__)
+#    error "The POSITION_INDEPENDENT_CODE property should cause __PIC__ to be defined on ELF platforms."
+#  endif
+#endif
diff --git a/Tests/PositionIndependentTargets/targets/CMakeLists.txt b/Tests/PositionIndependentTargets/targets/CMakeLists.txt
new file mode 100644
index 0000000..bdc30d5
--- /dev/null
+++ b/Tests/PositionIndependentTargets/targets/CMakeLists.txt
@@ -0,0 +1,18 @@
+
+add_executable(test_target_executable_properties "${CMAKE_CURRENT_SOURCE_DIR}/../pic_main.cpp")
+set_target_properties(test_target_executable_properties
+  PROPERTIES
+    POSITION_INDEPENDENT_CODE True
+)
+
+add_library(test_target_shared_library_properties SHARED "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp")
+set_target_properties(test_target_shared_library_properties
+  PROPERTIES
+    POSITION_INDEPENDENT_CODE True
+)
+
+add_library(test_target_static_library_properties STATIC "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp")
+set_target_properties(test_target_static_library_properties
+  PROPERTIES
+    POSITION_INDEPENDENT_CODE True
+)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c22b8ee5a8d99c13ccc227fc50a351a3f649b65e
commit c22b8ee5a8d99c13ccc227fc50a351a3f649b65e
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat May 5 21:59:50 2012 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Jun 4 23:47:01 2012 +0200

    Create the POSITION_INDEPENDENT_CODE property to initialize flags.
    
    By default it is true for shared libraries, but can also be set to
    true for executables to set the -fPIE (or equivalent flags).
    
    A policy determines whether to adhere to this new property or use
    the SHARED_LIBRARY flags as determined by the platform.

diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index b06cdb4..4014475 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -586,6 +586,13 @@ cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
           }
         } // end if in try compile
       } // end need test language
+    // Store the shared library flags so that we can satisfy CMP0018
+    std::string sharedLibFlagsVar = "CMAKE_SHARED_LIBRARY_";
+    sharedLibFlagsVar += lang;
+    sharedLibFlagsVar += "_FLAGS";
+    std::string sharedLibFlags =
+      mf->GetRequiredDefinition(sharedLibFlagsVar.c_str());
+    this->LanguageToOriginalSharedLibFlags[lang] = sharedLibFlags;
     } // end for each language
 
   // Now load files that can override any settings on the platform or for
@@ -2107,6 +2114,17 @@ cmGlobalGenerator::GenerateRuleFile(std::string const& output) const
 }
 
 //----------------------------------------------------------------------------
+std::string cmGlobalGenerator::GetSharedLibFlagsForLanguage(
+                                                        std::string const& l)
+{
+  if(this->LanguageToOriginalSharedLibFlags.count(l) > 0)
+    {
+    return this->LanguageToOriginalSharedLibFlags[l];
+    }
+  return "";
+}
+
+//----------------------------------------------------------------------------
 void cmGlobalGenerator::AppendDirectoryForConfig(const char*, const char*,
                                                  const char*, std::string&)
 {
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 5254b89..0ac38a0 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -277,6 +277,8 @@ public:
       i.e. "Can I build Debug and Release in the same tree?" */
   virtual bool IsMultiConfig() { return false; }
 
+  std::string GetSharedLibFlagsForLanguage(std::string const& lang);
+
   /** Generate an <output>.rule file path for a given command output.  */
   virtual std::string GenerateRuleFile(std::string const& output) const;
 
@@ -357,6 +359,7 @@ private:
   std::map<cmStdString, cmStdString> LanguageToOutputExtension;
   std::map<cmStdString, cmStdString> ExtensionToLanguage;
   std::map<cmStdString, int> LanguageToLinkerPreference;
+  std::map<cmStdString, cmStdString> LanguageToOriginalSharedLibFlags;
 
   // Record hashes for rules and outputs.
   struct RuleHash { char Data[32]; };
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 8265d72..59db51c 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1963,6 +1963,84 @@ void cmLocalGenerator::AddSharedFlags(std::string& flags,
 }
 
 //----------------------------------------------------------------------------
+bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
+                                            const std::string &lang) const
+{
+  std::string originalFlags =
+    this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
+  if (shared)
+    {
+    std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
+    flagsVar += lang;
+    flagsVar += "_FLAGS";
+    std::string flags =
+        this->Makefile->GetRequiredDefinition(flagsVar.c_str());
+
+    if (flags != originalFlags)
+      {
+      switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0018))
+        {
+        case cmPolicies::WARN:
+        {
+          cmOStringStream e;
+          e << "Variable " << flagsVar << " has been modified. CMake "
+            "will ignore the POSITION_INDEPENDENT_CODE target property for "
+            "shared libraries and will use the " << flagsVar << " variable "
+            "instead.  This may cause errors if the original content of "
+            << flagsVar << " was removed.\n"
+            << this->Makefile->GetPolicies()->GetPolicyWarning(
+                                                      cmPolicies::CMP0018);
+
+          this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+          // fall through to OLD behaviour
+        }
+        case cmPolicies::OLD:
+          return true;
+        case cmPolicies::REQUIRED_IF_USED:
+        case cmPolicies::REQUIRED_ALWAYS:
+        case cmPolicies::NEW:
+        default:
+          return false;
+        }
+      }
+    }
+  return false;
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
+                                                   std::string const& lang,
+                                                   int targetType)
+{
+  const char* picFlags = 0;
+
+  if(targetType == cmTarget::EXECUTABLE)
+    {
+    std::string flagsVar = "CMAKE_";
+    flagsVar += lang;
+    flagsVar += "_COMPILE_OPTIONS_PIE";
+    picFlags = this->Makefile->GetSafeDefinition(flagsVar.c_str());
+    }
+  if (!picFlags)
+    {
+    std::string flagsVar = "CMAKE_";
+    flagsVar += lang;
+    flagsVar += "_COMPILE_OPTIONS_PIC";
+    picFlags = this->Makefile->GetSafeDefinition(flagsVar.c_str());
+    }
+  if (picFlags)
+    {
+    std::vector<std::string> options;
+    cmSystemTools::ExpandListArgument(picFlags, options);
+    for(std::vector<std::string>::const_iterator oi = options.begin();
+        oi != options.end(); ++oi)
+      {
+      this->AppendFlags(flags, this->EscapeForShell(oi->c_str()).c_str());
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
 void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
                                               const char* var,
                                               const char* config)
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index cb84a30..027d340 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -425,6 +425,10 @@ protected:
 private:
   std::string ConvertToOutputForExistingCommon(const char* remote,
                                                std::string const& result);
+
+  bool GetShouldUseOldFlags(bool shared, const std::string &lang) const;
+  void AddPositionIndependentFlags(std::string& flags, std::string const& l,
+                                   int targetType);
 };
 
 #endif
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index 37070b6..79af4d7 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -463,6 +463,34 @@ cmPolicies::cmPolicies()
     "The OLD behaviour is to always prefer files from CMAKE_MODULE_PATH over "
     "files from the CMake modules directory.",
     2,8,4,0, cmPolicies::WARN);
+
+    this->DefinePolicy(
+    CMP0018, "CMP0018",
+    "Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.",
+    "CMake 2.8.8 and lower compiled sources in SHARED and MODULE libraries "
+    "using the value of the undocumented CMAKE_SHARED_LIBRARY_<Lang>_FLAGS "
+    "platform variable.  The variable contained platform-specific flags "
+    "needed to compile objects for shared libraries.  Typically it included "
+    "a flag such as -fPIC for position independent code but also included "
+    "other flags needed on certain platforms.  CMake 2.8.9 and higher "
+    "prefer instead to use the POSITION_INDEPENDENT_CODE target property to "
+    "determine what targets should be position independent, and new "
+    "undocumented platform variables to select flags while ignoring "
+    "CMAKE_SHARED_LIBRARY_<Lang>_FLAGS completely."
+    "\n"
+    "The default for either approach produces identical compilation flags, "
+    "but if a project modifies CMAKE_SHARED_LIBRARY_<Lang>_FLAGS from its "
+    "original value this policy determines which approach to use."
+    "\n"
+    "The OLD behavior for this policy is to ignore the "
+    "POSITION_INDEPENDENT_CODE property for all targets and use the modified "
+    "value of CMAKE_SHARED_LIBRARY_<Lang>_FLAGS for SHARED and MODULE "
+    "libraries."
+    "\n"
+    "The NEW behavior for this policy is to ignore "
+    "CMAKE_SHARED_LIBRARY_<Lang>_FLAGS whether it is modified or not and "
+    "honor the POSITION_INDEPENDENT_CODE target property.",
+    2,8,9,0, cmPolicies::WARN);
 }
 
 cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 3106248..6932565 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -65,6 +65,9 @@ public:
     /// target_link_libraries() fails if only argument is not a target
     CMP0016,
     CMP0017, ///< Prefer files in CMAKE_ROOT when including from CMAKE_ROOT
+    CMP0018, ///< Ignore language flags for shared libs, and adhere to
+    /// POSITION_INDEPENDENT_CODE property and *_COMPILE_OPTIONS_PI{E,C}
+    /// instead.
 
     /** \brief Always the last entry.
      *
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index c5ef9ff..b40f4ee 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -756,6 +756,14 @@ void cmTarget::DefineProperties(cmake *cm)
      "(such as \"lib\") on a library name.");
 
   cm->DefineProperty
+    ("POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
+     "Whether to create a position-independent target",
+     "The POSITION_INDEPENDENT_CODE property determines whether position "
+     "independent executables or shared libraries will be created.  "
+     "This property is true by default for SHARED and MODULE library "
+     "targets and false otherwise.");
+
+  cm->DefineProperty
     ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
      "Deprecated install support.",
      "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
@@ -1305,6 +1313,12 @@ void cmTarget::SetMakefile(cmMakefile* mf)
   this->SetProperty("INCLUDE_DIRECTORIES",
                     this->Makefile->GetProperty("INCLUDE_DIRECTORIES"));
 
+  if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
+      || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
+    {
+    this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
+    }
+
   // Record current policies for later use.
   this->PolicyStatusCMP0003 =
     this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=07be743afb7281317ab8b330027d1b4e958426d6
commit 07be743afb7281317ab8b330027d1b4e958426d6
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed May 30 10:52:35 2012 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Jun 4 23:47:01 2012 +0200

    Add a COMPILE_OPTIONS_DLL variable to replace using _FLAGS for that.

diff --git a/Modules/Compiler/SCO.cmake b/Modules/Compiler/SCO.cmake
index ef2f64b..f673c8f 100644
--- a/Modules/Compiler/SCO.cmake
+++ b/Modules/Compiler/SCO.cmake
@@ -22,6 +22,7 @@ macro(__compiler_sco lang)
   # Feature flags.
   set(CMAKE_${lang}_COMPILE_OPTIONS_PIC -Kpic)
   set(CMAKE_${lang}_COMPILE_OPTIONS_PIE -Kpie)
+  set(CMAKE_${lang}_COMPILE_OPTIONS_DLL -belf)
   set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-Kpic -belf")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-belf -Wl,-Bexport")
 endmacro()
diff --git a/Modules/Platform/Windows-Embarcadero.cmake b/Modules/Platform/Windows-Embarcadero.cmake
index 87b3767..62e8eb7 100644
--- a/Modules/Platform/Windows-Embarcadero.cmake
+++ b/Modules/Platform/Windows-Embarcadero.cmake
@@ -76,7 +76,8 @@ SET (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_SHARED_LINKER_FLAGS_R
 
 
 macro(__embarcadero_language lang)
-  set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "${_tD}")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_DLL "${_tD}") # Note: This variable is a ';' separated list
+  set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "${_tD}") # ... while this is a space separated string.
 
   # compile a source file into an object file
   # place <DEFINES> outside the response file because Borland refuses
diff --git a/Modules/Platform/Windows-wcl386.cmake b/Modules/Platform/Windows-wcl386.cmake
index e1140df..14b3b81 100644
--- a/Modules/Platform/Windows-wcl386.cmake
+++ b/Modules/Platform/Windows-wcl386.cmake
@@ -20,7 +20,8 @@ SET (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT "debug all" )
 SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "debug all" )
 SET (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT "debug all" )
 
-set (CMAKE_SHARED_LIBRARY_C_FLAGS "-bd" )
+set(CMAKE_C_COMPILE_OPTIONS_DLL "-bd") # Note: This variable is a ';' separated list
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-bd") # ... while this is a space separated string.
 
 SET(CMAKE_RC_COMPILER "rc" )
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5c6c7decc721c1d7220a0dd81d9e680c83a18aea
commit 5c6c7decc721c1d7220a0dd81d9e680c83a18aea
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat May 5 21:11:35 2012 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Jun 4 23:47:01 2012 +0200

    Add compiler specific position independent flags.
    
    In almost all cases, this means duplication of
    the CMAKE_SHARED_LIBRARY_${lang}_FLAGS for the _PIC
    case and using the assumed pie equivalent for the _PIE case.
    
    There is a possibility that the _PIE variables are not correct. However,
    as there is no backwards compatibility to be concerned about (as the
    POSITION_INDEPENDENT_CODE property is not used anywhere yet), the
    current state suffices. The dashboard will find incorrect flags on any
    tested platforms.

diff --git a/Modules/CMakeCXXInformation.cmake b/Modules/CMakeCXXInformation.cmake
index 608b833..5e09eab 100644
--- a/Modules/CMakeCXXInformation.cmake
+++ b/Modules/CMakeCXXInformation.cmake
@@ -100,6 +100,14 @@ IF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
   SET(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
 ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
 
+IF(NOT CMAKE_CXX_COMPILE_OPTIONS_PIC)
+  SET(CMAKE_CXX_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
+ENDIF(NOT CMAKE_CXX_COMPILE_OPTIONS_PIC)
+
+IF(NOT CMAKE_CXX_COMPILE_OPTIONS_PIE)
+  SET(CMAKE_CXX_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
+ENDIF(NOT CMAKE_CXX_COMPILE_OPTIONS_PIE)
+
 IF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
   SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
 ENDIF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake
index 2cbd7f8..9c82409 100644
--- a/Modules/CMakeFortranInformation.cmake
+++ b/Modules/CMakeFortranInformation.cmake
@@ -74,6 +74,14 @@ ENDIF()
 # catch any modules
 SET(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
 
+IF(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
+  SET(CMAKE_Fortran_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
+ENDIF(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
+
+IF(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIE)
+  SET(CMAKE_Fortran_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
+ENDIF(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIE)
+
 # Create a set of shared library variable specific to Fortran
 # For 90% of the systems, these are the same flags as the C versions
 # so if these are not set just copy the flags from the c version
diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake
index c74c179..bbc07e7 100644
--- a/Modules/Compiler/GNU.cmake
+++ b/Modules/Compiler/GNU.cmake
@@ -21,6 +21,8 @@ set(__COMPILER_GNU 1)
 macro(__compiler_gnu lang)
   # Feature flags.
   set(CMAKE_${lang}_VERBOSE_FLAG "-v")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
   set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
 
diff --git a/Modules/Compiler/SCO.cmake b/Modules/Compiler/SCO.cmake
index d3deeb1..ef2f64b 100644
--- a/Modules/Compiler/SCO.cmake
+++ b/Modules/Compiler/SCO.cmake
@@ -20,6 +20,8 @@ set(__COMPILER_SCO 1)
 
 macro(__compiler_sco lang)
   # Feature flags.
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIC -Kpic)
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIE -Kpie)
   set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-Kpic -belf")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-belf -Wl,-Bexport")
 endmacro()
diff --git a/Modules/Compiler/SunPro-C.cmake b/Modules/Compiler/SunPro-C.cmake
index 656eea6..a1a3ae1 100644
--- a/Modules/Compiler/SunPro-C.cmake
+++ b/Modules/Compiler/SunPro-C.cmake
@@ -1,5 +1,7 @@
 SET(CMAKE_C_VERBOSE_FLAG "-#")
 
+SET(CMAKE_C_COMPILE_OPTIONS_PIC -KPIC)
+SET(CMAKE_C_COMPILE_OPTIONS_PIE -KPIE)
 SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-KPIC")
 SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-G")
 SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-R")
diff --git a/Modules/Compiler/SunPro-CXX.cmake b/Modules/Compiler/SunPro-CXX.cmake
index 3e07e8e..702e424 100644
--- a/Modules/Compiler/SunPro-CXX.cmake
+++ b/Modules/Compiler/SunPro-CXX.cmake
@@ -1,5 +1,7 @@
 SET(CMAKE_CXX_VERBOSE_FLAG "-v")
 
+SET(CMAKE_CXX_COMPILE_OPTIONS_PIC -KPIC)
+SET(CMAKE_CXX_COMPILE_OPTIONS_PIE -KPIE)
 SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-KPIC")
 SET(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-G")
 SET(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-R")
diff --git a/Modules/Platform/BeOS.cmake b/Modules/Platform/BeOS.cmake
index 41aa8f7..3ffb67c 100644
--- a/Modules/Platform/BeOS.cmake
+++ b/Modules/Platform/BeOS.cmake
@@ -1,6 +1,8 @@
 SET(BEOS 1)
 
 SET(CMAKE_DL_LIBS root be)
+SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
+SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
 SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
 SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-nostart")
 SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
diff --git a/Modules/Platform/BlueGeneP-base.cmake b/Modules/Platform/BlueGeneP-base.cmake
index 926dbc0..c0241e1 100644
--- a/Modules/Platform/BlueGeneP-base.cmake
+++ b/Modules/Platform/BlueGeneP-base.cmake
@@ -85,11 +85,15 @@ set(CMAKE_DL_LIBS "dl")
 macro(__BlueGeneP_set_dynamic_flags compiler_id lang)
   if (${compiler_id} STREQUAL XL)
     # Flags for XL compilers if we explicitly detected XL
+    set(CMAKE_${lang}_COMPILE_OPTIONS_PIC            "-qpic")
+    set(CMAKE_${lang}_COMPILE_OPTIONS_PIE            "-qpie")
     set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS           "-qpic")
     set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS    "-qmkshrobj -qnostaticlink")
     set(BGP_${lang}_DYNAMIC_EXE_FLAGS                "-qnostaticlink -qnostaticlink=libgcc")
   else()
     # Assume flags for GNU compilers (if the ID is GNU *or* anything else).
+    set(CMAKE_${lang}_COMPILE_OPTIONS_PIC            "-fPIC")
+    set(CMAKE_${lang}_COMPILE_OPTIONS_PIE            "-fPIE")
     set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS           "-fPIC")
     set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS    "-shared")
     set(BGP_${lang}_DYNAMIC_EXE_FLAGS                "-dynamic")
diff --git a/Modules/Platform/FreeBSD.cmake b/Modules/Platform/FreeBSD.cmake
index 033db06..82fe961 100644
--- a/Modules/Platform/FreeBSD.cmake
+++ b/Modules/Platform/FreeBSD.cmake
@@ -1,6 +1,8 @@
 IF(EXISTS /usr/include/dlfcn.h)
   SET(CMAKE_DL_LIBS "")
-  SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")            # -pic 
+  SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
+  SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+  SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")            # -pic
   SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")       # -shared
   SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")         # +s, flag for exe link to use shared lib
   SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")       # -rpath
diff --git a/Modules/Platform/HP-UX-HP.cmake b/Modules/Platform/HP-UX-HP.cmake
index bce0a8b..871ea13 100644
--- a/Modules/Platform/HP-UX-HP.cmake
+++ b/Modules/Platform/HP-UX-HP.cmake
@@ -19,6 +19,7 @@ endif()
 set(__HPUX_COMPILER_HP 1)
 
 macro(__hpux_compiler_hp lang)
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "+Z")
   set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "+Z")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-Wl,-E,+nodefaultrpath -b -L/usr/lib")
   set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,+s,-E,+nodefaultrpath")
diff --git a/Modules/Platform/Haiku.cmake b/Modules/Platform/Haiku.cmake
index 8277a24..9dda3c5 100644
--- a/Modules/Platform/Haiku.cmake
+++ b/Modules/Platform/Haiku.cmake
@@ -1,6 +1,8 @@
 SET(BEOS 1)
 
 SET(CMAKE_DL_LIBS root be)
+SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
+SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
 SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
 SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-nostart")
 SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
diff --git a/Modules/Platform/Linux-Intel.cmake b/Modules/Platform/Linux-Intel.cmake
index dea8b90..47bf246 100644
--- a/Modules/Platform/Linux-Intel.cmake
+++ b/Modules/Platform/Linux-Intel.cmake
@@ -31,6 +31,8 @@ if(NOT XIAR)
 endif(NOT XIAR)
 
 macro(__linux_compiler_intel lang)
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
   set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
 
diff --git a/Modules/Platform/Linux-PGI.cmake b/Modules/Platform/Linux-PGI.cmake
index ef06acd..3cbb35c 100644
--- a/Modules/Platform/Linux-PGI.cmake
+++ b/Modules/Platform/Linux-PGI.cmake
@@ -20,6 +20,8 @@ set(__LINUX_COMPILER_PGI 1)
 
 macro(__linux_compiler_pgi lang)
   # Shared library compile and link flags.
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
   set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
 endmacro()
diff --git a/Modules/Platform/Linux-PathScale.cmake b/Modules/Platform/Linux-PathScale.cmake
index c131af2..d230ab2 100644
--- a/Modules/Platform/Linux-PathScale.cmake
+++ b/Modules/Platform/Linux-PathScale.cmake
@@ -20,6 +20,8 @@ set(__LINUX_COMPILER_PATHSCALE 1)
 
 macro(__linux_compiler_pathscale lang)
   # Shared library compile and link flags.
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
   set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
 endmacro()
diff --git a/Modules/Platform/MP-RAS.cmake b/Modules/Platform/MP-RAS.cmake
index 1e3e239..ff22a4f 100644
--- a/Modules/Platform/MP-RAS.cmake
+++ b/Modules/Platform/MP-RAS.cmake
@@ -1,6 +1,10 @@
 IF(CMAKE_SYSTEM MATCHES "MP-RAS-02*.")
+  SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+  SET(CMAKE_C_COMPILE_OPTIONS_PIE -K PIE)
   SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
 ELSE(CMAKE_SYSTEM MATCHES "MP-RAS-02*.")
+  SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+  SET(CMAKE_C_COMPILE_OPTIONS_PIE -K PIE)
   SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
   SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-Bexport")
 ENDIF(CMAKE_SYSTEM MATCHES "MP-RAS-02*.")
diff --git a/Modules/Platform/NetBSD.cmake b/Modules/Platform/NetBSD.cmake
index 0fb8636..e1b66b8 100644
--- a/Modules/Platform/NetBSD.cmake
+++ b/Modules/Platform/NetBSD.cmake
@@ -1,6 +1,8 @@
 IF(EXISTS /usr/include/dlfcn.h)
   SET(CMAKE_DL_LIBS "")
-  SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")            # -pic 
+  SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
+  SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+  SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")            # -pic
   SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")       # -shared
   SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")         # +s, flag for exe link to use shared lib
   SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")       # -rpath
diff --git a/Modules/Platform/OSF1.cmake b/Modules/Platform/OSF1.cmake
index 076410a..49a30e9 100644
--- a/Modules/Platform/OSF1.cmake
+++ b/Modules/Platform/OSF1.cmake
@@ -4,7 +4,9 @@ IF(CMAKE_SYSTEM MATCHES "OSF1-1.[012]")
 ENDIF(CMAKE_SYSTEM MATCHES "OSF1-1.[012]")
 IF(CMAKE_SYSTEM MATCHES "OSF1-1.*")  
   # OSF/1 1.3 from OSF using ELF, and derivatives, including AD2
-  SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fpic")     # -pic 
+  SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fpic")
+  SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fpie")
+  SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fpic")     # -pic
   SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-fpic")   # -pic
 ENDIF(CMAKE_SYSTEM MATCHES "OSF1-1.*")
 
diff --git a/Modules/Platform/SINIX.cmake b/Modules/Platform/SINIX.cmake
index 4592fdd..e0809f8 100644
--- a/Modules/Platform/SINIX.cmake
+++ b/Modules/Platform/SINIX.cmake
@@ -1,2 +1,4 @@
+SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+SET(CMAKE_C_COMPILE_OPTIONS_PIE "")
 SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
 INCLUDE(Platform/UnixPaths)
diff --git a/Modules/Platform/SunOS.cmake b/Modules/Platform/SunOS.cmake
index 2291c34..de287aa 100644
--- a/Modules/Platform/SunOS.cmake
+++ b/Modules/Platform/SunOS.cmake
@@ -1,6 +1,8 @@
 IF(CMAKE_SYSTEM MATCHES "SunOS-4.*")
-   SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-PIC") 
-   SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared -Wl,-r") 
+   SET(CMAKE_C_COMPILE_OPTIONS_PIC "-PIC")
+   SET(CMAKE_C_COMPILE_OPTIONS_PIE "-PIE")
+   SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-PIC")
+   SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared -Wl,-r")
    SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-R")
    SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")  
 ENDIF(CMAKE_SYSTEM MATCHES "SunOS-4.*")
diff --git a/Modules/Platform/UNIX_SV.cmake b/Modules/Platform/UNIX_SV.cmake
index 3b50e0a..869b3a6 100644
--- a/Modules/Platform/UNIX_SV.cmake
+++ b/Modules/Platform/UNIX_SV.cmake
@@ -1,3 +1,5 @@
+SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+SET(CMAKE_C_COMPILE_OPTIONS_PIE "")
 SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-Bexport")
 INCLUDE(Platform/UnixPaths)
diff --git a/Modules/Platform/UnixWare.cmake b/Modules/Platform/UnixWare.cmake
index c324bc8..3112ee1 100644
--- a/Modules/Platform/UnixWare.cmake
+++ b/Modules/Platform/UnixWare.cmake
@@ -1,3 +1,5 @@
+SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+SET(CMAKE_C_COMPILE_OPTIONS_PIE "")
 SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
 SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-Wl,-Bexport")
 INCLUDE(Platform/UnixPaths)
diff --git a/Modules/Platform/syllable.cmake b/Modules/Platform/syllable.cmake
index 3ce42f6..2d11d08 100644
--- a/Modules/Platform/syllable.cmake
+++ b/Modules/Platform/syllable.cmake
@@ -10,7 +10,9 @@
 
 
 SET(CMAKE_DL_LIBS "dl")
-SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")            # -pic 
+SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
+SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")            # -pic
 SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")       # -shared
 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")         # +s, flag for exe link to use shared lib
 SET(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")

-----------------------------------------------------------------------

Summary of changes:
 Modules/CMakeCXXInformation.cmake                  |    8 ++
 Modules/CMakeFortranInformation.cmake              |    8 ++
 Modules/Compiler/GNU.cmake                         |    2 +
 Modules/Compiler/SCO.cmake                         |    3 +
 Modules/Compiler/SunPro-C.cmake                    |    2 +
 Modules/Compiler/SunPro-CXX.cmake                  |    2 +
 Modules/Platform/BeOS.cmake                        |    2 +
 Modules/Platform/BlueGeneP-base.cmake              |    4 +
 Modules/Platform/FreeBSD.cmake                     |    4 +-
 Modules/Platform/HP-UX-HP.cmake                    |    1 +
 Modules/Platform/Haiku.cmake                       |    2 +
 Modules/Platform/Linux-Intel.cmake                 |    2 +
 Modules/Platform/Linux-PGI.cmake                   |    2 +
 Modules/Platform/Linux-PathScale.cmake             |    2 +
 Modules/Platform/MP-RAS.cmake                      |    4 +
 Modules/Platform/NetBSD.cmake                      |    4 +-
 Modules/Platform/OSF1.cmake                        |    4 +-
 Modules/Platform/SINIX.cmake                       |    2 +
 Modules/Platform/SunOS.cmake                       |    6 +-
 Modules/Platform/UNIX_SV.cmake                     |    2 +
 Modules/Platform/UnixWare.cmake                    |    2 +
 Modules/Platform/Windows-Embarcadero.cmake         |    3 +-
 Modules/Platform/Windows-wcl386.cmake              |    3 +-
 Modules/Platform/syllable.cmake                    |    4 +-
 Source/cmCoreTryCompile.cxx                        |    4 +
 Source/cmDocumentVariables.cxx                     |    8 ++
 Source/cmGlobalGenerator.cxx                       |   18 +++
 Source/cmGlobalGenerator.h                         |    3 +
 Source/cmGlobalXCodeGenerator.cxx                  |    4 +-
 Source/cmLocalGenerator.cxx                        |  111 ++++++++++++++++++-
 Source/cmLocalGenerator.h                          |    8 ++-
 Source/cmMakefileTargetGenerator.cxx               |    6 +-
 Source/cmNinjaTargetGenerator.cxx                  |    7 +-
 Source/cmPolicies.cxx                              |   28 +++++
 Source/cmPolicies.h                                |    3 +
 Source/cmTarget.cxx                                |   15 +++
 Tests/CMakeLists.txt                               |    2 +
 Tests/PositionIndependentTargets/CMakeLists.txt    |   13 +++
 .../global/CMakeLists.txt                          |   30 ++++++
 Tests/PositionIndependentTargets/main.cpp          |    2 +
 Tests/PositionIndependentTargets/pic_lib.cpp       |    2 +
 Tests/PositionIndependentTargets/pic_main.cpp      |    4 +
 Tests/PositionIndependentTargets/pic_test.h        |    6 +
 .../targets/CMakeLists.txt                         |   18 +++
 44 files changed, 343 insertions(+), 27 deletions(-)
 create mode 100644 Tests/PositionIndependentTargets/CMakeLists.txt
 create mode 100644 Tests/PositionIndependentTargets/global/CMakeLists.txt
 create mode 100644 Tests/PositionIndependentTargets/main.cpp
 create mode 100644 Tests/PositionIndependentTargets/pic_lib.cpp
 create mode 100644 Tests/PositionIndependentTargets/pic_main.cpp
 create mode 100644 Tests/PositionIndependentTargets/pic_test.h
 create mode 100644 Tests/PositionIndependentTargets/targets/CMakeLists.txt


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list