diff options
author | Gregor Jasny <gjasny@googlemail.com> | 2017-10-11 18:58:35 (GMT) |
---|---|---|
committer | Gregor Jasny <gjasny@googlemail.com> | 2017-10-13 19:28:34 (GMT) |
commit | 5de37a4a6474fa569e2ac28d5e9c164b6e7d2f46 (patch) | |
tree | 310730d01dd0a79a268c2ce6982ab49fe8b3e171 /Source/cmake.cxx | |
parent | d0b6c2da8b7fda317e11c66a4b133d4a88eaeef6 (diff) | |
download | CMake-5de37a4a6474fa569e2ac28d5e9c164b6e7d2f46.zip CMake-5de37a4a6474fa569e2ac28d5e9c164b6e7d2f46.tar.gz CMake-5de37a4a6474fa569e2ac28d5e9c164b6e7d2f46.tar.bz2 |
cmake: Add --open option for IDE generators
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r-- | Source/cmake.cxx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index fd7151f..d7ed772 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2425,6 +2425,49 @@ int cmake::Build(const std::string& dir, const std::string& target, nativeOptions); } +bool cmake::Open(const std::string& dir, bool dryRun) +{ + this->SetHomeDirectory(""); + this->SetHomeOutputDirectory(""); + if (!cmSystemTools::FileIsDirectory(dir)) { + std::cerr << "Error: " << dir << " is not a directory\n"; + return false; + } + + std::string cachePath = FindCacheFile(dir); + if (!this->LoadCache(cachePath)) { + std::cerr << "Error: could not load cache\n"; + return false; + } + const char* genName = this->State->GetCacheEntryValue("CMAKE_GENERATOR"); + if (!genName) { + std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n"; + return false; + } + const char* extraGenName = + this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR"); + std::string fullName = + cmExternalMakefileProjectGenerator::CreateFullGeneratorName( + genName, extraGenName ? extraGenName : ""); + + std::unique_ptr<cmGlobalGenerator> gen( + this->CreateGlobalGenerator(fullName)); + if (!gen.get()) { + std::cerr << "Error: could create CMAKE_GENERATOR \"" << fullName + << "\"\n"; + return false; + } + + const char* cachedProjectName = + this->State->GetCacheEntryValue("CMAKE_PROJECT_NAME"); + if (!cachedProjectName) { + std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n"; + return false; + } + + return gen->Open(dir, cachedProjectName, dryRun); +} + void cmake::WatchUnusedCli(const std::string& var) { #ifdef CMAKE_BUILD_WITH_CMAKE |