1
0
Эх сурвалжийг харах

added TARGET_LINK_LIBRARY command and support for debug and release libraries to link against

Ken Martin 24 жил өмнө
parent
commit
2da0c57d46

+ 4 - 0
Source/cmCommands.cxx

@@ -14,6 +14,7 @@
 #include "cmIncludeDirectoryCommand.cxx"
 #include "cmIncludeDirectoryCommand.cxx"
 #include "cmLinkDirectoriesCommand.cxx"
 #include "cmLinkDirectoriesCommand.cxx"
 #include "cmLinkLibrariesCommand.cxx"
 #include "cmLinkLibrariesCommand.cxx"
+#include "cmTargetLinkLibrariesCommand.cxx"
 #include "cmProjectCommand.cxx"
 #include "cmProjectCommand.cxx"
 #include "cmSourceFilesCommand.cxx"
 #include "cmSourceFilesCommand.cxx"
 #include "cmSourceFilesRequireCommand.cxx"
 #include "cmSourceFilesRequireCommand.cxx"
@@ -24,6 +25,7 @@
 #include "cmWin32DefinesCommand.cxx"
 #include "cmWin32DefinesCommand.cxx"
 #include "cmWin32LibrariesCommand.cxx"
 #include "cmWin32LibrariesCommand.cxx"
 #include "cmWin32IncludeDirectoryCommand.cxx"
 #include "cmWin32IncludeDirectoryCommand.cxx"
+#include "cmConfigureFile.cxx"
 #include "cmConfigureFileNoAutoconf.cxx"
 #include "cmConfigureFileNoAutoconf.cxx"
 #include "cmCableCommand.cxx"
 #include "cmCableCommand.cxx"
 #include "cmCableData.cxx"
 #include "cmCableData.cxx"
@@ -64,6 +66,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
   commands.push_back(new cmIncludeDirectoryCommand);
   commands.push_back(new cmIncludeDirectoryCommand);
   commands.push_back(new cmLinkDirectoriesCommand);
   commands.push_back(new cmLinkDirectoriesCommand);
   commands.push_back(new cmLinkLibrariesCommand);
   commands.push_back(new cmLinkLibrariesCommand);
+  commands.push_back(new cmTargetLinkLibrariesCommand);
   commands.push_back(new cmProjectCommand);
   commands.push_back(new cmProjectCommand);
   commands.push_back(new cmSourceFilesCommand);
   commands.push_back(new cmSourceFilesCommand);
   commands.push_back(new cmSourceFilesRequireCommand);
   commands.push_back(new cmSourceFilesRequireCommand);
@@ -74,6 +77,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
   commands.push_back(new cmWin32DefinesCommand);
   commands.push_back(new cmWin32DefinesCommand);
   commands.push_back(new cmWin32LibrariesCommand);
   commands.push_back(new cmWin32LibrariesCommand);
   commands.push_back(new cmWin32IncludeDirectoryCommand);
   commands.push_back(new cmWin32IncludeDirectoryCommand);
+  commands.push_back(new cmConfigureFile);
   commands.push_back(new cmConfigureFileNoAutoconf);
   commands.push_back(new cmConfigureFileNoAutoconf);
   commands.push_back(new cmCableDefineSetCommand);
   commands.push_back(new cmCableDefineSetCommand);
   commands.push_back(new cmCableOpenNamespaceCommand);
   commands.push_back(new cmCableOpenNamespaceCommand);

+ 5 - 5
Source/cmDSPMakefile.cxx

@@ -415,8 +415,8 @@ void cmDSPMakefile::WriteDSPHeader(std::ostream& fout, const char *libName,
     libOptions += "\" ";
     libOptions += "\" ";
     }
     }
   // find link libraries
   // find link libraries
