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

ENH: Add accessor for the list of commands

Andy Cedilnik 22 жил өмнө
parent
commit
c7f1198a00

+ 16 - 0
Source/cmGetCMakePropertyCommand.cxx

@@ -47,6 +47,22 @@ bool cmGetCMakePropertyCommand::InitialPass(
       output += vars[cc];
       }
     }
+  else if ( args[1] == "COMMANDS" )
+    {
+    cmake::RegisteredCommandsMap::iterator cmds 
+        = m_Makefile->GetCMakeInstance()->GetCommands()->begin();
+    for (cc=0 ; 
+      cmds != m_Makefile->GetCMakeInstance()->GetCommands()->end(); 
+      ++ cmds )
+      {
+      if ( cc > 0 )
+        {
+        output += ";";
+        }
+      output += cmds->first.c_str();
+      cc++;
+      }
+    }
   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.";
+        "CACHE_VARIABLES, COMMANDS.";
     }
   
   cmTypeMacro(cmGetCMakePropertyCommand, cmCommand);

+ 5 - 1
Source/cmake.h

@@ -50,6 +50,8 @@ class cmVariableWatch;
 class cmake
 {
  public:
+  typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
+
   ///! construct an instance of cmake
   cmake();
   ///! destruct an instance of cmake
@@ -193,6 +195,9 @@ class cmake
    */
   cmCommand *GetCommand(const char *name);
 
+  /** Get list of all commands */
+  RegisteredCommandsMap* GetCommands() { return &m_Commands; }
+
   /** Check if a command exists. */
   bool CommandExists(const char* name) const;
     
@@ -242,7 +247,6 @@ class cmake
   
 protected:
   typedef cmGlobalGenerator* (*CreateGeneratorFunctionType)();
-  typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
   typedef std::map<cmStdString, CreateGeneratorFunctionType> RegisteredGeneratorsMap;
   RegisteredCommandsMap m_Commands;
   RegisteredGeneratorsMap m_Generators;

+ 13 - 7
Tests/SystemInformation/CMakeLists.txt

@@ -6,11 +6,17 @@ CONFIGURE_FILE(${DumpInformation_SOURCE_DIR}/DumpInformation.h.in
 ${DumpInformation_BINARY_DIR}/DumpInformation.h)
 ADD_EXECUTABLE(DumpInformation DumpInformation.cxx)
 
-WRITE_FILE(${DumpInformation_BINARY_DIR}/AllVariables.txt "")
-GET_CMAKE_PROPERTY(VARS VARIABLES)
-FOREACH(var ${VARS})
-  WRITE_FILE(${DumpInformation_BINARY_DIR}/AllVariables.txt 
-             "${var} \"${${var}}\"" APPEND)
-  #MESSAGE(STATUS "Variable ${var} \"${${var}}\"")
-ENDFOREACH(var ${VARS})
+FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AllVariables.txt "")
+GET_CMAKE_PROPERTY(res VARIABLES)
+FOREACH(var ${res})
+  FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AllVariables.txt 
+             "${var} \"${${var}}\"\n")
+ENDFOREACH(var ${res})
+
+FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AllCommands.txt "")
+GET_CMAKE_PROPERTY(res COMMANDS)
+FOREACH(var ${res})
+  FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AllCommands.txt 
+             "${var}\n")
+ENDFOREACH(var ${res})
 

+ 1 - 0
Tests/SystemInformation/DumpInformation.cxx

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