[Cmake-commits] CMake branch, next, updated. v2.8.12.2-7526-g930141d

Nils Gladitz nilsgladitz at gmail.com
Sat Feb 8 03:38:06 EST 2014


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  930141dec3c7814855b53dd5d79ce682bab73211 (commit)
       via  31b49654bc3d90dc74836a560ab9f3e2d95a1acf (commit)
      from  3283439d6da10b1e37df7ab41cf2314df02d7ee9 (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=930141dec3c7814855b53dd5d79ce682bab73211
commit 930141dec3c7814855b53dd5d79ce682bab73211
Merge: 3283439 31b4965
Author:     Nils Gladitz <nilsgladitz at gmail.com>
AuthorDate: Sat Feb 8 03:38:04 2014 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Sat Feb 8 03:38:04 2014 -0500

    Merge topic 'gcc-ipo' into next
    
    31b49654 IPO: implemented INTERPROCEDURAL_OPTIMIZATION for gcc (-flto)


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=31b49654bc3d90dc74836a560ab9f3e2d95a1acf
commit 31b49654bc3d90dc74836a560ab9f3e2d95a1acf
Author:     Nils Gladitz <nilsgladitz at gmail.com>
AuthorDate: Fri Jan 31 23:56:40 2014 +0100
Commit:     Nils Gladitz <nilsgladitz at gmail.com>
CommitDate: Sat Feb 8 09:37:46 2014 +0100

    IPO: implemented INTERPROCEDURAL_OPTIMIZATION for gcc (-flto)
    
    Using the IPO specific rule variables in the Ninja generator should
    fix intel IPO as well.

diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake
index f01255c..e40fa9f 100644
--- a/Modules/Compiler/GNU.cmake
+++ b/Modules/Compiler/GNU.cmake
@@ -55,4 +55,92 @@ macro(__compiler_gnu lang)
   if(NOT APPLE)
     set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
   endif()
+
+  # LTO/IPO
+  if(NOT CMAKE_GCC_AR OR NOT CMAKE_GCC_RANLIB)
+    if(IS_ABSOLUTE "${CMAKE_${lang}_COMPILER}")
+      string(REGEX MATCH "^([0-9]+.[0-9]+)" _version
+        "${CMAKE_${lang}_COMPILER_VERSION}")
+      get_filename_component(_dir "${CMAKE_${lang}_COMPILER}" DIRECTORY)
+
+      find_program(CMAKE_GCC_AR NAMES
+        "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar"
+        "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${_version}"
+      )
+
+      find_program(CMAKE_GCC_RANLIB NAMES
+        "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib"
+        "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${_version}"
+      )
+    endif()
+  endif()
+
+  if(CMAKE_GCC_AR AND CMAKE_GCC_RANLIB)
+    set(__lto_flags -flto)
+
+    if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7)
+      list(APPEND __lto_flags -fno-fat-lto-objects)
+    endif()
+
+    if(NOT DEFINED CMAKE_${lang}_PASSED_LTO_TEST)
+      set(__output_dir "${CMAKE_PLATFORM_INFO_DIR}/LtoTest${lang}")
+      file(MAKE_DIRECTORY "${__output_dir}")
+      set(__output_base "${__output_dir}/lto-test-${lang}")
+
+      execute_process(
+        COMMAND ${CMAKE_COMMAND} -E echo "void foo() {}"
+        COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -c -xc -
+          -o ${__output_base}.o
+        RESULT_VARIABLE __result
+        ERROR_QUIET
+        OUTPUT_QUIET
+      )
+
+      if("${__result}" STREQUAL "0")
+        execute_process(
+          COMMAND ${CMAKE_GCC_AR} cr ${__output_base}.a ${__output_base}.o
+          COMMAND ${CMAKE_GCC_RANLIB} ${__output_base}.a
+          RESULT_VARIABLE __result
+          ERROR_QUIET
+          OUTPUT_QUIET
+        )
+      endif()
+
+      if("${__result}" STREQUAL "0")
+        execute_process(
+          COMMAND ${CMAKE_COMMAND} -E echo "void foo(); int main() {foo();}"
+          COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -xc -
+            -x none ${__output_base}.a -o ${__output_base}
+          RESULT_VARIABLE __result
+          ERROR_QUIET
+          OUTPUT_QUIET
+        )
+      endif()
+
+      if("${__result}" STREQUAL "0")
+        set(__lto_found TRUE)
+      endif()
+
+      set(CMAKE_${lang}_PASSED_LTO_TEST
+        ${__lto_found} CACHE INTERNAL
+        "If the compiler passed a simple LTO test compile")
+    endif()
+
+    if(CMAKE_${lang}_PASSED_LTO_TEST)
+
+      set(CMAKE_${lang}_COMPILE_OPTIONS_IPO ${__lto_flags})
+
+      set(CMAKE_${lang}_ARCHIVE_CREATE_IPO
+        "${CMAKE_GCC_AR} cr <TARGET> <LINK_FLAGS> <OBJECTS>"
+      )
+
+      set(CMAKE_${lang}_ARCHIVE_APPEND_IPO
+        "${CMAKE_GCC_AR} r <TARGET> <LINK_FLAGS> <OBJECTS>"
+      )
+
+      set(CMAKE_${lang}_ARCHIVE_FINISH_IPO
+        "${CMAKE_GCC_RANLIB} <TARGET>"
+      )
+    endif()
+  endif()
 endmacro()
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index d6a0cd4..38d3c3c 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -140,11 +140,7 @@ void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
     }
   linkRuleVar += "_CREATE_STATIC_LIBRARY";
 
