[cmake-commits] king committed cmAddDefinitionsCommand.h 1.12 1.13 cmGlobalXCodeGenerator.cxx 1.178 1.179 cmLocalGenerator.cxx 1.253 1.254 cmLocalGenerator.h 1.96 1.97 cmLocalVisualStudio6Generator.cxx 1.136 1.137 cmLocalVisualStudio7Generator.cxx 1.212 1.213 cmMakefile.cxx 1.424 1.425 cmMakefile.h 1.218 1.219 cmMakefileTargetGenerator.cxx 1.85 1.86 cmRemoveDefinitionsCommand.h 1.5 1.6

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Jan 17 19:29:46 EST 2008


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

Modified Files:
	cmAddDefinitionsCommand.h cmGlobalXCodeGenerator.cxx 
	cmLocalGenerator.cxx cmLocalGenerator.h 
	cmLocalVisualStudio6Generator.cxx 
	cmLocalVisualStudio7Generator.cxx cmMakefile.cxx cmMakefile.h 
	cmMakefileTargetGenerator.cxx cmRemoveDefinitionsCommand.h 
Log Message:
ENH: Converted cmMakefile DefineFlags added by ADD_DEFINITIONS command into a COMPILE_DEFINITIONS directory property.


Index: cmLocalVisualStudio7Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.cxx,v
retrieving revision 1.212
retrieving revision 1.213
diff -u -d -r1.212 -r1.213
--- cmLocalVisualStudio7Generator.cxx	16 Jan 2008 02:02:00 -0000	1.212
+++ cmLocalVisualStudio7Generator.cxx	18 Jan 2008 00:29:43 -0000	1.213
@@ -532,7 +532,10 @@
   targetOptions.FixExceptionHandlingDefault();
   targetOptions.Parse(flags.c_str());
   targetOptions.Parse(defineFlags.c_str());
+  targetOptions.AddDefines
+    (this->Makefile->GetProperty("COMPILE_DEFINITIONS"));
   targetOptions.AddDefines(target.GetProperty("COMPILE_DEFINITIONS"));
+  targetOptions.AddDefines(this->Makefile->GetProperty(defPropName.c_str()));
   targetOptions.AddDefines(target.GetProperty(defPropName.c_str()));
   targetOptions.SetVerboseMakefile(
     this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));

Index: cmLocalGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.h,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- cmLocalGenerator.h	17 Jan 2008 15:00:19 -0000	1.96
+++ cmLocalGenerator.h	18 Jan 2008 00:29:43 -0000	1.97
@@ -278,7 +278,6 @@
                                   unsigned int minor,
                                   unsigned int patch = 0xFFu);
 protected:
-  void FixDefineFlags(std::string& defineFlags, const char* lang);
   /** Construct a comment for a custom command.  */
   std::string ConstructComment(const cmCustomCommand& cc,
                                const char* default_comment = "");

Index: cmLocalGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.cxx,v
retrieving revision 1.253
retrieving revision 1.254
diff -u -d -r1.253 -r1.254
--- cmLocalGenerator.cxx	17 Jan 2008 17:44:59 -0000	1.253
+++ cmLocalGenerator.cxx	18 Jan 2008 00:29:43 -0000	1.254
@@ -1179,7 +1179,6 @@
     flags[flags.size()-1] = ' ';
     }
   std::string defineFlags = this->Makefile->GetDefineFlags();
-  this->FixDefineFlags(defineFlags, lang);
   flags += defineFlags;
   this->LanguageToIncludeFlags[lang] = flags;
 
@@ -1190,40 +1189,6 @@
 }
 
 //----------------------------------------------------------------------------
