ENH: added --system-information option to CMake

This commit is contained in:
Ken Martin 2007-02-27 10:10:10 -05:00
parent fa9f03779f
commit 31a700188b
4 changed files with 117 additions and 0 deletions

View File

@ -505,6 +505,11 @@ IF(BUILD_TESTING)
--build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
--test-command DumpInformation) --test-command DumpInformation)
ADD_TEST(SystemInformationNew
${CMAKE_CMAKE_COMMAND} -E chdir "${CMake_BINARY_DIR}"
${CMAKE_CMAKE_COMMAND} --system-information
)
ADD_TEST(StringFileTest ${CMAKE_CTEST_COMMAND} ADD_TEST(StringFileTest ${CMAKE_CTEST_COMMAND}
--build-and-test --build-and-test
"${CMake_SOURCE_DIR}/Tests/StringFileTest" "${CMake_SOURCE_DIR}/Tests/StringFileTest"

View File

@ -2912,3 +2912,95 @@ bool cmake::GetPropertyAsBool(const char* prop)
{ {
return cmSystemTools::IsOn(this->GetProperty(prop)); return cmSystemTools::IsOn(this->GetProperty(prop));
} }
int cmake::GetSystemInformation(std::vector<std::string>& args)
{
// we must create a temporary directory, copy some files to it
// run cmake on it, and then collect the results.
// so create the directory
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
std::string destPath = cwd + "/__cmake_systeminformation";
cmSystemTools::RemoveADirectory(destPath.c_str());
if (!cmSystemTools::MakeDirectory(destPath.c_str()))
{
std::cerr << "Error: --system-information must be run from a "
"writable directory!\n";
return 1;
}
// we have to find the module directory, so we can copy the files
this->AddCMakePaths(args[0].c_str());
std::string modulesPath =
this->CacheManager->GetCacheValue("CMAKE_ROOT");
modulesPath += "/Modules";
std::string inFile = modulesPath;
inFile += "/SystemInformation.cmake";
std::string outFile = destPath;
outFile += "/CMakeLists.txt";
// Copy file
if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
{
std::cerr << "Error copying file \"" << inFile.c_str()
<< "\" to \"" << outFile.c_str() << "\".\n";
return 1;
}
// do we write to a file or to stdout?
std::string resultFile;
if (args.size() == 1)
{
resultFile = cwd;
resultFile += "__cmake_systeminformation/results.txt";
}
else
{
if (!cmSystemTools::FileIsFullPath(args[1].c_str()))
{
resultFile += cwd;
resultFile += "/";
}
resultFile = args[1];
}
// now run cmake on the CMakeLists file
cmSystemTools::ChangeDirectory(destPath.c_str());
cmake cm;
std::vector<std::string> args2;
args2.push_back(args[0]);
args2.push_back(destPath);
std::string resultArg = "-DRESULT_FILE=";
resultArg += resultFile;
args2.push_back(resultArg);
int res = cm.Run(args2, false);
// change back to the original directory
cmSystemTools::ChangeDirectory(cwd.c_str());
// echo results to stdout if needed
if (args.size() == 1)
{
FILE* fin = fopen(resultFile.c_str(), "r");
if(fin)
{
const int bufferSize = 4096;
char buffer[bufferSize];
int n;
while((n = fread(buffer, 1, bufferSize, fin)) > 0)
{
for(char* c = buffer; c < buffer+n; ++c)
{
putc(*c, stdout);
}
fflush(stdout);
}
fclose(fin);
}
}
// clean up the directory
cmSystemTools::RemoveADirectory(destPath.c_str());
return 0;
}

View File

@ -189,6 +189,11 @@ class cmake
*/ */
static int ExecuteCMakeCommand(std::vector<std::string>&); static int ExecuteCMakeCommand(std::vector<std::string>&);
/**
* Get the system information and write it to the file specified
*/
int GetSystemInformation(std::vector<std::string>&);
/** /**
* Add a command to this cmake instance * Add a command to this cmake instance
*/ */

View File

@ -83,6 +83,10 @@ static const cmDocumentationEntry cmDocumentationOptions[] =
{"--graphviz=[file]", "Generate graphviz of dependencies.", {"--graphviz=[file]", "Generate graphviz of dependencies.",
"Generate a graphviz input file that will contain all the library and " "Generate a graphviz input file that will contain all the library and "
"executable dependencies in the project."}, "executable dependencies in the project."},
{"--system-information [file]", "Dump information about this system.",
"Dump a wide range of information about the current system. If run "
"from the top of a binary tree for a CMake project it will dump "
"additional information such as the cache, log files etc."},
{"--debug-trycompile", "Do not delete the try compile directories..", {"--debug-trycompile", "Do not delete the try compile directories..",
"Do not delete the files and directories created for try_compile calls. " "Do not delete the files and directories created for try_compile calls. "
"This is useful in debugging failed try_compiles."}, "This is useful in debugging failed try_compiles."},
@ -206,6 +210,7 @@ int do_cmake(int ac, char** av)
#endif #endif
bool wiz = false; bool wiz = false;
bool sysinfo = false;
bool command = false; bool command = false;
bool list_cached = false; bool list_cached = false;
bool list_all_cached = false; bool list_all_cached = false;
@ -219,6 +224,10 @@ int do_cmake(int ac, char** av)
{ {
wiz = true; wiz = true;
} }
else if(!command && strcmp(av[i], "--system-information") == 0)
{
sysinfo = true;
}
// if command has already been set, then // if command has already been set, then
// do not eat the -E // do not eat the -E
else if (!command && strcmp(av[i], "-E") == 0) else if (!command && strcmp(av[i], "-E") == 0)
@ -277,6 +286,12 @@ int do_cmake(int ac, char** av)
cmakewizard wizard; cmakewizard wizard;
return wizard.RunWizard(args); return wizard.RunWizard(args);
} }
if (sysinfo)
{
cmake cm;
int ret = cm.GetSystemInformation(args);
return ret;
}
cmake cm; cmake cm;
cm.SetProgressCallback(updateProgress, 0); cm.SetProgressCallback(updateProgress, 0);
cm.SetScriptMode(script_mode); cm.SetScriptMode(script_mode);