Browse Source

ENH: Add option to retrieve list of macros. Close Bug #25 - Get_CMAKE_PROPERTIES

Andy Cedilnik 22 years ago
parent
commit
96d561aabc

+ 4 - 0
Source/cmGetCMakePropertyCommand.cxx

@@ -63,6 +63,10 @@ bool cmGetCMakePropertyCommand::InitialPass(
       cc++;
       }
     }
+  else if ( args[1] == "MACROS" )
+    {
+    m_Makefile->GetListOfMacros(output);
+    }
   else
     {
     std::string emsg = "Unknown CMake property: " + args[1];

+ 1 - 1
Source/cmGetCMakePropertyCommand.h

@@ -57,7 +57,7 @@ public:
         "Get a property from the CMake.  The value of the property is" 
         "stored in the variable VAR. If the property is not found,"
         "CMake will report an error. The properties include: VARIABLES, "
-        "CACHE_VARIABLES, COMMANDS.";
+        "CACHE_VARIABLES, COMMANDS, and MACROS.";
     }
   
   cmTypeMacro(cmGetCMakePropertyCommand, cmCommand);

+ 9 - 0
Source/cmMacroCommand.cxx

@@ -30,6 +30,15 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
       if(!expandedArguments.empty() && (expandedArguments[0] == m_Args[0]))
         {
         m_Executing = true;
+        std::string name = m_Args[0];
+        std::vector<std::string>::size_type cc;
+        name += "(";
+        for ( cc = 0; cc < m_Args.size(); cc ++ )
+          {
+          name += " " + m_Args[cc];
+          }
+        name += " )";
+        mf.AddMacro(m_Args[0].c_str(), name.c_str());
         return true;
         }
       }

+ 25 - 0
Source/cmMakefile.cxx

@@ -2003,6 +2003,31 @@ cmVariableWatch *cmMakefile::GetVariableWatch() const
   return 0;
 }
 
+void cmMakefile::AddMacro(const char* name, const char* signature)
+{
+  if ( !name || !signature )
+    {
+    return;
+    }
+  m_MacrosMap[name] = signature;
+}
+
+void cmMakefile::GetListOfMacros(std::string& macros)
+{
+  StringStringMap::iterator it;
+  macros = "";
+  int cc;
+  for ( it = m_MacrosMap.begin(); it != m_MacrosMap.end(); ++it )
+    {
+    if ( cc > 0 )
+      {
+      macros += ";";
+      }
+    macros += it->first;
+    cc ++;
+    }
+}
+
 cmCacheManager *cmMakefile::GetCacheManager() const
 {
   return this->GetCMakeInstance()->GetCacheManager();

+ 14 - 0
Source/cmMakefile.h

@@ -603,6 +603,17 @@ public:
    * if so then return it
    */
   cmSourceFile *GetSourceFileWithOutput(const char *outName);
+
+  /**
+   * Add a macro to the list of macros. The arguments should be name of the
+   * macro and a documentation signature of it 
+   */
+  void AddMacro(const char* name, const char* signature);
+
+  /**
+   * Get a list of macros as a ; separated string
+   */
+  void GetListOfMacros(std::string& macros);
   
 protected:
   // add link libraries and directories to the target
@@ -670,6 +681,9 @@ private:
   DataMap m_DataMap;
   bool m_Inheriting;
 
+  typedef std::map<cmStdString, cmStdString> StringStringMap;
+  StringStringMap m_MacrosMap;
+
   // used in AddDefinition for performance improvement
   DefinitionMap::key_type  m_TemporaryDefinitionKey;
 };

+ 13 - 0
Tests/SystemInformation/CMakeLists.txt

@@ -6,6 +6,12 @@ CONFIGURE_FILE(${DumpInformation_SOURCE_DIR}/DumpInformation.h.in
 ${DumpInformation_BINARY_DIR}/DumpInformation.h)
 ADD_EXECUTABLE(DumpInformation DumpInformation.cxx)
 
+MACRO(FOO args)
+  MESSAGE("Test macro")
+ENDMACRO(FOO)
+
+FOO(lala)
+
 FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AllVariables.txt "")
 GET_CMAKE_PROPERTY(res VARIABLES)
 FOREACH(var ${res})
@@ -20,3 +26,10 @@ FOREACH(var ${res})
              "${var}\n")
 ENDFOREACH(var ${res})
 
+FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AllMacros.txt "")
+GET_CMAKE_PROPERTY(res MACROS)
+FOREACH(var ${res})
+  FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AllMacros.txt 
+             "${var}\n")
+ENDFOREACH(var ${res})
+

+ 1 - 0
Tests/SystemInformation/DumpInformation.cxx

@@ -54,6 +54,7 @@ int main(int,char *[])
       DumpInformation_BINARY_DIR "/SystemInformation.out",
       DumpInformation_BINARY_DIR "/AllVariables.txt",
       DumpInformation_BINARY_DIR "/AllCommands.txt",
+      DumpInformation_BINARY_DIR "/AllMacros.txt",
       DumpInformation_BINARY_DIR "/../../Source/cmConfigure.h",
       DumpInformation_BINARY_DIR "/../../CMakeCache.txt", 
       DumpInformation_BINARY_DIR "/../../CMakeOutput.log",