ENH: added --system-information option to CMake
This commit is contained in:
parent
fa9f03779f
commit
31a700188b
|
@ -505,6 +505,11 @@ IF(BUILD_TESTING)
|
|||
--build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
|
||||
--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}
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/StringFileTest"
|
||||
|
|
|
@ -2912,3 +2912,95 @@ bool cmake::GetPropertyAsBool(const char* 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;
|
||||
}
|
||||
|
|
|
@ -189,6 +189,11 @@ class cmake
|
|||
*/
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -83,6 +83,10 @@ static const cmDocumentationEntry cmDocumentationOptions[] =
|
|||
{"--graphviz=[file]", "Generate graphviz of dependencies.",
|
||||
"Generate a graphviz input file that will contain all the library and "
|
||||
"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..",
|
||||
"Do not delete the files and directories created for try_compile calls. "
|
||||
"This is useful in debugging failed try_compiles."},
|
||||
|
@ -206,6 +210,7 @@ int do_cmake(int ac, char** av)
|
|||
#endif
|
||||
|
||||
bool wiz = false;
|
||||
bool sysinfo = false;
|
||||
bool command = false;
|
||||
bool list_cached = false;
|
||||
bool list_all_cached = false;
|
||||
|
@ -219,6 +224,10 @@ int do_cmake(int ac, char** av)
|
|||
{
|
||||
wiz = true;
|
||||
}
|
||||
else if(!command && strcmp(av[i], "--system-information") == 0)
|
||||
{
|
||||
sysinfo = true;
|
||||
}
|
||||
// if command has already been set, then
|
||||
// do not eat the -E
|
||||
else if (!command && strcmp(av[i], "-E") == 0)
|
||||
|
@ -277,6 +286,12 @@ int do_cmake(int ac, char** av)
|
|||
cmakewizard wizard;
|
||||
return wizard.RunWizard(args);
|
||||
}
|
||||
if (sysinfo)
|
||||
{
|
||||
cmake cm;
|
||||
int ret = cm.GetSystemInformation(args);
|
||||
return ret;
|
||||
}
|
||||
cmake cm;
|
||||
cm.SetProgressCallback(updateProgress, 0);
|
||||
cm.SetScriptMode(script_mode);
|
||||
|
|
Loading…
Reference in New Issue