瀏覽代碼

ENH: Removed cmMakefile arguments from cmTarget methods because cmTarget has the ivar m_Makefile now. Re-implemented cmLocalUnixMakefileGenerator3::AppendAnyDepend to use the new global knowledge and avoid the need to look at the cache for information about other targets. This should fix problems with custom commands and executables with the OUTPUT_NAME set. Also the <target>_LIBRARY_TYPE cache variable is no longer needed at all and has been removed.

Brad King 20 年之前
父節點
當前提交
163e3ff56c
共有 5 個文件被更改,包括 95 次插入175 次删除
  1. 5 5
      Source/cmLocalGenerator.cxx
  2. 45 81
      Source/cmLocalUnixMakefileGenerator3.cxx
  3. 0 32
      Source/cmMakefile.cxx
  4. 32 39
      Source/cmTarget.cxx
  5. 13 18
      Source/cmTarget.h

+ 5 - 5
Source/cmLocalGenerator.cxx

@@ -363,7 +363,7 @@ void cmLocalGenerator::GenerateInstallRules()
       case cmTarget::STATIC_LIBRARY:
       case cmTarget::MODULE_LIBRARY:
         fname = libOutPath;
-        fname += l->second.GetFullName(m_Makefile);
+        fname += l->second.GetFullName();
         files = fname.c_str();
         this->AddInstallRule(fout, dest, type, files);
         break;