-  cmMakefile::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
-  cmMakefile::LinkLibraries::const_iterator j;
+  const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
+  cmTarget::LinkLibraries::const_iterator j;
   for(j = libs.begin(); j != libs.end(); ++j)
   for(j = libs.begin(); j != libs.end(); ++j)
     {
     {
     // add libraries to executables and dlls (but never include
     // add libraries to executables and dlls (but never include
@@ -424,19 +424,19 @@ void cmDSPMakefile::WriteDSPHeader(std::ostream& fout, const char *libName,
     if (!target.IsALibrary() || 
     if (!target.IsALibrary() || 
         (m_LibraryBuildType == DLL && libName != j->first))
         (m_LibraryBuildType == DLL && libName != j->first))
       {
       {
-      if (j->second == cmMakefile::GENERAL)
+      if (j->second == cmTarget::GENERAL)
         {
         {
         libOptions += " ";
         libOptions += " ";
         libOptions += j->first;
         libOptions += j->first;
         libOptions += ".lib ";
         libOptions += ".lib ";
         }
         }
-      if (j->second == cmMakefile::DEBUG)
+      if (j->second == cmTarget::DEBUG)
         {
         {
         libDebugOptions += " ";
         libDebugOptions += " ";
         libDebugOptions += j->first;
         libDebugOptions += j->first;
         libDebugOptions += ".lib ";
         libDebugOptions += ".lib ";
         }
         }
-      if (j->second == cmMakefile::OPTIMIZED)
+      if (j->second == cmTarget::OPTIMIZED)
         {
         {
         libOptimizedOptions += " ";
         libOptimizedOptions += " ";
         libOptimizedOptions += j->first;
         libOptimizedOptions += j->first;

+ 5 - 5
Source/cmDSPWriter.cxx

@@ -415,8 +415,8 @@ void cmDSPMakefile::WriteDSPHeader(std::ostream& fout, const char *libName,
     libOptions += "\" ";
     libOptions += "\" ";
     }
     }
   // find link libraries
   // find link libraries
-  cmMakefile::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
-  cmMakefile::LinkLibraries::const_iterator j;
+  const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
+  cmTarget::LinkLibraries::const_iterator j;
   for(j = libs.begin(); j != libs.end(); ++j)
   for(j = libs.begin(); j != libs.end(); ++j)
     {
     {
     // add libraries to executables and dlls (but never include
     // add libraries to executables and dlls (but never include
@@ -424,19 +424,19 @@ void cmDSPMakefile::WriteDSPHeader(std::ostream& fout, const char *libName,
     if (!target.IsALibrary() || 
     if (!target.IsALibrary() || 
         (m_LibraryBuildType == DLL && libName != j->first))
         (m_LibraryBuildType == DLL && libName != j->first))
       {
       {
-      if (j->second == cmMakefile::GENERAL)
+      if (j->second == cmTarget::GENERAL)
         {
         {
         libOptions += " ";
         libOptions += " ";
         libOptions += j->first;
         libOptions += j->first;
         libOptions += ".lib ";
         libOptions += ".lib ";
         }
         }
-      if (j->second == cmMakefile::DEBUG)
+      if (j->second == cmTarget::DEBUG)
         {
         {
         libDebugOptions += " ";
         libDebugOptions += " ";
         libDebugOptions += j->first;
         libDebugOptions += j->first;
         libDebugOptions += ".lib ";
         libDebugOptions += ".lib ";
         }
         }
-      if (j->second == cmMakefile::OPTIMIZED)
+      if (j->second == cmTarget::OPTIMIZED)
         {
         {
         libOptimizedOptions += " ";
         libOptimizedOptions += " ";
         libOptimizedOptions += j->first;
         libOptimizedOptions += j->first;

+ 13 - 6
Source/cmDSWMakefile.cxx

@@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 #include "cmDSPMakefile.h"
 #include "cmDSPMakefile.h"
 #include "cmMSProjectGenerator.h"
 #include "cmMSProjectGenerator.h"
+#include "cmCacheManager.h"
 
 
 
 
 cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
 cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
@@ -151,9 +152,9 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
   fout << "{{{\n";
   fout << "{{{\n";
 
 
   // insert Begin Project Dependency  Project_Dep_Name project stuff here 
   // insert Begin Project Dependency  Project_Dep_Name project stuff here 
-  cmMakefile::LinkLibraries::const_iterator j, jend;
-  j = project->GetMakefile()->GetLinkLibraries().begin();
-  jend = project->GetMakefile()->GetLinkLibraries().end();
+  cmTarget::LinkLibraries::const_iterator j, jend;
+  j = l.GetLinkLibraries().begin();
+  jend = l.GetLinkLibraries().end();
   for(;j!= jend; ++j)
   for(;j!= jend; ++j)
     {
     {
     if(j->first != dspname)
     if(j->first != dspname)
@@ -161,9 +162,15 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
       if (!l.IsALibrary() || 
       if (!l.IsALibrary() || 
           project->GetLibraryBuildType() == cmDSPMakefile::DLL)
           project->GetLibraryBuildType() == cmDSPMakefile::DLL)
         {
         {
-        fout << "Begin Project Dependency\n";
-        fout << "Project_Dep_Name " << j->first << "\n";
-        fout << "End Project Dependency\n";
+        // is the library part of this DSW ? If so add dependency
+        const char* cacheValue
+          = cmCacheManager::GetInstance()->GetCacheValue(j->first.c_str());
+        if(cacheValue)
+          {
+          fout << "Begin Project Dependency\n";
+          fout << "Project_Dep_Name " << j->first << "\n";
+          fout << "End Project Dependency\n";
+          }
         }
         }
       }
       }
     }
     }

+ 13 - 6
Source/cmDSWWriter.cxx

@@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 #include "cmDSPMakefile.h"
 #include "cmDSPMakefile.h"
 #include "cmMSProjectGenerator.h"
 #include "cmMSProjectGenerator.h"
+#include "cmCacheManager.h"
 
 
 
 
 cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
 cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
@@ -151,9 +152,9 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
   fout << "{{{\n";
   fout << "{{{\n";
 
 
   // insert Begin Project Dependency  Project_Dep_Name project stuff here 
   // insert Begin Project Dependency  Project_Dep_Name project stuff here 
-  cmMakefile::LinkLibraries::const_iterator j, jend;
-  j = project->GetMakefile()->GetLinkLibraries().begin();
-  jend = project->GetMakefile()->GetLinkLibraries().end();
+  cmTarget::LinkLibraries::const_iterator j, jend;
+  j = l.GetLinkLibraries().begin();
+  jend = l.GetLinkLibraries().end();
   for(;j!= jend; ++j)
   for(;j!= jend; ++j)
     {
     {
     if(j->first != dspname)
     if(j->first != dspname)
@@ -161,9 +162,15 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
       if (!l.IsALibrary() || 
       if (!l.IsALibrary() || 
           project->GetLibraryBuildType() == cmDSPMakefile::DLL)
           project->GetLibraryBuildType() == cmDSPMakefile::DLL)
         {
         {
-        fout << "Begin Project Dependency\n";
-        fout << "Project_Dep_Name " << j->first << "\n";
-        fout << "End Project Dependency\n";
+        // is the library part of this DSW ? If so add dependency
+        const char* cacheValue
+          = cmCacheManager::GetInstance()->GetCacheValue(j->first.c_str());
+        if(cacheValue)
+          {
+          fout << "Begin Project Dependency\n";
+          fout << "Project_Dep_Name " << j->first << "\n";
+          fout << "End Project Dependency\n";
+          }
         }
         }
       }
       }
     }
     }

+ 4 - 5
Source/cmFindIncludeCommand.cxx

@@ -44,11 +44,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // cmFindIncludeCommand
 // cmFindIncludeCommand
 bool cmFindIncludeCommand::Invoke(std::vector<std::string>& args)
 bool cmFindIncludeCommand::Invoke(std::vector<std::string>& args)
 {
 {
-  if(args.size() < 2 )
-    {
-    this->SetError("called with incorrect number of arguments");
-    return false;
-    }
+  this->SetError("This has been deprecated, please use FIND_PATH command instead ");
+  return false;
+  
+  
   // Now check and see if the value has been stored in the cache
   // Now check and see if the value has been stored in the cache
   // already, if so use that value and don't look for the program
   // already, if so use that value and don't look for the program
   const char* cacheValue
   const char* cacheValue

+ 1 - 1
Source/cmFindLibraryCommand.cxx

@@ -132,6 +132,6 @@ bool cmFindLibraryCommand::Invoke(std::vector<std::string>& args)
                                                "NOTFOUND",
                                                "NOTFOUND",
                                                helpString.c_str(),
                                                helpString.c_str(),
                                                cmCacheManager::PATH);
                                                cmCacheManager::PATH);
-  return false;
+  return true;
 }
 }
 
 

+ 2 - 2
Source/cmLinkLibrariesCommand.cxx

@@ -57,13 +57,13 @@ bool cmLinkLibrariesCommand::Invoke(std::vector<std::string>& args)
       {
       {
       ++i;
       ++i;
       m_Makefile->AddLinkLibrary(i->c_str(),
       m_Makefile->AddLinkLibrary(i->c_str(),
-                                 cmMakefile::DEBUG);
+                                 cmTarget::DEBUG);
       }
       }
     else if (*i == "optimized")
     else if (*i == "optimized")
       {
       {
       ++i;
       ++i;
       m_Makefile->AddLinkLibrary(i->c_str(),
       m_Makefile->AddLinkLibrary(i->c_str(),
-                                 cmMakefile::OPTIMIZED);
+                                 cmTarget::OPTIMIZED);
       }
       }
     else
     else
       {
       {

+ 1 - 2
Source/cmLinkLibrariesCommand.h

@@ -98,8 +98,7 @@ public:
       "LINK_LIBRARIES(library1 <debug | optimized> library2 ...)\n"
       "LINK_LIBRARIES(library1 <debug | optimized> library2 ...)\n"
       "Specify a list of libraries to be linked into\n"
       "Specify a list of libraries to be linked into\n"
       "executables or shared objects.  This command is passed\n"
       "executables or shared objects.  This command is passed\n"
-      "down to all other commands. The library name should be\n"
-      "the same as the name used in the LIBRARY(library) command.\n"
+      "down to all other commands. \n"
       "The debug and optimized strings may be used to indicate that\n"
       "The debug and optimized strings may be used to indicate that\n"
       "the next library listed is to be used only for that specific\n"
       "the next library listed is to be used only for that specific\n"
       "type of build";
       "type of build";

+ 90 - 4
Source/cmMakefile.cxx

@@ -83,8 +83,39 @@ void cmMakefile::AddDefaultCommands()
 #if defined(__CYGWIN__)
 #if defined(__CYGWIN__)
   this->AddDefinition("UNIX", "1");
   this->AddDefinition("UNIX", "1");
 #endif
 #endif
+  
 }
 }
 
 
+void cmMakefile::ReadSystemConfiguration(const char *fname)
+{
+  std::ifstream fin(fname);
+  if(!fin)
+    {
+    cmSystemTools::Error("error can not open file ", fname);
+    return;
+    }
+
+  cmRegularExpression aDef("^Define[ \t]*([A-Za-z_0-9]*)[ \t]*([A-Za-z_0-9]*)[ \t]*$");  
+  const int BUFFER_SIZE = 4096;
+  char inbuffer[BUFFER_SIZE];
+  while (fin)
+    {
+    if(fin.getline(inbuffer, BUFFER_SIZE ) )
+      {
+      if(aDef.find(inbuffer))
+        {
+        // the arguments are the second match
+        std::string def = aDef.match(1);
+        std::string val = aDef.match(2);
+        // add the definition if true
+        if (cmSystemTools::IsOn(val.c_str()))
+          {
+          this->AddDefinition(def.c_str(),val.c_str());
+          }
+        }
+      }
+    }
+}
 
 
 cmMakefile::~cmMakefile()
 cmMakefile::~cmMakefile()
 {
 {
@@ -309,6 +340,12 @@ void cmMakefile::GenerateMakefile()
     {
     {
     (*i)->FinalPass();
     (*i)->FinalPass();
     }
     }
+  // merge libraries
+  for (cmTargets::iterator l = m_Targets.begin();
+       l != m_Targets.end(); l++)
+    {
+    l->second.MergeLibraries(m_LinkLibraries);
+    }
   // now do the generation
   // now do the generation
   m_MakefileGenerator->GenerateMakefile();
   m_MakefileGenerator->GenerateMakefile();
 }
 }
@@ -359,15 +396,27 @@ void cmMakefile::AddUtilityDirectory(const char* dir)
   m_UtilityDirectories.push_back(dir);
   m_UtilityDirectories.push_back(dir);
 }
 }
 
 
-void cmMakefile::AddLinkLibrary(const char* lib, LinkLibraryType llt)
+void cmMakefile::AddLinkLibrary(const char* lib, cmTarget::LinkLibraryType llt)
 {
 {
   m_LinkLibraries.push_back(
   m_LinkLibraries.push_back(
-    std::pair<std::string, LinkLibraryType>(lib,llt));
+	  std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt));
+}
+
+void cmMakefile::AddLinkLibraryForTarget(const char *target,
+                                         const char* lib, 
+                                         cmTarget::LinkLibraryType llt)
+{
+  if (m_Targets.find(target) != m_Targets.end())
+    {
+    m_Targets[target].GetLinkLibraries().
+      push_back(
+        std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt));
+    }
 }
 }
 
 
 void cmMakefile::AddLinkLibrary(const char* lib)
 void cmMakefile::AddLinkLibrary(const char* lib)
 {
 {
-  this->AddLinkLibrary(lib,GENERAL);
+  this->AddLinkLibrary(lib,cmTarget::GENERAL);
 }
 }
 
 
 void cmMakefile::AddLinkDirectory(const char* dir)
 void cmMakefile::AddLinkDirectory(const char* dir)
@@ -513,7 +562,7 @@ void cmMakefile::ExpandVariables()
     {
     {
     this->ExpandVariablesInString(*j);
     this->ExpandVariablesInString(*j);
     }
     }
-  LinkLibraries::iterator j2, end2;
+  cmTarget::LinkLibraries::iterator j2, end2;
   j2 = m_LinkLibraries.begin();
   j2 = m_LinkLibraries.begin();
   end2 = m_LinkLibraries.end();
   end2 = m_LinkLibraries.end();
   for(; j2 != end2; ++j2)
   for(; j2 != end2; ++j2)
@@ -581,6 +630,19 @@ void cmMakefile::ExpandVariablesInString(std::string& source) const
     }
     }
 }
 }
 
 