-  if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION") &&
-     this->Makefile->GetDefinition((linkRuleVar+"_IPO").c_str()))
-    {
-    linkRuleVar += "_IPO";
-    }
+  linkRuleVar = this->GetFeatureSpecificLinkRuleVariable(linkRuleVar);
 
   std::string extraFlags;
   this->LocalGenerator->GetStaticLibraryFlags(extraFlags,
@@ -494,6 +490,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     std::string arCreateVar = "CMAKE_";
     arCreateVar += linkLanguage;
     arCreateVar += "_ARCHIVE_CREATE";
+    arCreateVar = this->GetFeatureSpecificLinkRuleVariable(arCreateVar);
     if(const char* rule = this->Makefile->GetDefinition(arCreateVar.c_str()))
       {
       cmSystemTools::ExpandListArgument(rule, archiveCreateCommands);
@@ -501,6 +498,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     std::string arAppendVar = "CMAKE_";
     arAppendVar += linkLanguage;
     arAppendVar += "_ARCHIVE_APPEND";
+    arAppendVar = this->GetFeatureSpecificLinkRuleVariable(arAppendVar);
     if(const char* rule = this->Makefile->GetDefinition(arAppendVar.c_str()))
       {
       cmSystemTools::ExpandListArgument(rule, archiveAppendCommands);
@@ -508,6 +506,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     std::string arFinishVar = "CMAKE_";
     arFinishVar += linkLanguage;
     arFinishVar += "_ARCHIVE_FINISH";
+    arFinishVar = this->GetFeatureSpecificLinkRuleVariable(arFinishVar);
     if(const char* rule = this->Makefile->GetDefinition(arFinishVar.c_str()))
       {
       cmSystemTools::ExpandListArgument(rule, archiveFinishCommands);
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index 7f90078..14dd6ab 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -1664,6 +1664,20 @@ void cmMakefileTargetGenerator
 }
 
 //----------------------------------------------------------------------------
+std::string cmMakefileTargetGenerator::GetFeatureSpecificLinkRuleVariable(
+  std::string const& var) const
+{
+  std::string ipoVar = var + "_IPO";
+  if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION") &&
+     this->Makefile->GetDefinition(ipoVar.c_str()))
+    {
+    return ipoVar;
+    }
+
+  return var;
+}
+
+//----------------------------------------------------------------------------
 std::string cmMakefileTargetGenerator::GetLinkRule(const char* linkRuleVar)
 {
   std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
@@ -2041,13 +2055,13 @@ void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
 }
 
 //----------------------------------------------------------------------------
-const char* cmMakefileTargetGenerator::GetFeature(const char* feature)
+const char* cmMakefileTargetGenerator::GetFeature(const char* feature) const
 {
   return this->Target->GetFeature(feature, this->ConfigName);
 }
 
 //----------------------------------------------------------------------------
-bool cmMakefileTargetGenerator::GetFeatureAsBool(const char* feature)
+bool cmMakefileTargetGenerator::GetFeatureAsBool(const char* feature) const
 {
   return cmSystemTools::IsOn(this->GetFeature(feature));
 }
diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h
index 4f8fafa..16524c3 100644
--- a/Source/cmMakefileTargetGenerator.h
+++ b/Source/cmMakefileTargetGenerator.h
@@ -137,6 +137,9 @@ protected:
   // Append link rule dependencies (objects, etc.).
   void AppendLinkDepends(std::vector<std::string>& depends);
 
+  // Get feature specific link rule variable (e.g. <var>_IPO)
+  std::string GetFeatureSpecificLinkRuleVariable(std::string const& var) const;
+
   // Lookup the link rule for this target.
   std::string GetLinkRule(const char* linkRuleVar);
 
@@ -258,8 +261,8 @@ protected:
   void AddFeatureFlags(std::string& flags, const char* lang);
 
   // Feature query methods.
-  const char* GetFeature(const char* feature);
-  bool GetFeatureAsBool(const char* feature);
+  const char* GetFeature(const char* feature) const;
+  bool GetFeatureAsBool(const char* feature) const;
 
   //==================================================================
   // Convenience routines that do nothing more than forward to
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 73ba815..b979be1 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -140,10 +140,17 @@ std::string
 cmNinjaNormalTargetGenerator
 ::LanguageLinkerRule() const
 {
-  return std::string(this->TargetLinkLanguage)
+  std::string var = std::string(this->TargetLinkLanguage)
     + "_"
     + cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
     + "_LINKER";
+
+  if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION"))
+    {
+    var += "_IPO";
+    }
+
+  return var;
 }
 
 void
@@ -152,6 +159,7 @@ cmNinjaNormalTargetGenerator
 {
   cmTarget::TargetType targetType = this->GetTarget()->GetType();
   std::string ruleName = this->LanguageLinkerRule();
+
   if (useResponseFile)
     ruleName += "_RSP_FILE";
 
@@ -320,6 +328,7 @@ cmNinjaNormalTargetGenerator
       std::string linkCmdVar = "CMAKE_";
       linkCmdVar += this->TargetLinkLanguage;
       linkCmdVar += "_CREATE_STATIC_LIBRARY";
+      linkCmdVar = this->GetFeatureSpecificLinkRuleVariable(linkCmdVar);
       if (const char *linkCmd =
             this->GetMakefile()->GetDefinition(linkCmdVar.c_str()))
         {
@@ -340,6 +349,7 @@ cmNinjaNormalTargetGenerator
       std::string linkCmdVar = "CMAKE_";
       linkCmdVar += this->TargetLinkLanguage;
       linkCmdVar += "_ARCHIVE_CREATE";
+      linkCmdVar = this->GetFeatureSpecificLinkRuleVariable(linkCmdVar);
       const char *linkCmd =
         this->GetMakefile()->GetRequiredDefinition(linkCmdVar.c_str());
       cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
@@ -348,6 +358,7 @@ cmNinjaNormalTargetGenerator
       std::string linkCmdVar = "CMAKE_";
       linkCmdVar += this->TargetLinkLanguage;
       linkCmdVar += "_ARCHIVE_FINISH";
+      linkCmdVar = this->GetFeatureSpecificLinkRuleVariable(linkCmdVar);
       const char *linkCmd =
         this->GetMakefile()->GetRequiredDefinition(linkCmdVar.c_str());
       cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
@@ -478,6 +489,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
   std::string flags = (targetType == cmTarget::EXECUTABLE
                                ? vars["FLAGS"]
                                : vars["ARCH_FLAGS"]);
+
+  this->AddFeatureFlags(flags, this->TargetLinkLanguage);
+
   this->GetLocalGenerator()->AddArchitectureFlags(flags,
                              this->GetGeneratorTarget(),
                              this->TargetLinkLanguage,
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 82f8d1b..2af7bf11 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -97,18 +97,33 @@ const char* cmNinjaTargetGenerator::GetConfigName() const
 }
 
 // TODO: Picked up from cmMakefileTargetGenerator.  Refactor it.
-const char* cmNinjaTargetGenerator::GetFeature(const char* feature)
+const char* cmNinjaTargetGenerator::GetFeature(const char* feature) const
 {
   return this->Target->GetFeature(feature, this->GetConfigName());
 }
 
 // TODO: Picked up from cmMakefileTargetGenerator.  Refactor it.
-bool cmNinjaTargetGenerator::GetFeatureAsBool(const char* feature)
+bool cmNinjaTargetGenerator::GetFeatureAsBool(const char* feature) const
 {
   return cmSystemTools::IsOn(this->GetFeature(feature));
 }
 
 // TODO: Picked up from cmMakefileTargetGenerator.  Refactor it.
+std::string cmNinjaTargetGenerator::GetFeatureSpecificLinkRuleVariable(
+  std::string const& var) const
+{
+  std::string ipoVar = var + "_IPO";
+  if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION") &&
+     this->Makefile->GetDefinition(ipoVar.c_str()))
+    {
+    return ipoVar;
+    }
+
+  return var;
+}
+
+
+// TODO: Picked up from cmMakefileTargetGenerator.  Refactor it.
 void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags,
                                              const char* lang)
 {
diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h
index 2ce1ed7..bce3647 100644
--- a/Source/cmNinjaTargetGenerator.h
+++ b/Source/cmNinjaTargetGenerator.h
@@ -70,8 +70,9 @@ protected:
   std::string LanguageCompilerRule(const std::string& lang) const
   { return lang + "_COMPILER"; }
 
-  const char* GetFeature(const char* feature);
-  bool GetFeatureAsBool(const char* feature);
+  const char* GetFeature(const char* feature) const;
+  bool GetFeatureAsBool(const char* feature) const;
+  std::string GetFeatureSpecificLinkRuleVariable(std::string const& var) const;
   void AddFeatureFlags(std::string& flags, const char* lang);
 
   /**
diff --git a/Tests/IPO/CMakeLists.txt b/Tests/IPO/CMakeLists.txt
index 6dabf86..b45ec89 100644
--- a/Tests/IPO/CMakeLists.txt
+++ b/Tests/IPO/CMakeLists.txt
@@ -1,5 +1,13 @@
 cmake_minimum_required (VERSION 2.8)
-project(IPO NONE)
+project(IPO C)
+
+message("======== IPO specific variables ======")
+get_cmake_property(variables VARIABLES)
+foreach(variable ${variables})
+  if("${variable}xxx" MATCHES "_IPOxxx")
+    message("${variable}: [${${variable}}]")
+  endif()
+endforeach()
 
 set_property(DIRECTORY PROPERTY INTERPROCEDURAL_OPTIMIZATION 1)
 

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

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list