diff --git a/Source/cmAbstractFilesCommand.h b/Source/cmAbstractFilesCommand.h index 6e7f73e49..a40cce891 100644 --- a/Source/cmAbstractFilesCommand.h +++ b/Source/cmAbstractFilesCommand.h @@ -54,6 +54,8 @@ public: return "ABSTRACT_FILES(file1 file2 ..)"; } + + cmTypeMacro(cmAbstractFilesCommand, cmCommand); }; diff --git a/Source/cmAddTargetCommand.h b/Source/cmAddTargetCommand.h index 01653e625..fd0aeab68 100644 --- a/Source/cmAddTargetCommand.h +++ b/Source/cmAddTargetCommand.h @@ -65,6 +65,8 @@ public: return "ADD_TARGET(Name \"command to run\")"; } + + cmTypeMacro(cmAddTargetCommand, cmCommand); }; #endif diff --git a/Source/cmAuxSourceDirectoryCommand.h b/Source/cmAuxSourceDirectoryCommand.h index c830a769a..905d63ab9 100644 --- a/Source/cmAuxSourceDirectoryCommand.h +++ b/Source/cmAuxSourceDirectoryCommand.h @@ -67,6 +67,8 @@ public: return "AUX_SOURCE_DIRECTORY(dir)"; } + + cmTypeMacro(cmAuxSourceDirectoryCommand, cmCommand); }; diff --git a/Source/cmCommand.h b/Source/cmCommand.h index aefd757bd..55841c432 100644 --- a/Source/cmCommand.h +++ b/Source/cmCommand.h @@ -122,6 +122,19 @@ public: const char* GetError() {return m_Error.c_str();} + /** + * Returns true if this class is the given class, or a subclass of it. + */ + static bool IsTypeOf(const char *type) + { return !strcmp("cmCommand", type); } + + /** + * Returns true if this object is an instance of the given class or + * a subclass of it. + */ + virtual bool IsA(const char *type) + { return cmCommand::IsTypeOf(type); } + protected: void SetError(const char* e) { @@ -136,4 +149,28 @@ private: std::string m_Error; }; +// All subclasses of cmCommand should invoke this macro. +#define cmTypeMacro(thisClass,superclass) \ +static bool IsTypeOf(const char *type) \ +{ \ + if ( !strcmp(#thisClass,type) ) \ + { \ + return true; \ + } \ + return superclass::IsTypeOf(type); \ +} \ +virtual bool IsA(const char *type) \ +{ \ + return thisClass::IsTypeOf(type); \ +} \ +static thisClass* SafeDownCast(cmCommand *c) \ +{ \ + if ( c && c->IsA(#thisClass) ) \ + { \ + return (thisClass *)c; \ + } \ + return 0;\ +} + + #endif diff --git a/Source/cmExecutablesCommand.h b/Source/cmExecutablesCommand.h index c420a878c..48b013ffa 100644 --- a/Source/cmExecutablesCommand.h +++ b/Source/cmExecutablesCommand.h @@ -63,6 +63,8 @@ public: return "EXECUTABLES(file1 file2 ...)"; } + + cmTypeMacro(cmExecutablesCommand, cmCommand); }; diff --git a/Source/cmFindIncludeCommand.h b/Source/cmFindIncludeCommand.h index 4b2cd4a68..738103293 100644 --- a/Source/cmFindIncludeCommand.h +++ b/Source/cmFindIncludeCommand.h @@ -70,6 +70,8 @@ public: return "FIND_INCLUDE(DEFINE try1 try2 ...)"; } + + cmTypeMacro(cmFindIncludeCommand, cmCommand); }; diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h index eca2e60b8..f1e26a28e 100644 --- a/Source/cmFindLibraryCommand.h +++ b/Source/cmFindLibraryCommand.h @@ -71,6 +71,8 @@ public: return "FIND_LIBRARY(DEFINE libraryName path1 path2 path3...)"; } + + cmTypeMacro(cmFindLibraryCommand, cmCommand); }; diff --git a/Source/cmFindProgramCommand.h b/Source/cmFindProgramCommand.h index 8aa7ee9ce..4b6d58cad 100644 --- a/Source/cmFindProgramCommand.h +++ b/Source/cmFindProgramCommand.h @@ -71,6 +71,8 @@ public: return "FIND_PROGRAM(NAME executable1 executable2 ...)"; } + + cmTypeMacro(cmFindProgramCommand, cmCommand); }; diff --git a/Source/cmIncludeDirectoryCommand.h b/Source/cmIncludeDirectoryCommand.h index 4236880c0..8011e533a 100644 --- a/Source/cmIncludeDirectoryCommand.h +++ b/Source/cmIncludeDirectoryCommand.h @@ -69,6 +69,8 @@ public: return "INCLUDE_DIRECTORIES(dir1 dir2 ...)"; } + + cmTypeMacro(cmIncludeDirectoryCommand, cmCommand); }; diff --git a/Source/cmLibraryCommand.h b/Source/cmLibraryCommand.h index 74957cb66..0abb2dd51 100644 --- a/Source/cmLibraryCommand.h +++ b/Source/cmLibraryCommand.h @@ -64,6 +64,8 @@ public: return "LIBRARY(libraryname)"; } + + cmTypeMacro(cmLibraryCommand, cmCommand); }; diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h index 783c8802f..36a6ad8ee 100644 --- a/Source/cmLinkDirectoriesCommand.h +++ b/Source/cmLinkDirectoriesCommand.h @@ -74,6 +74,8 @@ public: "The directories can use built in definitions like \n" "CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR."; } + + cmTypeMacro(cmLinkDirectoriesCommand, cmCommand); }; diff --git a/Source/cmLinkLibrariesCommand.h b/Source/cmLinkLibrariesCommand.h index 31e931031..5f01d524a 100644 --- a/Source/cmLinkLibrariesCommand.h +++ b/Source/cmLinkLibrariesCommand.h @@ -76,6 +76,8 @@ public: "down to all other commands. The library name should be\n" "the same as the name used in the LIBRARY(library) command."; } + + cmTypeMacro(cmLinkLibrariesCommand, cmCommand); }; diff --git a/Source/cmProjectCommand.h b/Source/cmProjectCommand.h index fe395b056..7c0c67377 100644 --- a/Source/cmProjectCommand.h +++ b/Source/cmProjectCommand.h @@ -74,6 +74,8 @@ public: return "PROJECT(projectname) Sets the name of the Microsoft workspace .dsw file. Does nothing on UNIX currently\n"; } + + cmTypeMacro(cmProjectCommand, cmCommand); }; diff --git a/Source/cmSourceFilesCommand.h b/Source/cmSourceFilesCommand.h index f53433982..6ff44b20d 100644 --- a/Source/cmSourceFilesCommand.h +++ b/Source/cmSourceFilesCommand.h @@ -68,6 +68,8 @@ public: return "SOURCE_FILES(file1 file2 ...)"; } + + cmTypeMacro(cmSourceFilesCommand, cmCommand); }; diff --git a/Source/cmSourceFilesRequireCommand.h b/Source/cmSourceFilesRequireCommand.h index e84c21e22..b7253b7a1 100644 --- a/Source/cmSourceFilesRequireCommand.h +++ b/Source/cmSourceFilesRequireCommand.h @@ -67,6 +67,8 @@ public: return "SOURCE_FILES_REQUIRE(var1 var2 ... SOURCES_BEGIN file1 file2 ...)"; } + + cmTypeMacro(cmSourceFilesRequireCommand, cmCommand); }; diff --git a/Source/cmSubdirCommand.h b/Source/cmSubdirCommand.h index 43a501e0b..fd8b346be 100644 --- a/Source/cmSubdirCommand.h +++ b/Source/cmSubdirCommand.h @@ -67,6 +67,8 @@ public: "This will cause any CMakeLists.txt files in the sub directories\n" "to be processed by CMake."; } + + cmTypeMacro(cmSubdirCommand, cmCommand); }; diff --git a/Source/cmTestsCommand.h b/Source/cmTestsCommand.h index ec001b3c3..0a9fd9318 100644 --- a/Source/cmTestsCommand.h +++ b/Source/cmTestsCommand.h @@ -67,6 +67,8 @@ public: return "TESTS(file1 file2 ...)"; } + + cmTypeMacro(cmTestsCommand, cmCommand); }; diff --git a/Source/cmUnixDefinesCommand.h b/Source/cmUnixDefinesCommand.h index f912ff4da..595792c8b 100644 --- a/Source/cmUnixDefinesCommand.h +++ b/Source/cmUnixDefinesCommand.h @@ -75,6 +75,8 @@ public: "UNIX_DEFINES(-DFOO -DBAR)\n" "Add -D flags to the command line for Unix only."; } + + cmTypeMacro(cmUnixDefinesCommand, cmCommand); }; diff --git a/Source/cmUnixLibrariesCommand.h b/Source/cmUnixLibrariesCommand.h index 80a77a482..e3c883d15 100644 --- a/Source/cmUnixLibrariesCommand.h +++ b/Source/cmUnixLibrariesCommand.h @@ -74,6 +74,8 @@ public: return "UNIX_LIBRARIES(library -lm ...)"; } + + cmTypeMacro(cmUnixLibrariesCommand, cmCommand); }; diff --git a/Source/cmWin32DefinesCommand.h b/Source/cmWin32DefinesCommand.h index a8e0da89f..af07265be 100644 --- a/Source/cmWin32DefinesCommand.h +++ b/Source/cmWin32DefinesCommand.h @@ -75,6 +75,8 @@ public: "WIN32_DEFINES(-DFOO -DBAR ...)\n" "Add -D define flags to command line for Win32 environments."; } + + cmTypeMacro(cmWin32DefinesCommand, cmCommand); }; diff --git a/Source/cmWin32LibrariesCommand.h b/Source/cmWin32LibrariesCommand.h index 61d7b189d..02885afbb 100644 --- a/Source/cmWin32LibrariesCommand.h +++ b/Source/cmWin32LibrariesCommand.h @@ -74,6 +74,8 @@ public: return "WIN32_LIBRARIES(library -lm ...)"; } + + cmTypeMacro(cmWin32LibrariesCommand, cmCommand); };