+void cmMakefile::RemoveVariablesInString(std::string& source) const
+{
+  cmRegularExpression var("(\\${[A-Za-z_0-9]*})");
+  cmRegularExpression var2("(@[A-Za-z_0-9]*@)");
+  while (var.find(source))
+    {
+    source.erase(var.start(),var.end());
+    }
+  while (var2.find(source))
+    {
+    source.erase(var2.start(),var2.end());
+    }
+}
 
 
 // recursive function to create a vector of cmMakefile objects
 // recursive function to create a vector of cmMakefile objects
 // This is done by reading the sub directory CMakeLists.txt files,
 // This is done by reading the sub directory CMakeLists.txt files,
@@ -774,3 +836,27 @@ void cmMakefile::RemoveFunctionBlocker(const char *name,
   
   
   return;
   return;
 }
 }
+
+void cmMakefile::SetHomeDirectory(const char* dir) 
+{
+  m_cmHomeDirectory = dir;
+  cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
+  this->AddDefinition("CMAKE_SOURCE_DIR", this->GetHomeDirectory());
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  std::string fpath = dir;
+  fpath += "/CMake/CMakeWindowsSystemConfig.txt";
+  this->ReadSystemConfiguration(fpath.c_str());
+#endif
+}
+
+void cmMakefile::SetHomeOutputDirectory(const char* lib)
+{
+  m_HomeOutputDirectory = lib;
+  cmSystemTools::ConvertToUnixSlashes(m_HomeOutputDirectory);
+  this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory());
+#if !defined(_WIN32) || defined(__CYGWIN__)
+  std::string fpath = lib;
+  fpath += "/CMakeSystemConfig.txt";
+  this->ReadSystemConfiguration(fpath.c_str());
+#endif
+}

