[Cmake-commits] CMake branch, next, updated. v2.8.12.2-7720-g7e21d8d

Nils Gladitz nilsgladitz at gmail.com
Fri Feb 14 05:15:46 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  7e21d8d7d49f1f2da42f331d768f8b5a46b7ecff (commit)
       via  e4c5b620c7bc48c9145aa1fe9b23b6f97d68ea22 (commit)
      from  49b96a74d9ec869722226328ed54ca801a73a44e (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=7e21d8d7d49f1f2da42f331d768f8b5a46b7ecff
commit 7e21d8d7d49f1f2da42f331d768f8b5a46b7ecff
Merge: 49b96a7 e4c5b62
Author:     Nils Gladitz <nilsgladitz at gmail.com>
AuthorDate: Fri Feb 14 05:15:45 2014 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Fri Feb 14 05:15:45 2014 -0500

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


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e4c5b620c7bc48c9145aa1fe9b23b6f97d68ea22
commit e4c5b620c7bc48c9145aa1fe9b23b6f97d68ea22
Author:     Nils Gladitz <nilsgladitz at gmail.com>
AuthorDate: Fri Jan 31 23:56:40 2014 +0100
Commit:     Nils Gladitz <nilsgladitz at gmail.com>
CommitDate: Fri Feb 14 11:14:23 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..a38ebce 100644
--- a/Modules/Compiler/GNU.cmake
+++ b/Modules/Compiler/GNU.cmake
@@ -55,4 +55,96 @@ 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}"
+        DOC "gcc provided wrapper for ar which adds the --plugin option"
+      )
+
+      find_program(CMAKE_GCC_RANLIB NAMES
+        "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib"
+        "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${_version}"
+        DOC "gcc provided wrapper for ranlib which adds the --plugin option"
+      )
+
+      mark_as_advanced(CMAKE_GCC_AR CMAKE_GCC_RANLIB)
+    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