summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2002-09-10 20:51:29 (GMT)
committerKen Martin <ken.martin@kitware.com>2002-09-10 20:51:29 (GMT)
commit9149cdd078a1f1ab03eb0a60d30628aeb2395023 (patch)
tree998ee59b89e278926ec862721c31a0b270c619a3 /Source
parent38e412626b604d7f79cac82153047fc59b55597f (diff)
downloadCMake-9149cdd078a1f1ab03eb0a60d30628aeb2395023.zip
CMake-9149cdd078a1f1ab03eb0a60d30628aeb2395023.tar.gz
CMake-9149cdd078a1f1ab03eb0a60d30628aeb2395023.tar.bz2
moved commands into cmake
Diffstat (limited to 'Source')
-rw-r--r--Source/cmake.cxx66
-rw-r--r--Source/cmake.h24
2 files changed, 90 insertions, 0 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index d816726..5ed7183 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -19,6 +19,8 @@
#include "cmCacheManager.h"
#include "cmMakefile.h"
#include "cmLocalGenerator.h"
+#include "cmCommands.h"
+#include "cmCommand.h"
// include the generator
#if defined(_WIN32) && !defined(__CYGWIN__)
@@ -35,6 +37,7 @@ cmake::cmake()
m_Verbose = false;
m_CacheManager = new cmCacheManager;
m_GlobalGenerator = 0;
+ this->AddDefaultCommands();
}
cmake::~cmake()
@@ -45,8 +48,34 @@ cmake::~cmake()
delete m_GlobalGenerator;
m_GlobalGenerator = 0;
}
+ for(RegisteredCommandsMap::iterator j = m_Commands.begin();
+ j != m_Commands.end(); ++j)
+ {
+ delete (*j).second;
+ }
+}
+
+bool cmake::CommandExists(const char* name) const
+{
+ return (m_Commands.find(name) != m_Commands.end());
}
+cmCommand *cmake::GetCommand(const char *name)
+{
+ cmCommand* rm = 0;
+ RegisteredCommandsMap::iterator pos = m_Commands.find(name);
+ if (pos != m_Commands.end())
+ {
+ rm = (*pos).second;
+ }
+ return rm;
+}
+
+void cmake::AddCommand(cmCommand* wg)
+{
+ std::string name = wg->GetName();
+ m_Commands.insert( RegisteredCommandsMap::value_type(name, wg));
+}
void cmake::Usage(const char* program)
{
@@ -811,3 +840,40 @@ const char* cmake::GetCacheDefinition(const char* name) const
{
return m_CacheManager->GetCacheValue(name);
}
+
+int cmake::DumpDocumentationToFile(std::ostream& f)
+{
+ // Loop over all registered commands and print out documentation
+ const char *name;
+ const char *terse;
+ const char *full;
+ char tmp[1024];
+ sprintf(tmp,"Version %d.%d", cmake::GetMajorVersion(),
+ cmake::GetMinorVersion());
+ f << "<html>\n";
+ f << "<h1>Documentation for commands of CMake " << tmp << "</h1>\n";
+ f << "<ul>\n";
+ for(RegisteredCommandsMap::iterator j = m_Commands.begin();
+ j != m_Commands.end(); ++j)
+ {
+ name = (*j).second->GetName();
+ terse = (*j).second->GetTerseDocumentation();
+ full = (*j).second->GetFullDocumentation();
+ f << "<li><b>" << name << "</b> - " << terse << std::endl
+ << "<br><i>Usage:</i> " << full << "</li>" << std::endl << std::endl;
+ }
+ f << "</ul></html>\n";
+ return 1;
+}
+
+void cmake::AddDefaultCommands()
+{
+ std::list<cmCommand*> commands;
+ GetPredefinedCommands(commands);
+ for(std::list<cmCommand*>::iterator i = commands.begin();
+ i != commands.end(); ++i)
+ {
+ this->AddCommand(*i);
+ }
+}
+
diff --git a/Source/cmake.h b/Source/cmake.h
index 709778f..da5d329 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -25,6 +25,7 @@ class cmGlobalGenerator;
class cmLocalGenerator;
class cmCacheManager;
class cmMakefile;
+class cmCommand;
class cmake
{
@@ -90,6 +91,12 @@ class cmake
//@}
/**
+ * Dump documentation to a file. If 0 is returned, the
+ * operation failed.
+ */
+ int DumpDocumentationToFile(std::ostream&);
+
+ /**
* Handle a command line invocation of cmake.
*/
int Run(const std::vector<std::string>&args);
@@ -141,6 +148,19 @@ class cmake
static int CMakeCommand(std::vector<std::string>&);
/**
+ * Add a command to this cmake instance
+ */
+ void AddCommand(cmCommand* );
+
+ /**
+ * Get a command by its name
+ */
+ cmCommand *GetCommand(const char *name);
+
+ /** Check if a command exists. */
+ bool CommandExists(const char* name) const;
+
+ /**
* Is cmake in the process of a local cmake invocation. If so, we know the
* cache is already configured and ready to go.
*/
@@ -156,6 +176,10 @@ class cmake
void SetArgs(const std::vector<std::string>&);
protected:
+ typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
+ RegisteredCommandsMap m_Commands;
+ void AddDefaultCommands();
+
cmGlobalGenerator *m_GlobalGenerator;
cmCacheManager *m_CacheManager;
std::string m_cmHomeDirectory;