+ 18 - 17
Source/cmMakefile.h

@@ -146,9 +146,7 @@ public:
   /**
   /**
    * Get a list of link libraries in the build.
    * Get a list of link libraries in the build.
    */
    */
-  enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED};
-  typedef std::vector<std::pair<std::string,LinkLibraryType> > LinkLibraries;
-  LinkLibraries& GetLinkLibraries()
+  cmTarget::LinkLibraries& GetLinkLibraries()
     { 
     { 
     return m_LinkLibraries;
     return m_LinkLibraries;
     }
     }
@@ -157,7 +155,9 @@ public:
    * Add a link library to the build.
    * Add a link library to the build.
    */
    */
   void AddLinkLibrary(const char*);
   void AddLinkLibrary(const char*);
-  void AddLinkLibrary(const char*, LinkLibraryType type);
+  void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
+  void AddLinkLibraryForTarget(const char *tgt, const char*, 
+                               cmTarget::LinkLibraryType type);
 
 
   /**
   /**
    * Add a link directory to the build.
    * Add a link directory to the build.
@@ -236,22 +236,12 @@ public:
    * CMakeLists files by recursing up the tree starting at the StartDirectory
    * CMakeLists files by recursing up the tree starting at the StartDirectory
    * and going up until it reaches the HomeDirectory.  
    * and going up until it reaches the HomeDirectory.  
    */
    */
