Browse Source

ENH: Added implib option to cmTarget::GetDirectory to support a separate directory containing the import library. This is an incremental step for bug#4210.

Brad King 18 years ago
parent
commit
528f60f4a6

+ 1 - 1
Source/cmInstallTargetGenerator.cxx

@@ -54,7 +54,7 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
     }
     }
   else
   else
     {
     {
-    fromDir = this->Target->GetDirectory();
+    fromDir = this->Target->GetDirectory(0, this->ImportLibrary);
     fromDir += "/";
     fromDir += "/";
     }
     }
 
 

+ 6 - 2
Source/cmLocalGenerator.cxx

@@ -1619,6 +1619,10 @@ void cmLocalGenerator
     linkType = cmTarget::DEBUG;
     linkType = cmTarget::DEBUG;
     }
     }
 
 
+  // Check whether we should use an import library for linking a target.
+  bool implib =
+    this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")?true:false;
+
   // Get the list of libraries against which this target wants to link.
   // Get the list of libraries against which this target wants to link.
   std::vector<std::string> linkLibraries;
   std::vector<std::string> linkLibraries;
   const cmTarget::LinkLibraryVectorType& inLibs = target.GetLinkLibraries();
   const cmTarget::LinkLibraryVectorType& inLibs = target.GetLinkLibraries();
@@ -1658,9 +1662,9 @@ void cmLocalGenerator
         // Pass the full path to the target file but purposely leave
         // Pass the full path to the target file but purposely leave
         // off the per-configuration subdirectory.  The link directory
         // off the per-configuration subdirectory.  The link directory
         // ordering knows how to deal with this.
         // ordering knows how to deal with this.
-        std::string linkItem = tgt->GetDirectory(0);
+        std::string linkItem = tgt->GetDirectory(0, implib);
         linkItem += "/";
         linkItem += "/";
-        linkItem += tgt->GetFullName(config);
+        linkItem += tgt->GetFullName(config, implib);
         linkLibraries.push_back(linkItem);
         linkLibraries.push_back(linkItem);
         // For full path, use the true location.
         // For full path, use the true location.
         if(fullPathLibs)
         if(fullPathLibs)

+ 9 - 15
Source/cmLocalVisualStudio7Generator.cxx

@@ -605,7 +605,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
       target.GetType() == cmTarget::MODULE_LIBRARY))
       target.GetType() == cmTarget::MODULE_LIBRARY))
     {
     {
     fout <<  "\t\t\t\tProgramDataBaseFileName=\""
     fout <<  "\t\t\t\tProgramDataBaseFileName=\""
-         << target.GetDirectory() << "/$(OutDir)/"
+         << target.GetDirectory(configName) << "/"
          << target.GetPDBName(configName) << "\"\n";
          << target.GetPDBName(configName) << "\"\n";
     }
     }
   fout << "/>\n";  // end of <Tool Name=VCCLCompilerTool
   fout << "/>\n";  // end of <Tool Name=VCCLCompilerTool
