[cmake-commits] king committed cmAddCustomTargetCommand.cxx 1.29 1.30 cmGlobalGenerator.cxx 1.225 1.226 cmGlobalGenerator.h 1.106 1.107 cmGlobalUnixMakefileGenerator3.h 1.54 1.55 cmMakefile.cxx 1.436 1.437 cmMakefile.h 1.224 1.225 cmake.cxx 1.359 1.360

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Feb 14 16:42:31 EST 2008


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

Modified Files:
	cmAddCustomTargetCommand.cxx cmGlobalGenerator.cxx 
	cmGlobalGenerator.h cmGlobalUnixMakefileGenerator3.h 
	cmMakefile.cxx cmMakefile.h cmake.cxx 
Log Message:
ENH: Add global property ALLOW_DUPLICATE_CUSTOM_TARGETS to help existing projects that depend on having duplicate custom targets.  It is allowed only for Makefile generators.  See bug#6348.


Index: cmGlobalGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalGenerator.h,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -d -r1.106 -r1.107
--- cmGlobalGenerator.h	6 Feb 2008 04:10:41 -0000	1.106
+++ cmGlobalGenerator.h	14 Feb 2008 21:42:29 -0000	1.107
@@ -258,6 +258,8 @@
   void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
   void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
 
+  virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
+
   // Fill the ProjectMap, this must be called after LocalGenerators 
   // has been populated.
   void FillProjectMap();

Index: cmAddCustomTargetCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmAddCustomTargetCommand.cxx,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- cmAddCustomTargetCommand.cxx	11 Feb 2008 22:33:46 -0000	1.29
+++ cmAddCustomTargetCommand.cxx	14 Feb 2008 21:42:29 -0000	1.30
@@ -161,7 +161,7 @@
   // Enforce name uniqueness.
   {
   std::string msg;
-  if(!this->Makefile->EnforceUniqueName(args[0], msg))
+  if(!this->Makefile->EnforceUniqueName(args[0], msg, true))
     {
     this->SetError(msg.c_str());
     return false;

Index: cmGlobalGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalGenerator.cxx,v
retrieving revision 1.225
retrieving revision 1.226
diff -u -d -r1.225 -r1.226
--- cmGlobalGenerator.cxx	6 Feb 2008 04:10:41 -0000	1.225
+++ cmGlobalGenerator.cxx	14 Feb 2008 21:42:29 -0000	1.226
@@ -733,12 +733,39 @@
     }
 }
 
+bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS()
+{
+  // If the property is not enabled then okay.
+  if(!this->CMakeInstance
+     ->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
+    {
+    return true;
+    }
+
+  // This generator does not support duplicate custom targets.
+  cmOStringStream e;
+  e << "This project has enabled the ALLOW_DUPLICATE_CUSTOM_TARGETS "
+    << "global property.  "
+    << "The \"" << this->GetName() << "\" generator does not support "
+    << "duplicate custom targets.  "
+    << "Consider using a Makefiles generator or fix the project to not "
+    << "use duplicat target names.";
+  cmSystemTools::Error(e.str().c_str());
+  return false;
+}
+
 void cmGlobalGenerator::Generate()
 {
   // Some generators track files replaced during the Generate.
   // Start with an empty vector:
   this->FilesReplacedDuringGenerate.clear();
 
+  // Check whether this generator is allowed to run.
+  if(!this->CheckALLOW_DUPLICATE_CUSTOM_TARGETS())
+    {
+    return;
+    }
+
   // For each existing cmLocalGenerator
   unsigned int i;
 

Index: cmake.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.cxx,v
retrieving revision 1.359
retrieving revision 1.360
diff -u -d -r1.359 -r1.360
--- cmake.cxx	12 Feb 2008 14:49:42 -0000	1.359
+++ cmake.cxx	14 Feb 2008 21:42:29 -0000	1.360
@@ -3322,6 +3322,25 @@
     "at the beginning of native build system generation.  "
     "This property causes it to display details of its analysis to stderr.");
 
+  cm->DefineProperty(
+    "ALLOW_DUPLICATE_CUSTOM_TARGETS", cmProperty::GLOBAL,
+    "Allow duplicate custom targets to be created.",
+    "Normally CMake requires that all targets built in a project have "
+    "globally unique names.  "
+    "This is necessary to generate meaningful project file names in "
+    "Xcode and VS IDE generators.  "
+    "It also allows the target names to be referenced unambiguously.\n"
+    "Makefile generators are capable of supporting duplicate custom target "
+    "names.  "
+    "For projects that care only about Makefile generators and do "
+    "not wish to support Xcode or VS IDE generators, one may set this "
+    "property to true to allow duplicate custom targets.  "
+    "The property allows multiple add_custom_target command calls in "
+    "*different directories* to specify the same target name.  "
+    "However, setting this property will cause non-Makefile generators "
+    "to produce an error and refuse to generate the project."
+    );
+
   cm->DefineProperty
     ("IN_TRY_COMPILE", cmProperty::GLOBAL,
      "Read-only property that is true during a try-compile configuration.",

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.224
retrieving revision 1.225
diff -u -d -r1.224 -r1.225
--- cmMakefile.h	11 Feb 2008 18:35:39 -0000	1.224
+++ cmMakefile.h	14 Feb 2008 21:42:29 -0000	1.225
@@ -132,7 +132,8 @@
   /**
    * Help enforce global target name uniqueness.
    */
-  bool EnforceUniqueName(std::string const& name, std::string& msg);
+  bool EnforceUniqueName(std::string const& name, std::string& msg,
+                         bool isCustom = false);
 
   /**
    * Perform FinalPass, Library dependency analysis etc before output of the

Index: cmGlobalUnixMakefileGenerator3.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalUnixMakefileGenerator3.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- cmGlobalUnixMakefileGenerator3.h	31 Jan 2008 03:56:34 -0000	1.54
+++ cmGlobalUnixMakefileGenerator3.h	14 Feb 2008 21:42:29 -0000	1.55
@@ -162,6 +162,8 @@
   virtual const char* GetRebuildCacheTargetName() { return "rebuild_cache"; }
   virtual const char* GetCleanTargetName()        { return "clean"; }
 
+  virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
+
   // Some make programs (Borland) do not keep a rule if there are no
   // dependencies or commands.  This is a problem for creating rules
   // that might not do anything but might have other dependencies

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.436
retrieving revision 1.437
diff -u -d -r1.436 -r1.437
--- cmMakefile.cxx	14 Feb 2008 16:58:32 -0000	1.436
+++ cmMakefile.cxx	14 Feb 2008 21:42:29 -0000	1.437
@@ -3140,7 +3140,8 @@
 }
 
 //----------------------------------------------------------------------------
-bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg)
+bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
+                                   bool isCustom)
 {
   if(cmTarget* existing = this->FindTargetToUse(name.c_str()))
     {
@@ -3158,21 +3159,76 @@
       }
     else if(!this->NeedBackwardsCompatibility(2, 4))
       {
-      // The conflict is with a non-imported target.  Produce an error
-      // that tells the user how to work around the problem.
+      // The conflict is with a non-imported target.
+      // Allow this if the user has requested support.
+      cmake* cm =
+        this->LocalGenerator->GetGlobalGenerator()->GetCMakeInstance();
+      if(isCustom && existing->GetType() == cmTarget::UTILITY &&
+         this != existing->GetMakefile() &&
+         cm->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
+        {
+        return true;
+        }
+
+      // Produce an error that tells the user how to work around the
+      // problem.
       cmOStringStream e;
       e << "cannot create target \"" << name
         << "\" because another target with the same name already exists.  "
-        << "Logical target names must be globally unique.  "
-        << "For executables and libraries, consider using the OUTPUT_NAME "
-        << "target property to create two targets with the same physical "
-        << "name while keeping logical names distinct.  "
-        << "Custom targets must simply have globally unique names.\n"
-        << "If you are building an older project it is possible that "
-        << "it violated this rule but was working accidentally.  "
-        << "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.4 or lower to disable "
-        << "this error.";
-      msg = e.str();
+        << "The existing target is ";
+      switch(existing->GetType())
+        {
+        case cmTarget::EXECUTABLE:
+          e << "an executable ";
+          break;
+        case cmTarget::STATIC_LIBRARY:
+          e << "a static library ";
+          break;
+        case cmTarget::SHARED_LIBRARY:
+          e << "a shared library ";
+          break;
+        case cmTarget::MODULE_LIBRARY:
+          e << "a module library ";
+          break;
+        case cmTarget::UTILITY:
+          e << "a custom target ";
+          break;
+        default: break;
+        }
+      e << "created in source directory \""
+        << existing->GetMakefile()->GetCurrentDirectory() << "\".\n"
+        << "\n";
+      e <<
+        "Logical target names must be globally unique because:\n"
+        "  - Unique names may be referenced unambiguously both in CMake\n"
+        "    code and on make tool command lines.\n"
+        "  - Logical names are used by Xcode and VS IDE generators\n"
+        "    to produce meaningful project names for the targets.\n"
+        "The logical name of executable and library targets does not "
+        "have to correspond to the physical file names built.  "
+        "Consider using the OUTPUT_NAME target property to create two "
+        "targets with the same physical name while keeping logical "
+        "names distinct.  "
+        "Custom targets must simply have globally unique names.\n"
+        "\n"
+        "If you are building an older project it is possible that "
+        "it violated this rule but was working accidentally because "
+        "CMake did not previously diagnose this problem.  "
+        "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.4 or lower to disable "
+        "this error.\n";
+      if(isCustom && existing->GetType() == cmTarget::UTILITY)
+        {
+        e <<
+          "\n"
+          "For projects that care only about Makefile generators and do "
+          "not wish to support Xcode or VS IDE generators, one may add\n"
+          "  set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)\n"
+          "to the top of the project to allow duplicate custom targets "
+          "(target names must still be unique within each directory).  "
+          "However, setting this property will cause non-Makefile generators "
+          "to produce an error and refuse to generate the project.";
+        }
+        msg = e.str();
       return false;
       }
     }



More information about the Cmake-commits mailing list