-  void SetHomeDirectory(const char* dir) 
-    {
-    m_cmHomeDirectory = dir;
-    cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
-    this->AddDefinition("CMAKE_SOURCE_DIR", this->GetHomeDirectory());
-    }
+  void SetHomeDirectory(const char* dir);
   const char* GetHomeDirectory() const
   const char* GetHomeDirectory() const
     {
     {
     return m_cmHomeDirectory.c_str();
     return m_cmHomeDirectory.c_str();
     }
     }
-  void SetHomeOutputDirectory(const char* lib)
-    {
-    m_HomeOutputDirectory = lib;
-    cmSystemTools::ConvertToUnixSlashes(m_HomeOutputDirectory);
-    this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory());
-    }
+  void SetHomeOutputDirectory(const char* lib);
   const char* GetHomeOutputDirectory() const
   const char* GetHomeOutputDirectory() const
     {
     {
     return m_HomeOutputDirectory.c_str();
     return m_HomeOutputDirectory.c_str();
@@ -426,6 +416,12 @@ public:
    */
    */
   void ExpandVariablesInString(std::string& source) const;
   void ExpandVariablesInString(std::string& source) const;
 
 
+  /**
+   * Remove any remaining variables in the string. Anything with ${var} or
+   * @var@ will be removed.  
+   */
+  void RemoveVariablesInString(std::string& source) const;
+
   /**
   /**
    * Expand variables in the makefiles ivars such as link directories etc
    * Expand variables in the makefiles ivars such as link directories etc
    */
    */
@@ -445,6 +441,11 @@ public:
    */
    */
   void GenerateCacheOnly();
   void GenerateCacheOnly();
 
 
+  /**
+   * find what source group this source is in
+   */
+  void ReadSystemConfiguration(const char *fname);
+  
   /**
   /**
    * find what source group this source is in
    * find what source group this source is in
    */
    */
@@ -474,7 +475,7 @@ protected:
   std::vector<std::string> m_LinkDirectories;
   std::vector<std::string> m_LinkDirectories;
   std::vector<std::string> m_Utilities;
   std::vector<std::string> m_Utilities;
   std::vector<std::string> m_UtilityDirectories;
   std::vector<std::string> m_UtilityDirectories;
-  LinkLibraries m_LinkLibraries;
+  cmTarget::LinkLibraries m_LinkLibraries;
   std::string m_IncludeFileRegularExpression;
   std::string m_IncludeFileRegularExpression;
   std::string m_DefineFlags;
   std::string m_DefineFlags;
   std::vector<cmSourceGroup> m_SourceGroups;
   std::vector<cmSourceGroup> m_SourceGroups;

+ 15 - 0
Source/cmTarget.cxx

@@ -67,3 +67,18 @@ void cmTarget::GenerateSourceFilesFromSourceLists(const cmMakefile &mf)
       }
       }
     }
     }
 }
 }
