[cmake-commits] alex committed cmAddLibraryCommand.cxx 1.29 1.30 cmAddLibraryCommand.h 1.17 1.18 cmCPluginAPI.cxx 1.39 1.40 cmMakefile.cxx 1.398 1.399 cmMakefile.h 1.210 1.211

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Jun 22 09:58:12 EDT 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv3463

Modified Files:
	cmAddLibraryCommand.cxx cmAddLibraryCommand.h cmCPluginAPI.cxx 
	cmMakefile.cxx cmMakefile.h 
Log Message:

ENH: add IMPORT keyword to ADD_LIBRARY, dependencies are not yet working
STYLE: fix line lengths and indentation, use enum as argument to AddLibrary() instead of int (which was initialized from a bool in some cases)

Alex


Index: cmAddLibraryCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmAddLibraryCommand.cxx,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- cmAddLibraryCommand.cxx	21 Jun 2007 20:23:54 -0000	1.29
+++ cmAddLibraryCommand.cxx	22 Jun 2007 13:58:10 -0000	1.30
@@ -26,62 +26,62 @@
     }
   // Library type defaults to value of BUILD_SHARED_LIBS, if it exists,
   // otherwise it defaults to static library.
-  int shared = 
-    !cmSystemTools::IsOff(this->Makefile->GetDefinition("BUILD_SHARED_LIBS"));
+  cmTarget::TargetType type = cmTarget::SHARED_LIBRARY;
+  if (cmSystemTools::IsOff(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
+    {
+    type = cmTarget::STATIC_LIBRARY;
+    }
   bool excludeFromAll = false;
+  bool importTarget = false;
   
   std::vector<std::string>::const_iterator s = args.begin();
 
-  this->LibName = *s;
+  std::string libName = *s;
 
   ++s;
   
   // If the second argument is "SHARED" or "STATIC", then it controls
   // the type of library.  Otherwise, it is treated as a source or
-  // source list name. There man be two keyword arguments, check for them
+  // source list name. There may be two keyword arguments, check for them
   while ( s != args.end() )
     {
     std::string libType = *s;
     if(libType == "STATIC")
       {
       ++s;
-      shared = 0;
+      type = cmTarget::STATIC_LIBRARY;
       }
     else if(libType == "SHARED")
       {
       ++s;
-      shared = 1;
+      type = cmTarget::SHARED_LIBRARY;
       }
     else if(libType == "MODULE")
       {
       ++s;
-      shared = 2;
+      type = cmTarget::MODULE_LIBRARY;
       }
     else if(*s == "EXCLUDE_FROM_ALL")
       {
       ++s;
       excludeFromAll = true;
       }
+    else if(*s == "IMPORT")
+      {
+      ++s;
+      importTarget = true;
+      }
     else
       {
       break;
       }
     }
 
-  if (s == args.end())
-    {
-    std::string msg = "You have called ADD_LIBRARY for library ";
-    msg += args[0];
-    msg += " without any source files. This typically indicates a problem ";
-    msg += "with your CMakeLists.txt file";
-    cmSystemTools::Message(msg.c_str() ,"Warning");
-    }
-
   /* ideally we should check whether for the linker language of the target 
     CMAKE_${LANG}_CREATE_SHARED_LIBRARY is defined and if not default to
     STATIC. But at this point we know only the name of the target, but not 
     yet its linker language. */
-  if ((shared != 0) && 
+  if ((type != cmTarget::STATIC_LIBRARY) && 
        (this->Makefile->IsOn("CMAKE_TARGET_SUPPORTS_ONLY_STATIC_LIBS")))
     {
     std::string msg = "ADD_LIBRARY for library ";
@@ -90,7 +90,22 @@
         "platform supports only STATIC libraries. Building it STATIC instead. "
         "This may lead to problems.";
     cmSystemTools::Message(msg.c_str() ,"Warning");
-    shared = 0;
+    type = cmTarget::STATIC_LIBRARY;
+    }
+
+  if (importTarget)
+    {
+    this->Makefile->AddNewTarget(type, libName.c_str(), true);
+    return true;
+    }
+
+  if (s == args.end())
+    {
+    std::string msg = "You have called ADD_LIBRARY for library ";
+    msg += args[0];
+    msg += " without any source files. This typically indicates a problem ";
+    msg += "with your CMakeLists.txt file";
+    cmSystemTools::Message(msg.c_str() ,"Warning");
     }
 
   std::vector<std::string> srclists;
@@ -100,7 +115,7 @@
     ++s;
     }
 
-  this->Makefile->AddLibrary(this->LibName.c_str(), shared, srclists,
+  this->Makefile->AddLibrary(libName.c_str(), type, srclists,
                              excludeFromAll);
   
   return true;

Index: cmAddLibraryCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmAddLibraryCommand.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cmAddLibraryCommand.h	2 Oct 2006 16:01:19 -0000	1.17
+++ cmAddLibraryCommand.h	22 Jun 2007 13:58:10 -0000	1.18
@@ -76,9 +76,6 @@
     }
   
   cmTypeMacro(cmAddLibraryCommand, cmCommand);
-
-private:
-  std::string LibName;
 };
 
 

Index: cmCPluginAPI.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCPluginAPI.cxx,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- cmCPluginAPI.cxx	19 Jun 2007 13:18:22 -0000	1.39
+++ cmCPluginAPI.cxx	22 Jun 2007 13:58:10 -0000	1.40
@@ -394,7 +394,9 @@
     {
     srcs2.push_back(srcs[i]);
     }
-  mf->AddLibrary(libname, (shared ? true : false), srcs2);
+  mf->AddLibrary(libname, 
+                 (shared? cmTarget::SHARED_LIBRARY : cmTarget::STATIC_LIBRARY),
+                  srcs2);
 }
 
 char CCONV *cmExpandVariablesInString(void *arg, const char *source,

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.210
retrieving revision 1.211
diff -u -d -r1.210 -r1.211
--- cmMakefile.h	21 Jun 2007 03:01:36 -0000	1.210
+++ cmMakefile.h	22 Jun 2007 13:58:10 -0000	1.211
@@ -283,7 +283,7 @@
   /**
    * Set the name of the library.
    */
-  void AddLibrary(const char *libname, int shared,
+  void AddLibrary(const char *libname, cmTarget::TargetType type,
                   const std::vector<std::string> &srcs,
                   bool excludeFromAll = false);
 

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.398
retrieving revision 1.399
diff -u -d -r1.398 -r1.399
--- cmMakefile.cxx	18 Jun 2007 15:59:23 -0000	1.398
+++ cmMakefile.cxx	22 Jun 2007 13:58:10 -0000	1.399
@@ -1336,26 +1336,19 @@
 }
 
 
-void cmMakefile::AddLibrary(const char* lname, int shared,
+void cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type,
                             const std::vector<std::string> &srcs,
                             bool excludeFromAll)
 {
-  cmTarget* target=0;
-  switch (shared)
+  // wrong type ? default to STATIC
+  if (    (type != cmTarget::STATIC_LIBRARY) 
+       && (type != cmTarget::SHARED_LIBRARY) 
+       && (type != cmTarget::MODULE_LIBRARY))
     {
-    case 0:
-      target=this->AddNewTarget(cmTarget::STATIC_LIBRARY, lname, false);
-      break;
-    case 1:
-      target=this->AddNewTarget(cmTarget::SHARED_LIBRARY, lname, false);
-      break;
-    case 2:
-      target=this->AddNewTarget(cmTarget::MODULE_LIBRARY, lname, false);
-      break;
-    default:
-      target=this->AddNewTarget(cmTarget::STATIC_LIBRARY, lname, false);
+    type = cmTarget::STATIC_LIBRARY;
     }
 
+  cmTarget* target = this->AddNewTarget(type, lname, false);
   // Clear its dependencies. Otherwise, dependencies might persist
   // over changes in CMakeLists.txt, making the information stale and
   // hence useless.
@@ -1383,21 +1376,25 @@
 }
 
 
-cmTarget* cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name, bool isImported)
+cmTarget* cmMakefile::AddNewTarget(cmTarget::TargetType type, 
+                                   const char* name, 
+                                   bool isImported)
 {
   cmTargets::iterator it;
   cmTarget target;
   target.SetType(type, name);
   target.SetMakefile(this);
   if (isImported)
-  {
+    {
     target.MarkAsImported();
-    it=this->ImportedTargets.insert(cmTargets::value_type(target.GetName(), target)).first;
-  }
+    it=this->ImportedTargets.insert(
+                        cmTargets::value_type(target.GetName(), target)).first;
+    }
   else
-  {
-    it=this->Targets.insert(cmTargets::value_type(target.GetName(), target)).first;
-  }
+    {
+    it=this->Targets.insert(
+                        cmTargets::value_type(target.GetName(), target)).first;
+    }
   this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
   return &it->second;
 }



More information about the Cmake-commits mailing list