diff options
author | Brad King <brad.king@kitware.com> | 2017-10-18 13:37:36 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2017-10-18 13:37:59 (GMT) |
commit | b0b94cdec5bb201e64aac4b3877a1a635b9f1119 (patch) | |
tree | 5a10cbf8d1fc8fb96c517ae75c6c13637256bc53 /Source/cmake.cxx | |
parent | 0dba1db9d5d9f2c555c718acde5ec550503fae6f (diff) | |
parent | 96d642c7b87e303813b75aaa3412f8e532d2b925 (diff) | |
download | CMake-b0b94cdec5bb201e64aac4b3877a1a635b9f1119.zip CMake-b0b94cdec5bb201e64aac4b3877a1a635b9f1119.tar.gz CMake-b0b94cdec5bb201e64aac4b3877a1a635b9f1119.tar.bz2 |
Merge topic 'cmake-open'
96d642c7 cmake-gui: Use cmake::Open to open generated project
5de37a4a cmake: Add --open option for IDE generators
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Ruslan Baratov <ruslan_baratov@yahoo.com>
Merge-request: !1337
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 |