+
+void cmTarget::MergeLibraries(const LinkLibraries &ll)
+{
+  typedef std::vector<std::pair<std::string,LinkLibraryType> > LinkLibraries;
+
+  LinkLibraries::const_iterator p = ll.begin();
+  for (;p != ll.end(); ++p)
+    {
+	  if (std::find(m_LinkLibraries.begin(),m_LinkLibraries.end(),*p) == m_LinkLibraries.end())
+      {
+      m_LinkLibraries.push_back(*p);
+      }
+    }
+}
+

+ 14 - 0
Source/cmTarget.h

@@ -81,6 +81,19 @@ public:
     {return m_SourceFiles;}
     {return m_SourceFiles;}
   std::vector<cmSourceFile> &GetSourceFiles() {return m_SourceFiles;}
   std::vector<cmSourceFile> &GetSourceFiles() {return m_SourceFiles;}
 
 
+  /**
+   * Get the list of the source files used by this target
+   */
+  enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED};
+  typedef std::vector<std::pair<std::string,LinkLibraryType> > LinkLibraries;
+  const LinkLibraries &GetLinkLibraries() const {return m_LinkLibraries;}
+  LinkLibraries &GetLinkLibraries() {return m_LinkLibraries;}
+  
+  /**
+   * Merge Link LIbraries into this targets current list 
+   */
+  void MergeLibraries(const LinkLibraries &ll);
+    
   /**
   /**
    * Generate the SourceFilesList from the SourceLists. This should only be
    * Generate the SourceFilesList from the SourceLists. This should only be
    * done once to be safe.  
    * done once to be safe.  
@@ -92,6 +105,7 @@ private:
   std::vector<std::string> m_SourceLists;
   std::vector<std::string> m_SourceLists;
   bool m_IsALibrary;
   bool m_IsALibrary;
   std::vector<cmSourceFile> m_SourceFiles;
   std::vector<cmSourceFile> m_SourceFiles;
+  LinkLibraries m_LinkLibraries;
 };
 };
 
 
 typedef std::map<std::string,cmTarget> cmTargets;
 typedef std::map<std::string,cmTarget> cmTargets;

+ 76 - 0
Source/cmTargetLinkLibrariesCommand.cxx

@@ -0,0 +1,76 @@
+/*=========================================================================
+
+  Program:   Insight Segmentation & Registration Toolkit
+  Module:    $RCSfile$
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+Copyright (c) 2001 Insight Consortium
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+ * The name of the Insight Consortium, nor the names of any consortium members,
+   nor of any contributors, may be used to endorse or promote products derived
+   from this software without specific prior written permission.
+
+  * Modified source versions must be plainly marked as such, and must not be
+    misrepresented as being the original software.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=========================================================================*/
+#include "cmTargetLinkLibrariesCommand.h"
+
+// cmTargetLinkLibrariesCommand
+bool cmTargetLinkLibrariesCommand::Invoke(std::vector<std::string>& args)
+{
+  if(args.size() < 2)
+    {
+    this->SetError("called with incorrect number of arguments");
+    return false;
+    }
+  // add libraries, nothe that there is an optional prefix 
+  // of debug and optimized than can be used
+  for(std::vector<std::string>::iterator i = args.begin();
+      i != args.end(); ++i)
+    {
+    if (*i == "debug")
+      {
+      ++i;
+      m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
+                                          cmTarget::DEBUG);
+      }
+    else if (*i == "optimized")
+      {
+      ++i;
+      m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
+                                 cmTarget::OPTIMIZED);
+      }
+    else
+      {
+      m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
+                                          cmTarget::GENERAL);  
+      }
+    }
+  return true;
+}
+

