diff options
author | Ken Martin <ken.martin@kitware.com> | 2007-02-27 15:10:10 (GMT) |
---|---|---|
committer | Ken Martin <ken.martin@kitware.com> | 2007-02-27 15:10:10 (GMT) |
commit | 31a700188b6864341fdcbd22cd4181dbe6ace671 (patch) | |
tree | d1fafeb509092de727a1b977ffb9071ea1d966a8 /Source | |
parent | fa9f03779f5cbfcd6ee264fcf6989e571779a156 (diff) | |
download | CMake-31a700188b6864341fdcbd22cd4181dbe6ace671.zip CMake-31a700188b6864341fdcbd22cd4181dbe6ace671.tar.gz CMake-31a700188b6864341fdcbd22cd4181dbe6ace671.tar.bz2 |
ENH: added --system-information option to CMake
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Source/cmake.cxx | 92 | ||||
-rw-r--r-- | Source/cmake.h | 5 | ||||
-rw-r--r-- | Source/cmakemain.cxx | 15 |
4 files changed, 117 insertions, 0 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 44d50da..a63df3e 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -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" diff --git a/Source/cmake.cxx b/Source/cmake.cxx index d1cb716..af1c0a8 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -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; +} diff --git a/Source/cmake.h b/Source/cmake.h index c32e3f1..2262ba4 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -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 */ diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index d636559..fd9a6e1 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -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); |