-void cmLocalGenerator::FixDefineFlags(std::string& flags, 
-                                      const char* lang)
-{
-  std::string defineFlagVar = "CMAKE_";
-  defineFlagVar += lang;
-  defineFlagVar += "_DEFINE_FLAG";
-  std::string defineFlag = 
-    this->Makefile->GetSafeDefinition(defineFlagVar.c_str());
-  if(defineFlag.size() == 0)
-    {
-    return;
-    }
-  std::vector<std::string> args;
-  cmSystemTools::ParseWindowsCommandLine(flags.c_str(), args);
-  std::string fixedFlags;
-  const char* sep = 0;
-  for(std::vector<std::string>::iterator i = args.begin();
-      i != args.end(); ++i)
-    {
-    if(sep)
-      {
-      fixedFlags += sep;
-      }
-    else
-      {
-      sep = " ";
-      }
-    cmSystemTools::ReplaceString(*i, "-D", defineFlag.c_str());
-    fixedFlags += *i;
-    }
-  flags = fixedFlags;
-}
-
-//----------------------------------------------------------------------------
 void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
                                              bool filter_system_dirs)
 {

Index: cmGlobalXCodeGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalXCodeGenerator.cxx,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -d -r1.178 -r1.179
--- cmGlobalXCodeGenerator.cxx	16 Jan 2008 02:02:00 -0000	1.178
+++ cmGlobalXCodeGenerator.cxx	18 Jan 2008 00:29:43 -0000	1.179
@@ -1300,11 +1300,15 @@
     // Add the export symbol definition for shared library objects.
     this->AppendDefines(ppDefs, exportMacro);
     }
+  this->AppendDefines
+    (ppDefs, this->CurrentMakefile->GetProperty("COMPILE_DEFINITIONS"));
   this->AppendDefines(ppDefs, target.GetProperty("COMPILE_DEFINITIONS"));
   if(configName)
     {
     std::string defVarName = "COMPILE_DEFINITIONS_";
     defVarName += cmSystemTools::UpperCase(configName);
+    this->AppendDefines
+      (ppDefs, this->CurrentMakefile->GetProperty(defVarName.c_str()));
     this->AppendDefines(ppDefs, target.GetProperty(defVarName.c_str()));
     }
   buildSettings->AddAttribute

Index: cmLocalVisualStudio6Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio6Generator.cxx,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -d -r1.136 -r1.137
--- cmLocalVisualStudio6Generator.cxx	17 Jan 2008 15:00:19 -0000	1.136
+++ cmLocalVisualStudio6Generator.cxx	18 Jan 2008 00:29:43 -0000	1.137
@@ -1503,16 +1503,30 @@
       }
 
     // Add per-target and per-configuration preprocessor definitions.
+    this->AppendDefines
+      (flags, this->Makefile->GetProperty("COMPILE_DEFINITIONS"), 0);
     this->AppendDefines(flags, target.GetProperty("COMPILE_DEFINITIONS"), 0);
+    this->AppendDefines
+      (flagsDebug,
+       this->Makefile->GetProperty("COMPILE_DEFINITIONS_DEBUG"), 0);
     this->AppendDefines(flagsDebug,
                         target.GetProperty("COMPILE_DEFINITIONS_DEBUG"), 0);
+    this->AppendDefines
+      (flagsRelease,
+       this->Makefile->GetProperty("COMPILE_DEFINITIONS_RELEASE"), 0);
     this->AppendDefines(flagsRelease,
                         target.GetProperty("COMPILE_DEFINITIONS_RELEASE"), 0);
     this->AppendDefines
       (flagsMinSize,
+       this->Makefile->GetProperty("COMPILE_DEFINITIONS_MINSIZEREL"), 0);
+    this->AppendDefines
+      (flagsMinSize,
        target.GetProperty("COMPILE_DEFINITIONS_MINSIZEREL"), 0);
     this->AppendDefines
       (flagsDebugRel,
+       this->Makefile->GetProperty("COMPILE_DEFINITIONS_RELWITHDEBINFO"), 0);
+    this->AppendDefines
+      (flagsDebugRel,
        target.GetProperty("COMPILE_DEFINITIONS_RELWITHDEBINFO"), 0);
 
     // The template files have CXX FLAGS in them, that need to be replaced.

Index: cmRemoveDefinitionsCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmRemoveDefinitionsCommand.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cmRemoveDefinitionsCommand.h	10 Oct 2007 15:47:43 -0000	1.5
+++ cmRemoveDefinitionsCommand.h	18 Jan 2008 00:29:43 -0000	1.6
@@ -53,8 +53,7 @@
    */
   virtual const char* GetTerseDocumentation() 
     {
-    return 
-      "Removes -D define flags to the command line of C and C++ compilers.";
+    return "Removes -D define flags added by add_definitions.";
     }
   
   /**
@@ -64,10 +63,8 @@
     {
     return
       "  remove_definitions(-DFOO -DBAR ...)\n"
-      "Removes flags from command line of C and C++ compilers.  "
-      "This command can be used to remove any flag from a compile line, "
-      "but the -D flag is accepted by most C/C++ compilers.  "
-      "Other flags may not be as portable.";
+      "Removes flags (added by add_definitions) from the compiler command "
+      "line for sources in the current directory and below.";
     }
   
   cmTypeMacro(cmRemoveDefinitionsCommand, cmCommand);

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -d -r1.218 -r1.219
--- cmMakefile.h	17 Jan 2008 23:13:55 -0000	1.218
+++ cmMakefile.h	18 Jan 2008 00:29:43 -0000	1.219
@@ -801,6 +801,8 @@
 private:
   void Initialize();
 
+  bool ParseDefineFlag(std::string const& definition, bool remove);
+
   void ReadSources(std::ifstream& fin, bool t);
   friend class cmMakeDepend;    // make depend needs direct access
                                 // to the Sources array 

Index: cmMakefileTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefileTargetGenerator.cxx,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- cmMakefileTargetGenerator.cxx	17 Jan 2008 15:00:19 -0000	1.85
+++ cmMakefileTargetGenerator.cxx	18 Jan 2008 00:29:43 -0000	1.86
@@ -267,11 +267,15 @@
 
     // Add preprocessor definitions for this target and configuration.
     this->LocalGenerator->AppendDefines
+      (defines, this->Makefile->GetProperty("COMPILE_DEFINITIONS"), lang);
+    this->LocalGenerator->AppendDefines
       (defines, this->Target->GetProperty("COMPILE_DEFINITIONS"), lang);
     std::string defPropName = "COMPILE_DEFINITIONS_";
     defPropName +=
       cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName);
     this->LocalGenerator->AppendDefines
+      (defines, this->Makefile->GetProperty(defPropName.c_str()), lang);
+    this->LocalGenerator->AppendDefines
       (defines, this->Target->GetProperty(defPropName.c_str()), lang);
 
     // Add language-specific flags.

Index: cmAddDefinitionsCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmAddDefinitionsCommand.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- cmAddDefinitionsCommand.h	10 Oct 2007 15:47:43 -0000	1.12
+++ cmAddDefinitionsCommand.h	18 Jan 2008 00:29:43 -0000	1.13
@@ -52,7 +52,7 @@
    */
   virtual const char* GetTerseDocumentation()
     {
-    return "Adds -D define flags to the command line of C and C++ compilers.";
+    return "Adds -D define flags to the compilation of source files.";
     }
 
   /**
@@ -62,13 +62,23 @@
     {
     return
       "  add_definitions(-DFOO -DBAR ...)\n"
-      "Adds flags to command line of C and C++ compilers.  "
-      "This command can be used to add any flag to a compile line, "
-      "but the -D flag is accepted most C/C++ compilers.  "
-      "Other flags may not be as portable.";
+      "Adds flags to the compiler command line for sources in the current "
+      "directory and below.  This command can be used to add any flags, "
+      "but it was originally intended to add preprocessor definitions.  "
+      "Flags beginning in -D or /D that look like preprocessor definitions "
+      "are automatically added to the COMPILE_DEFINITIONS property for "
+      "the current directory.  Definitions with non-trival values may be "
+      "left in the set of flags instead of being converted for reasons of "
+      "backwards compatibility.  See documentation of the directory, "
+      "target, and source file COMPILE_DEFINITIONS properties for details "
+      "on adding preprocessor definitions to specific scopes and "
+      "configurations."
+      ;
     }
 
   cmTypeMacro(cmAddDefinitionsCommand, cmCommand);
+private:
+  bool ParseDefinition(std::string const& def);
 };
 
 

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.424
retrieving revision 1.425
diff -u -d -r1.424 -r1.425
--- cmMakefile.cxx	17 Jan 2008 23:13:55 -0000	1.424
+++ cmMakefile.cxx	18 Jan 2008 00:29:43 -0000	1.425
@@ -877,6 +877,12 @@
     return;
     }
 
+  // If this is really a definition, update COMPILE_DEFINITIONS.
+  if(this->ParseDefineFlag(flag, false))
+    {
+    return;
+    }
+
   // remove any \n\r
   std::string ret = flag;
   std::string::size_type pos = 0;
@@ -906,6 +912,12 @@
     return;
     }
 
+  // If this is really a definition, update COMPILE_DEFINITIONS.
+  if(this->ParseDefineFlag(flag, true))
+    {
+    return;
+    }
+
   // Remove all instances of the flag that are surrounded by
   // whitespace or the beginning/end of the string.
   for(std::string::size_type lpos = this->DefineFlags.find(flag, 0);
@@ -924,6 +936,67 @@
     }
 }
 
+bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
+{
+  // Create a regular expression to match valid definitions.
+  // Definitions with non-trivial values must not be matched because
+  // escaping them could break compatibility with escapes added by
+  // users.
+  static cmsys::RegularExpression
+    regex("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=[A-Za-z0-9_.]+)?$");
+
+  // Make sure the definition matches.
+  if(!regex.find(def.c_str()))
+    {
+    return false;
+    }
+
+  // VS6 IDE does not support definitions with values.
+  if((strcmp(this->LocalGenerator->GetGlobalGenerator()->GetName(),
+             "Visual Studio 6") == 0) &&
+     (def.find("=") != def.npos))
+    {
+    return false;
+    }
+
+  // Get the definition part after the flag.
+  const char* define = def.c_str() + 2;
+
+  if(remove)
+    {
+    if(const char* cdefs = this->GetProperty("COMPILE_DEFINITIONS"))
+      {
+      // Expand the list.
+      std::vector<std::string> defs;
+      cmSystemTools::ExpandListArgument(cdefs, defs);
+
+      // Recompose the list without the definition.
+      std::string ndefs;
+      const char* sep = "";
+      for(std::vector<std::string>::const_iterator di = defs.begin();
+          di != defs.end(); ++di)
+        {
+        if(*di != define)
+          {
+          ndefs += sep;
+          sep = ";";
+          ndefs += *di;
+          }
+        }
+
+      // Store the new list.
+      this->SetProperty("COMPILE_DEFINITIONS", ndefs.c_str());
+      }
+    }
+  else
+    {
+    // Append the definition to the directory property.
+    this->AppendProperty("COMPILE_DEFINITIONS", define);
+    }
+
+  return true;
+}
+
 void cmMakefile::AddLinkLibrary(const char* lib,
                                 cmTarget::LinkLibraryType llt)
 {
@@ -2960,6 +3033,35 @@
      "included and processed when ctest is run on the directory.");
 
   cm->DefineProperty
+    ("COMPILE_DEFINITIONS", cmProperty::DIRECTORY,
+     "Preprocessor definitions for compiling a directory's sources.",
+     "The COMPILE_DEFINITIONS property may be set to a list of preprocessor "
+     "definitions using the syntax VAR or VAR=value.  Function-style "
+     "definitions are not supported.  CMake will automatically escape "
+     "the value correctly for the native build system (note that CMake "
+     "language syntax may require escapes to specify some values).  "
+     "This property may be set on a per-configuration basis using the name "
+     "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
+     "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
+     "CMake will automatically drop some definitions that "
+     "are not supported by the native build tool.  "
+     "The VS6 IDE does not support definitions with values "
+     "(but NMake does).\n"
+     "Dislaimer: Most native build tools have poor support for escaping "
+     "certain values.  CMake has work-arounds for many cases but some "
+     "values may just not be possible to pass correctly.  If a value "
+     "does not seem to be escaped correctly, do not attempt to "
+     "work-around the problem by adding escape sequences to the value.  "
+     "Your work-around may break in a future version of CMake that "
+     "has improved escape support.  Instead consider defining the macro "
+     "in a (configured) header file.  Then report the limitation.");
+
+  cm->DefineProperty
+    ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::DIRECTORY,
+     "Per-configuration preprocessor definitions in a directory.",
+     "This is the configuration-specific version of COMPILE_DEFINITIONS.");
+
+  cm->DefineProperty
     ("EXCLUDE_FROM_ALL", cmProperty::DIRECTORY,
      "Exclude the directory from the all target of its parent.",
      "A property on a directory that indicates if its targets are excluded "



More information about the Cmake-commits mailing list