+ 104 - 0
Source/cmTargetLinkLibrariesCommand.h

@@ -0,0 +1,104 @@
+/*=========================================================================
+
+  Program:   Insight Segmentation & Registration Toolkit
+  Module:    $RCSfile$
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+Copyright (c) 2001 Insight Consortium
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+ * The name of the Insight Consortium, nor the names of any consortium members,
+   nor of any contributors, may be used to endorse or promote products derived
+   from this software without specific prior written permission.
+
+  * Modified source versions must be plainly marked as such, and must not be
+    misrepresented as being the original software.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=========================================================================*/
+#ifndef cmTargetLinkLibrariesCommand_h
+#define cmTargetLinkLibrariesCommand_h
+
+#include "cmStandardIncludes.h"
+#include "cmCommand.h"
+
+/** \class cmTargetLinkLibrariesCommand
+ * \brief Specify a list of libraries to link into executables.
+ *
+ * cmTargetLinkLibrariesCommand is used to specify a list of libraries to link
+ * into executable(s) or shared objects. The names of the libraries
+ * should be those defined by the LIBRARY(library) command(s).  
+ */
+class cmTargetLinkLibrariesCommand : public cmCommand
+{
+public:
+  /**
+   * This is a virtual constructor for the command.
+   */
+  virtual cmCommand* Clone() 
+    {
+    return new cmTargetLinkLibrariesCommand;
+    }
+
+  /**
+   * This is called when the command is first encountered in
+   * the CMakeLists.txt file.
+   */
+  virtual bool Invoke(std::vector<std::string>& args);
+
+  /**
+   * The name of the command as specified in CMakeList.txt.
+   */
+  virtual const char* GetName() { return "TARGET_LINK_LIBRARIES";}
+
+  /**
+   * Succinct documentation.
+   */
+  virtual const char* GetTerseDocumentation() 
+    {
+    return 
+      "Specify a list of libraries to be linked into\n"
+      "executables or shared objects.";
+    }
+  
+  /**
+   * More documentation.
+   */
+  virtual const char* GetFullDocumentation()
+    {
+    return
+      "TARGET_LINK_LIBRARIES(target library1 <debug | optimized> library2 ...)\n"
+      "Specify a list of libraries to be linked into the specified target\n"
+      "The debug and optimized strings may be used to indicate that\n"
+      "the next library listed is to be used only for that specific\n"
+      "type of build";
+    }
+  
+  cmTypeMacro(cmTargetLinkLibrariesCommand, cmCommand);
+};
+
+
+
+#endif

+ 9 - 8
Source/cmUnixMakefileGenerator.cxx