@@ -728,8 +728,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
     case cmTarget::STATIC_LIBRARY:
     case cmTarget::STATIC_LIBRARY:
     {
     {
     std::string targetNameFull = target.GetFullName(configName);
     std::string targetNameFull = target.GetFullName(configName);
-    std::string libpath = target.GetDirectory();
-    libpath += "/$(OutDir)/";
+    std::string libpath = target.GetDirectory(configName);
+    libpath += "/";
     libpath += targetNameFull;
     libpath += targetNameFull;
     fout << "\t\t\t<Tool\n"
     fout << "\t\t\t<Tool\n"
          << "\t\t\t\tName=\"VCLibrarianTool\"\n";
          << "\t\t\t\tName=\"VCLibrarianTool\"\n";
@@ -795,9 +795,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
          << " ";
          << " ";
     this->OutputLibraries(fout, linkLibs);
     this->OutputLibraries(fout, linkLibs);
     fout << "\"\n";
     fout << "\"\n";
-    temp = target.GetDirectory();
-    temp += "/";
-    temp += configName;
+    temp = target.GetDirectory(configName);
     temp += "/";
     temp += "/";
     temp += targetNameFull;
     temp += targetNameFull;
     fout << "\t\t\t\tOutputFile=\""
     fout << "\t\t\t\tOutputFile=\""
@@ -808,8 +806,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
     this->OutputLibraryDirectories(fout, linkDirs);
     this->OutputLibraryDirectories(fout, linkDirs);
     fout << "\"\n";
     fout << "\"\n";
     this->OutputModuleDefinitionFile(fout, target);
     this->OutputModuleDefinitionFile(fout, target);
-    temp = target.GetDirectory();
-    temp += "/$(OutDir)/";
+    temp = target.GetDirectory(configName);
+    temp += "/";
     temp += targetNamePDB;
     temp += targetNamePDB;
     fout << "\t\t\t\tProgramDataBaseFile=\"" <<
     fout << "\t\t\t\tProgramDataBaseFile=\"" <<
       this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
       this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
@@ -826,9 +824,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
       {
       {
       fout << "\t\t\t\tStackReserveSize=\"" << stackVal  << "\"\n";
       fout << "\t\t\t\tStackReserveSize=\"" << stackVal  << "\"\n";
       }
       }
-    temp = target.GetDirectory();
-    temp += "/";
-    temp += configName;
+    temp = target.GetDirectory(configName, true);
     temp += "/";
     temp += "/";
     temp += targetNameImport;
     temp += targetNameImport;
     fout << "\t\t\t\tImportLibrary=\""
     fout << "\t\t\t\tImportLibrary=\""
@@ -875,9 +871,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
          << " ";
          << " ";
     this->OutputLibraries(fout, linkLibs);
     this->OutputLibraries(fout, linkLibs);
     fout << "\"\n";
     fout << "\"\n";
-    temp = target.GetDirectory();
-    temp += "/";
-    temp += configName;
+    temp = target.GetDirectory(configName);
     temp += "/";
     temp += "/";
     temp += targetNameFull;
     temp += targetNameFull;
     fout << "\t\t\t\tOutputFile=\"" 
     fout << "\t\t\t\tOutputFile=\"" 
@@ -888,7 +882,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
     this->OutputLibraryDirectories(fout, linkDirs);
     this->OutputLibraryDirectories(fout, linkDirs);
     fout << "\"\n";
     fout << "\"\n";
     fout << "\t\t\t\tProgramDataBaseFile=\""
     fout << "\t\t\t\tProgramDataBaseFile=\""
-         << target.GetDirectory() << "\\$(OutDir)\\" << targetNamePDB
+         << target.GetDirectory(configName) << "/" << targetNamePDB
          << "\"\n";
          << "\"\n";
     if(strcmp(configName, "Debug") == 0
     if(strcmp(configName, "Debug") == 0
        || strcmp(configName, "RelWithDebInfo") == 0)
        || strcmp(configName, "RelWithDebInfo") == 0)

+ 5 - 1
Source/cmMakefileLibraryTargetGenerator.cxx

@@ -246,6 +246,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
 
 
   // Construct the full path version of the names.
   // Construct the full path version of the names.
   std::string outpath;
   std::string outpath;
+  std::string outpathImp;
   if(relink)
   if(relink)
     {
     {
     outpath = this->Makefile->GetStartOutputDirectory();
     outpath = this->Makefile->GetStartOutputDirectory();
@@ -253,17 +254,20 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     outpath += "/CMakeRelink.dir";
     outpath += "/CMakeRelink.dir";
     cmSystemTools::MakeDirectory(outpath.c_str());
     cmSystemTools::MakeDirectory(outpath.c_str());
     outpath += "/";
     outpath += "/";
+    outpathImp = outpath;
     }
     }
   else
   else
     {
     {
     outpath = this->Target->GetDirectory();
     outpath = this->Target->GetDirectory();
     outpath += "/";
     outpath += "/";
+    outpathImp = this->Target->GetDirectory(0, true);
+    outpathImp += "/";
     }
     }
   std::string targetFullPath = outpath + targetName;
   std::string targetFullPath = outpath + targetName;
   std::string targetFullPathPDB = outpath + targetNamePDB;
   std::string targetFullPathPDB = outpath + targetNamePDB;
   std::string targetFullPathSO = outpath + targetNameSO;
   std::string targetFullPathSO = outpath + targetNameSO;
   std::string targetFullPathReal = outpath + targetNameReal;
   std::string targetFullPathReal = outpath + targetNameReal;
-  std::string targetFullPathImport = outpath + targetNameImport;
+  std::string targetFullPathImport = outpathImp + targetNameImport;
 
 
   // Construct the output path version of the names for use in command
   // Construct the output path version of the names for use in command
   // arguments.
   // arguments.

+ 15 - 6
Source/cmTarget.cxx

@@ -661,7 +661,7 @@ const std::vector<std::string>& cmTarget::GetLinkDirectories()
         // Add the directory only if it is not already present.  This
         // Add the directory only if it is not already present.  This
         // is an N^2 algorithm for adding the directories, but N
         // is an N^2 algorithm for adding the directories, but N
         // should not get very big.
         // should not get very big.
-        const char* libpath = tgt->GetDirectory();
+        const char* libpath = tgt->GetDirectory(0, true);
         if(std::find(this->LinkDirectories.begin(), 
         if(std::find(this->LinkDirectories.begin(), 
                      this->LinkDirectories.end(),
                      this->LinkDirectories.end(),
                      libpath) == this->LinkDirectories.end())
                      libpath) == this->LinkDirectories.end())
@@ -1091,11 +1091,11 @@ void cmTarget::SetProperty(const char* prop, const char* value)
   this->Properties.SetProperty(prop, value, cmProperty::TARGET);
   this->Properties.SetProperty(prop, value, cmProperty::TARGET);
 }
 }
 
 