@@ -371,7 +371,7 @@ void cmLocalGenerator::GenerateInstallRules()
         {
         // Special code to handle DLL
         fname = libOutPath;
-        fname += l->second.GetFullName(m_Makefile);
+        fname += l->second.GetFullName();
         std::string ext = cmSystemTools::GetFilenameExtension(fname);
         ext = cmSystemTools::LowerCase(ext);
         if ( ext == ".dll" )
@@ -428,7 +428,7 @@ void cmLocalGenerator::GenerateInstallRules()
         if(l->second.GetPropertyAsBool("MACOSX_BUNDLE"))
           {
           fname = exeOutPath;
-          fname += l->second.GetFullName(m_Makefile);
+          fname += l->second.GetFullName();
           std::string plist = fname;
           plist += ".app/Contents/Info.plist";
           fname += ".app/Contents/MacOS/";
@@ -451,7 +451,7 @@ void cmLocalGenerator::GenerateInstallRules()
         else
           {
           fname = exeOutPath;
-          fname += l->second.GetFullName(m_Makefile);
+          fname += l->second.GetFullName();
           files = fname.c_str();
           this->AddInstallRule(fout, dest, type, files, false,
                                properties.c_str());
@@ -668,7 +668,7 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
   std::string createRule = "CMAKE_";
   createRule += llang;
   createRule += target.GetCreateRuleVariable();
-  std::string targetName = target.GetFullName(m_Makefile);
+  std::string targetName = target.GetFullName();
   // Executable :
   // Shared Library:
   // Static Library:

+ 45 - 81
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -1301,7 +1301,7 @@ cmLocalUnixMakefileGenerator3
   // Get the name of the executable to generate.
   std::string targetName;
   std::string targetNameReal;
-  target.GetExecutableNames(m_Makefile, targetName, targetNameReal);
+  target.GetExecutableNames(targetName, targetNameReal);
 
   // Construct the full path version of the names.
   std::string outpath = m_ExecutableOutputPath;
@@ -1382,8 +1382,7 @@ cmLocalUnixMakefileGenerator3
   {
   std::string cleanName;
   std::string cleanRealName;
-  target.GetExecutableCleanNames(m_Makefile, cleanName,
-                                 cleanRealName);
+  target.GetExecutableCleanNames(cleanName, cleanRealName);
   std::string cleanFullName = outpath + cleanName;
   std::string cleanFullRealName = outpath + cleanRealName;
   exeCleanFiles.push_back
@@ -1646,8 +1645,7 @@ cmLocalUnixMakefileGenerator3
   std::string targetNameSO;
   std::string targetNameReal;
   std::string targetNameBase;
-  target.GetLibraryNames(m_Makefile,
-                         targetName, targetNameSO,
+  target.GetLibraryNames(targetName, targetNameSO,
                          targetNameReal, targetNameBase);
 
   // Construct the full path version of the names.
@@ -1698,8 +1696,7 @@ cmLocalUnixMakefileGenerator3
   std::string cleanSharedName;
   std::string cleanSharedSOName;
   std::string cleanSharedRealName;
-  target.GetLibraryCleanNames(m_Makefile,
-                              cleanStaticName,
+  target.GetLibraryCleanNames(cleanStaticName,
                               cleanSharedName,
                               cleanSharedSOName,
                               cleanSharedRealName);
@@ -2178,85 +2175,52 @@ cmLocalUnixMakefileGenerator3
                   bool assume_unknown_is_file)
 {
   // There are a few cases for the name of the target:
-  //  - CMake target in this directory: depend on it.
-  //  - CMake target in another directory: depend and add jump-and-build.
+  //  - CMake target.
   //  - Full path to a file: depend on it.
-  //  - Other format (like -lm): do nothing.
-
-  // If it is an executable or library target there will be a
-  // definition for it.
-  std::string dirVar = name;
-  dirVar += "_CMAKE_PATH";
-  const char* dir = m_Makefile->GetDefinition(dirVar.c_str());
-  if(dir && *dir)
-    {
-    // This is a CMake target somewhere in this project.
-    // Get the type of the library.  If it does not have a type then
-    // it is an executable.
-    std::string typeVar = name;
-    typeVar += "_LIBRARY_TYPE";
-    const char* libType = m_Makefile->GetDefinition(typeVar.c_str());
-    
-    // Get the output path for this target type.
-    std::string tgtOutputPath;
-    if(libType)
-      {
-      tgtOutputPath = m_LibraryOutputPath;
-      }
-    else
-      {
-      tgtOutputPath = m_ExecutableOutputPath;
-      }
+  //  - Other format (like -lm): do nothing unless assume_unknown_is_file is true.
 
-    // Get the path to the target.
-    std::string tgtPath;
-    if(tgtOutputPath.size())
-      {
-      tgtPath = tgtOutputPath;
-      }
-    else
-      {
-      tgtPath = dir;
-      tgtPath += "/";
-      }
+  // Look for a CMake target in the current makefile.
+  cmTarget* target = m_Makefile->FindTarget(name);
 
-    // Add the name of the targets's file.  This depends on the type
-    // of the target.
-    std::string prefix;
-    std::string suffix;
-    if(!libType)
-      {
-      suffix = cmSystemTools::GetExecutableExtension();
-      }
-    else if(strcmp(libType, "SHARED") == 0)
-      {
-      prefix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
-      suffix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
-      }
-    else if(strcmp(libType, "MODULE") == 0)
-      {
-      prefix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
-      suffix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
-      }
-    else if(strcmp(libType, "STATIC") == 0)
-      {
-      prefix = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
-      suffix = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
-      }
-    tgtPath += prefix;
-    tgtPath += name;
-    tgtPath += suffix;
-
-    // Add a dependency on the target.
-    depends.push_back(tgtPath.c_str());
+  // If no target was found in the current makefile search globally.
+  bool local = target;
+  if(!local)
+    {
+    target = m_GlobalGenerator->FindTarget(0, name);
     }
-  else if(m_Makefile->GetTargets().find(name) !=
-          m_Makefile->GetTargets().end())
+
+  // If a target was found then depend on it.
+  if(target)
     {
-    // This is a CMake target that is not an executable or library.
-    // It must be in this directory, so just depend on the name
-    // directly.
-    depends.push_back(name);
+    switch (target->GetType())
+      {
+      case cmTarget::EXECUTABLE:
+      case cmTarget::STATIC_LIBRARY:
+      case cmTarget::SHARED_LIBRARY:
+      case cmTarget::MODULE_LIBRARY:
+        {
+        // Get the location of the target's output file and depend on it.
+        if(const char* location = target->GetProperty("LOCATION"))
+          {
+          depends.push_back(location);
+          }
+        }
+        break;
+      case cmTarget::UTILITY:
+        {
+        if(local)
+          {
+          // This is a utility target in the current makefile.  Just
+          // depend on it directly.
+          depends.push_back(name);
+          }
+        }
+        break;
+      case cmTarget::INSTALL_FILES:
+      case cmTarget::INSTALL_PROGRAMS:
+        // Do not depend on install targets.
+        break;
+      }
     }
   else if(cmSystemTools::FileIsFullPath(name))
     {

+ 0 - 32
Source/cmMakefile.cxx

@@ -1096,38 +1096,6 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
     AddCacheEntry(libPath.c_str(),
                   this->GetCurrentOutputDirectory(),
                   "Path to a library", cmCacheManager::INTERNAL);
-  
-  // Add an entry into the cache
-  std::string ltname = lname;
-  ltname += "_LIBRARY_TYPE";
-  switch (shared)
-    {
-    case 0:
-      this->GetCacheManager()->AddCacheEntry(ltname.c_str(),"STATIC",
-                                             "Whether a library is static, shared or module.",
-                                             cmCacheManager::INTERNAL);
-      break;
-    case 1:
-      this->GetCacheManager()->
-        AddCacheEntry(ltname.c_str(),
-                      "SHARED",
-                      "Whether a library is static, shared or module.",
-                      cmCacheManager::INTERNAL);
-      break;
-    case 2:
-      this->GetCacheManager()->
-        AddCacheEntry(ltname.c_str(),
-                      "MODULE",
-                      "Whether a library is static, shared or module.",
-                      cmCacheManager::INTERNAL);
-      break;
-    default:
-      this->GetCacheManager()->
-        AddCacheEntry(ltname.c_str(),
-                      "STATIC",
-                      "Whether a library is static, shared or module.",
-                      cmCacheManager::INTERNAL);
-    }
 }
 
 cmTarget* cmMakefile::AddExecutable(const char *exeName, 

+ 32 - 39
Source/cmTarget.cxx

@@ -733,7 +733,7 @@ void cmTarget::UpdateLocation()
     target_location += cfgid;
     target_location += "/";
     }  
-  target_location += this->GetFullName(m_Makefile);
+  target_location += this->GetFullName();
   this->SetProperty("LOCATION",target_location.c_str());
 }
 
@@ -927,13 +927,12 @@ const char* cmTarget::GetPrefixVariableInternal(TargetType type)
   return "";
 }
 
-std::string cmTarget::GetFullName(cmMakefile* mf)
+std::string cmTarget::GetFullName()
 {
-  return this->GetFullNameInternal(mf, this->GetType());
+  return this->GetFullNameInternal(this->GetType());
 }
 
-std::string cmTarget::GetFullNameInternal(cmMakefile* mf,
-                                          TargetType type)
+std::string cmTarget::GetFullNameInternal(TargetType type)
 {
   const char* targetPrefix = this->GetProperty("PREFIX");
   const char* targetSuffix = this->GetProperty("SUFFIX");
@@ -945,31 +944,31 @@ std::string cmTarget::GetFullNameInternal(cmMakefile* mf,
   const char* suffixVar = this->GetSuffixVariableInternal(type);
   const char* ll =
     this->GetLinkerLanguage(
-      mf->GetLocalGenerator()->GetGlobalGenerator());
+      m_Makefile->GetLocalGenerator()->GetGlobalGenerator());
   // first try language specific suffix
   if(ll)
     {
     if(!targetSuffix && suffixVar && *suffixVar)
       {
       std::string langSuff = suffixVar + std::string("_") + ll;
-      targetSuffix = mf->GetDefinition(langSuff.c_str());
+      targetSuffix = m_Makefile->GetDefinition(langSuff.c_str());
       }
     if(!targetPrefix && prefixVar && *prefixVar)
       {
       std::string langPrefix = prefixVar + std::string("_") + ll;
-      targetPrefix = mf->GetDefinition(langPrefix.c_str());
+      targetPrefix = m_Makefile->GetDefinition(langPrefix.c_str());
       }
     }
 
   // if there is no prefix on the target use the cmake definition
   if(!targetPrefix && prefixVar)
     {
-    targetPrefix = mf->GetSafeDefinition(prefixVar);
+    targetPrefix = m_Makefile->GetSafeDefinition(prefixVar);
     }
   // if there is no suffix on the target use the cmake definition
   if(!targetSuffix && suffixVar)
     {
-    targetSuffix = mf->GetSafeDefinition(suffixVar);
+    targetSuffix = m_Makefile->GetSafeDefinition(suffixVar);
     }
 
   // Begin the final name with the prefix.
@@ -994,13 +993,13 @@ std::string cmTarget::GetFullNameInternal(cmMakefile* mf,
   return name;
 }
 
-std::string cmTarget::GetBaseName(cmMakefile* mf) 
+std::string cmTarget::GetBaseName()
 {
-  return this->GetBaseNameInternal(mf, this->GetType());
+  return this->GetBaseNameInternal(this->GetType());
 }
 
 std::string
-cmTarget::GetBaseNameInternal(cmMakefile* mf, TargetType type) 
+cmTarget::GetBaseNameInternal(TargetType type) 
 {
   std::string pathPrefix = "";
 #ifdef __APPLE__
@@ -1018,16 +1017,16 @@ cmTarget::GetBaseNameInternal(cmMakefile* mf, TargetType type)
     // first check for a language specific suffix var
     const char* ll =
       this->GetLinkerLanguage(
-        mf->GetLocalGenerator()->GetGlobalGenerator());
+        m_Makefile->GetLocalGenerator()->GetGlobalGenerator());
     if(ll)
       {
       std::string langPrefix = prefixVar + std::string("_") + ll;
-      targetPrefix = mf->GetDefinition(langPrefix.c_str());
+      targetPrefix = m_Makefile->GetDefinition(langPrefix.c_str());
       }
     // if there not a language specific suffix then use the general one
     if(!targetPrefix)
       {
-      targetPrefix = mf->GetSafeDefinition(prefixVar);
+      targetPrefix = m_Makefile->GetSafeDefinition(prefixVar);
       }
     }
   std::string name = pathPrefix;
@@ -1036,21 +1035,19 @@ cmTarget::GetBaseNameInternal(cmMakefile* mf, TargetType type)
   return name;
 }
 
-void cmTarget::GetLibraryNames(cmMakefile* mf,
-                               std::string& name,
+void cmTarget::GetLibraryNames(std::string& name,
                                std::string& soName,
                                std::string& realName,
                                std::string& baseName) 
 {
   // Get the names based on the real type of the library.
-  this->GetLibraryNamesInternal(mf, name, soName, realName, this->GetType());
+  this->GetLibraryNamesInternal(name, soName, realName, this->GetType());
 
   // The library name without extension.
-  baseName = this->GetBaseName(mf);
+  baseName = this->GetBaseName();
 }
 
-void cmTarget::GetLibraryCleanNames(cmMakefile* mf,
-                                    std::string& staticName,
+void cmTarget::GetLibraryCleanNames(std::string& staticName,
                                     std::string& sharedName,
                                     std::string& sharedSOName,
                                     std::string& sharedRealName) 
@@ -1058,7 +1055,7 @@ void cmTarget::GetLibraryCleanNames(cmMakefile* mf,
   // Get the name as if this were a static library.
   std::string soName;
   std::string realName;
-  this->GetLibraryNamesInternal(mf, staticName, soName, realName,
+  this->GetLibraryNamesInternal(staticName, soName, realName,
                                 cmTarget::STATIC_LIBRARY);
 
   // Get the names as if this were a shared library.
@@ -1069,19 +1066,18 @@ void cmTarget::GetLibraryCleanNames(cmMakefile* mf,
     // shared library will never be present.  In the latter case the
     // type will never be MODULE.  Either way the only names that
     // might have to be cleaned are the shared library names.
-    this->GetLibraryNamesInternal(mf, sharedName, sharedSOName,
+    this->GetLibraryNamesInternal(sharedName, sharedSOName,
                                   sharedRealName, cmTarget::SHARED_LIBRARY);
     }
   else
     {
     // Use the name of the real type of the library (shared or module).
-    this->GetLibraryNamesInternal(mf, sharedName, sharedSOName,
+    this->GetLibraryNamesInternal(sharedName, sharedSOName,
                                   sharedRealName, this->GetType());
     }
 }
 
-void cmTarget::GetLibraryNamesInternal(cmMakefile* mf,
-                                       std::string& name,
+void cmTarget::GetLibraryNamesInternal(std::string& name,
                                        std::string& soName,
                                        std::string& realName,
                                        TargetType type) 
@@ -1089,7 +1085,7 @@ void cmTarget::GetLibraryNamesInternal(cmMakefile* mf,
   // Construct the name of the soname flag variable for this language.
   const char* ll =
     this->GetLinkerLanguage(
-      mf->GetLocalGenerator()->GetGlobalGenerator());
+      m_Makefile->GetLocalGenerator()->GetGlobalGenerator());
   std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
   if(ll)
     {
@@ -1102,7 +1098,7 @@ void cmTarget::GetLibraryNamesInternal(cmMakefile* mf,
   const char* version = this->GetProperty("VERSION");
   const char* soversion = this->GetProperty("SOVERSION");
   if((type != cmTarget::SHARED_LIBRARY && type != cmTarget::MODULE_LIBRARY) ||
-     !mf->GetDefinition(sonameFlag.c_str()))
+     !m_Makefile->GetDefinition(sonameFlag.c_str()))
     {
     // Versioning is supported only for shared libraries and modules,
     // and then only when the platform supports an soname flag.
@@ -1117,7 +1113,7 @@ void cmTarget::GetLibraryNamesInternal(cmMakefile* mf,
     }
 
   // The library name.
-  name = this->GetFullNameInternal(mf, type);
+  name = this->GetFullNameInternal(type);
 
   // The library's soname.
   soName = name;
@@ -1141,24 +1137,21 @@ void cmTarget::GetLibraryNamesInternal(cmMakefile* mf,
     }
 }
 
-void cmTarget::GetExecutableNames(cmMakefile* mf,
-                                  std::string& name,
+void cmTarget::GetExecutableNames(std::string& name,
                                   std::string& realName)
 {
   // Get the names based on the real type of the executable.
-  this->GetExecutableNamesInternal(mf, name, realName, this->GetType());
+  this->GetExecutableNamesInternal(name, realName, this->GetType());
 }
 
-void cmTarget::GetExecutableCleanNames(cmMakefile* mf,
-                                       std::string& name,
+void cmTarget::GetExecutableCleanNames(std::string& name,
                                        std::string& realName)
 {
   // Get the name and versioned name of this executable.
-  this->GetExecutableNamesInternal(mf, name, realName, cmTarget::EXECUTABLE);
+  this->GetExecutableNamesInternal(name, realName, cmTarget::EXECUTABLE);
 }
 
-void cmTarget::GetExecutableNamesInternal(cmMakefile* mf,
-                                          std::string& name,
+void cmTarget::GetExecutableNamesInternal(std::string& name,
                                           std::string& realName,
                                           TargetType type)
 {
@@ -1176,7 +1169,7 @@ void cmTarget::GetExecutableNamesInternal(cmMakefile* mf,
 #endif
 
   // The executable name.
-  name = this->GetFullNameInternal(mf, type);
+  name = this->GetFullNameInternal(type);
 
   // The executable's real name on disk.
   realName = name;

+ 13 - 18
Source/cmTarget.h

@@ -163,18 +163,18 @@ public:
   ///! Return the name of the variable to look up the target suffix
   const char* GetPrefixVariable();
 
-  /** Get the full name of the target according to the settings in the
-      given makefile.  */
-  std::string GetFullName(cmMakefile* mf);
+  /** Get the full name of the target according to the settings in its
+      makefile.  */
+  std::string GetFullName();
 
   /** Get the base name (no suffix) of the target according to the
-      settings in the given makefile.  */
-  std::string GetBaseName(cmMakefile* mf);
+      settings in its makefile.  */
+  std::string GetBaseName();
 
   /** Get the names of the library needed to generate a build rule
       that takes into account shared library version numbers.  This
       should be called only on a library target.  */
-  void GetLibraryNames(cmMakefile* mf, std::string& name,
+  void GetLibraryNames(std::string& name,
                        std::string& soName, std::string& realName,
                        std::string& baseName);
 
@@ -182,8 +182,7 @@ public:
       the library from the build tree either before linking or during
       a clean step.  This should be called only on a library
       target.  */
-  void GetLibraryCleanNames(cmMakefile* mf,
-                            std::string& staticName,
+  void GetLibraryCleanNames(std::string& staticName,
                             std::string& sharedName,
                             std::string& sharedSOName,
                             std::string& sharedRealName);
@@ -191,15 +190,13 @@ public:
   /** Get the names of the executable needed to generate a build rule
       that takes into account executable version numbers.  This should
       be called only on an executable target.  */
-  void GetExecutableNames(cmMakefile* mf, std::string& name,
-                          std::string& realName);
+  void GetExecutableNames(std::string& name, std::string& realName);
 
   /** Get the names of the executable used to remove existing copies
       of the executable from the build tree either before linking or
       during a clean step.  This should be called only on an
       executable target.  */
-  void GetExecutableCleanNames(cmMakefile* mf, std::string& name,
-                               std::string& realName);
+  void GetExecutableCleanNames(std::string& name, std::string& realName);
 private:
   /**
    * A list of direct dependencies. Use in conjunction with DependencyMap.
@@ -256,15 +253,13 @@ private:
 
   const char* GetSuffixVariableInternal(TargetType type);
   const char* GetPrefixVariableInternal(TargetType type);
-  std::string GetFullNameInternal(cmMakefile* mf, TargetType type);
-  std::string GetBaseNameInternal(cmMakefile* mf, TargetType type);
-  void GetLibraryNamesInternal(cmMakefile* mf,
-                               std::string& name,
+  std::string GetFullNameInternal(TargetType type);
+  std::string GetBaseNameInternal(TargetType type);
+  void GetLibraryNamesInternal(std::string& name,
                                std::string& soName,
                                std::string& realName,
                                TargetType type);
-  void GetExecutableNamesInternal(cmMakefile* mf,
-                                  std::string& name,
+  void GetExecutableNamesInternal(std::string& name,
                                   std::string& realName,
                                   TargetType type);