@@ -140,7 +140,8 @@ void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
  * to the name of the library.  This will not link a library against itself.
  * to the name of the library.  This will not link a library against itself.
  */
  */
 void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
 void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
-                                                  const char* targetLibrary)
+                                                  const char* targetLibrary,
+                                                  const cmTarget &tgt)
 {
 {
   // collect all the flags needed for linking libraries
   // collect all the flags needed for linking libraries
   std::string linkLibs;        
   std::string linkLibs;        
@@ -158,14 +159,14 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
     linkLibs += " ";
     linkLibs += " ";
     }
     }
   std::string librariesLinked;
   std::string librariesLinked;
-  cmMakefile::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
-  cmMakefile::LinkLibraries::const_iterator j2;
+  const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries();
+  cmTarget::LinkLibraries::const_iterator j2;
   for(j2 = libs.begin(); j2 != libs.end(); ++j2)
   for(j2 = libs.begin(); j2 != libs.end(); ++j2)
     {
     {
     // Don't link the library against itself!
     // Don't link the library against itself!
     if(targetLibrary && (j2->first == targetLibrary)) continue;
     if(targetLibrary && (j2->first == targetLibrary)) continue;
     // don't look at debug libraries
     // don't look at debug libraries
-    if (j2->second == cmMakefile::DEBUG) continue;
+    if (j2->second == cmTarget::DEBUG) continue;
     std::string::size_type pos = j2->first.find("-l");
     std::string::size_type pos = j2->first.find("-l");
     if((pos == std::string::npos || pos > 0)
     if((pos == std::string::npos || pos > 0)
        && j2->first.find("${") == std::string::npos)
        && j2->first.find("${") == std::string::npos)
@@ -213,7 +214,7 @@ void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
       fout << "\t  lib" << l->first << "$(SHLIB_SUFFIX) \\\n";
       fout << "\t  lib" << l->first << "$(SHLIB_SUFFIX) \\\n";
       fout << "\t  ${KIT_OBJ} ${" << l->first << 
       fout << "\t  ${KIT_OBJ} ${" << l->first << 
         "_SRC_OBJS} ";
         "_SRC_OBJS} ";
-      this->OutputLinkLibraries(fout, l->first.c_str());
+      this->OutputLinkLibraries(fout, l->first.c_str(), l->second);
       fout << "\n\n";
       fout << "\n\n";
       }
       }
     else
     else
@@ -222,7 +223,7 @@ void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
         l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
         l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
       fout << "\t${CXX}  ${CXX_FLAGS} ${" << 
       fout << "\t${CXX}  ${CXX_FLAGS} ${" << 
         l->first << "_SRC_OBJS} ";
         l->first << "_SRC_OBJS} ";
-      this->OutputLinkLibraries(fout, NULL);
+      this->OutputLinkLibraries(fout, NULL,l->second);
       fout << " -o " << l->first << "\n\n";
       fout << " -o " << l->first << "\n\n";
       }
       }
     }
     }
@@ -234,8 +235,8 @@ void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
 void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
 void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
 {
 {
   fout << "CMAKE_DEPEND_LIBS = ";
   fout << "CMAKE_DEPEND_LIBS = ";
-  cmMakefile::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
-  cmMakefile::LinkLibraries::const_iterator lib2;
+  cmTarget::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
+  cmTarget::LinkLibraries::const_iterator lib2;
   // Search the list of libraries that will be linked into
   // Search the list of libraries that will be linked into
   // the executable
   // the executable
   for(lib2 = libs.begin(); lib2 != libs.end(); ++lib2)
   for(lib2 = libs.begin(); lib2 != libs.end(); ++lib2)

+ 1 - 1
Source/cmUnixMakefileGenerator.h

@@ -70,7 +70,7 @@ protected:
   void OutputMakeFlags(std::ostream&);
   void OutputMakeFlags(std::ostream&);
   void OutputVerbatim(std::ostream&);
   void OutputVerbatim(std::ostream&);
   void OutputTargetRules(std::ostream& fout);
   void OutputTargetRules(std::ostream& fout);
-  void OutputLinkLibraries(std::ostream&, const char*);
+  void OutputLinkLibraries(std::ostream&, const char*, const cmTarget &);
   void OutputTargets(std::ostream&);
   void OutputTargets(std::ostream&);
   void OutputSubDirectoryRules(std::ostream&);
   void OutputSubDirectoryRules(std::ostream&);
   void OutputDependInformation(std::ostream&);
   void OutputDependInformation(std::ostream&);