-const char* cmTarget::GetDirectory(const char* config)
+const char* cmTarget::GetDirectory(const char* config, bool implib)
 {
 {
   if(config)
   if(config)
     {
     {
-    this->Directory = this->GetOutputDir();
+    this->Directory = this->GetOutputDir(implib);
     // Add the configuration's subdirectory.
     // Add the configuration's subdirectory.
     this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
     this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
       AppendDirectoryForConfig("/", config, "", this->Directory);
       AppendDirectoryForConfig("/", config, "", this->Directory);
@@ -1103,7 +1103,7 @@ const char* cmTarget::GetDirectory(const char* config)
     }
     }
   else
   else
     {
     {
-    return this->GetOutputDir();
+    return this->GetOutputDir(implib);
     }
     }
 }
 }
 
 
@@ -1446,7 +1446,7 @@ void cmTarget::GetFullName(std::string& prefix, std::string& base,
 std::string cmTarget::GetFullPath(const char* config, bool implib)
 std::string cmTarget::GetFullPath(const char* config, bool implib)
 {
 {
   // Start with the output directory for the target.
   // Start with the output directory for the target.
-  std::string fpath = this->GetDirectory(config);
+  std::string fpath = this->GetDirectory(config, implib);
   fpath += "/";
   fpath += "/";
 
 
   // Add the full name of the target.
   // Add the full name of the target.
@@ -1935,8 +1935,17 @@ std::string cmTarget::GetInstallNameDirForInstallTree(const char*)
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-const char* cmTarget::GetOutputDir()
+const char* cmTarget::GetOutputDir(bool implib)
 {
 {
+  // The implib option is only allowed for shared libraries.
+  if(this->GetType() != cmTarget::SHARED_LIBRARY)
+    {
+    implib = false;
+    }
+
+  // For now the import library is always in the same directory as the DLL.
+  static_cast<void>(implib);
+
   if(this->OutputDir.empty())
   if(this->OutputDir.empty())
     {
     {
     // Lookup the output path for this target type.
     // Lookup the output path for this target type.

+ 2 - 2
Source/cmTarget.h

@@ -174,7 +174,7 @@ public:
       configuration name is given then the generator will add its
       configuration name is given then the generator will add its
       subdirectory for that configuration.  Otherwise just the canonical
       subdirectory for that configuration.  Otherwise just the canonical
       output directory is given.  */
       output directory is given.  */
-  const char* GetDirectory(const char* config = 0);
+  const char* GetDirectory(const char* config = 0, bool implib = false);
 
 
   /** Get the location of the target in the build tree for the given
   /** Get the location of the target in the build tree for the given
       configuration.  This location is suitable for use as the LOCATION
       configuration.  This location is suitable for use as the LOCATION
@@ -340,7 +340,7 @@ private:
   void SetPropertyDefault(const char* property, const char* default_value);
   void SetPropertyDefault(const char* property, const char* default_value);
 
 
   // Get the full path to the target output directory.
   // Get the full path to the target output directory.
-  const char* GetOutputDir();
+  const char* GetOutputDir(bool implib);
 
 
 private:
 private:
   std::string Name;
   std::string Name;