diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-09-09 12:49:30 (GMT) |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2016-09-12 20:00:22 (GMT) |
commit | 3e58b9af57074ded65566330c33999bdfac191a8 (patch) | |
tree | cd5c65ca8c103f6ec6ea9fadb406e5f6808fa202 /Source/cmake.cxx | |
parent | c73967cb4a0217b2d0825f67d6fd56af2b4d6b7f (diff) | |
download | CMake-3e58b9af57074ded65566330c33999bdfac191a8.zip CMake-3e58b9af57074ded65566330c33999bdfac191a8.tar.gz CMake-3e58b9af57074ded65566330c33999bdfac191a8.tar.bz2 |
cmake: Factor out method to find the CMakeCache.txt file
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r-- | Source/cmake.cxx | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 4edf228..0d61a3d 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1046,6 +1046,28 @@ const char* cmake::GetHomeOutputDirectory() const return this->State->GetBinaryDirectory(); } +std::string cmake::FindCacheFile(const std::string& binaryDir) const +{ + std::string cachePath = binaryDir; + cmSystemTools::ConvertToUnixSlashes(cachePath); + std::string cacheFile = cachePath; + cacheFile += "/CMakeCache.txt"; + if (!cmSystemTools::FileExists(cacheFile.c_str())) { + // search in parent directories for cache + std::string cmakeFiles = cachePath; + cmakeFiles += "/CMakeFiles"; + if (cmSystemTools::FileExists(cmakeFiles.c_str())) { + std::string cachePathFound = + cmSystemTools::FileExistsInParentDirectories("CMakeCache.txt", + cachePath.c_str(), "/"); + if (!cachePathFound.empty()) { + cachePath = cmSystemTools::GetFilenamePath(cachePathFound); + } + } + } + return cachePath; +} + void cmake::SetGlobalGenerator(cmGlobalGenerator* gg) { if (!gg) { @@ -2344,24 +2366,8 @@ int cmake::Build(const std::string& dir, const std::string& target, std::cerr << "Error: " << dir << " is not a directory\n"; return 1; } - std::string cachePath = dir; - cmSystemTools::ConvertToUnixSlashes(cachePath); - std::string cacheFile = cachePath; - cacheFile += "/CMakeCache.txt"; - if (!cmSystemTools::FileExists(cacheFile.c_str())) { - // search in parent directories for cache - std::string cmakeFiles = cachePath; - cmakeFiles += "/CMakeFiles"; - if (cmSystemTools::FileExists(cmakeFiles.c_str())) { - std::string cachePathFound = - cmSystemTools::FileExistsInParentDirectories("CMakeCache.txt", - cachePath.c_str(), "/"); - if (!cachePathFound.empty()) { - cachePath = cmSystemTools::GetFilenamePath(cachePathFound); - } - } - } + std::string cachePath = FindCacheFile(dir); if (!this->LoadCache(cachePath)) { std::cerr << "Error: could not load cache\n"; return 1; |