summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-11-17 15:29:55 (GMT)
committerBrad King <brad.king@kitware.com>2016-11-17 15:29:58 (GMT)
commit25b6e7b710d7739cca44ed19bf45a190e72a6b82 (patch)
tree9699bdd712c12a0828a80ab6a01dfbb471c2ca53 /Source
parent0e9634d2c90fd748774f9238219cb1661550f233 (diff)
downloadCMake-25b6e7b710d7739cca44ed19bf45a190e72a6b82.zip
CMake-25b6e7b710d7739cca44ed19bf45a190e72a6b82.tar.gz
CMake-25b6e7b710d7739cca44ed19bf45a190e72a6b82.tar.bz2
Tolerate removed/replaced CMakeCache.txt with old CMakeFiles/
Users or scripts commonly remove or replace `CMakeCache.txt` without also removing `CMakeFiles/`. In this case the information saved in the cache from platform information initialization is missing, so we need to re-initialize it. In such a case, remove the platform information directory so that re-initialization will occur and restore needed information to the cache. Closes: #14820
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalGenerator.cxx20
1 files changed, 20 insertions, 0 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index fa447ff..2808051 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -50,6 +50,9 @@
#include <cm_jsoncpp_writer.h>
#endif
+const std::string kCMAKE_PLATFORM_INFO_INITIALIZED =
+ "CMAKE_PLATFORM_INFO_INITIALIZED";
+
class cmInstalledFile;
bool cmTarget::StrictTargetComparison::operator()(cmTarget const* t1,
@@ -428,6 +431,23 @@ void cmGlobalGenerator::EnableLanguage(
// set the dir for parent files so they can be used by modules
mf->AddDefinition("CMAKE_PLATFORM_INFO_DIR", rootBin.c_str());
+ if (!this->CMakeInstance->GetIsInTryCompile()) {
+ // Keep a mark in the cache to indicate that we've initialized the
+ // platform information directory. If the platform information
+ // directory exists but the mark is missing then CMakeCache.txt
+ // has been removed or replaced without also removing the CMakeFiles/
+ // directory. In this case remove the platform information directory
+ // so that it will be re-initialized and the relevant information
+ // restored in the cache.
+ if (cmSystemTools::FileIsDirectory(rootBin) &&
+ !mf->IsOn(kCMAKE_PLATFORM_INFO_INITIALIZED)) {
+ cmSystemTools::RemoveADirectory(rootBin);
+ }
+ this->GetCMakeInstance()->AddCacheEntry(
+ kCMAKE_PLATFORM_INFO_INITIALIZED, "1",
+ "Platform information initialized", cmStateEnums::INTERNAL);
+ }
+
// find and make sure CMAKE_MAKE_PROGRAM is defined
if (!this->FindMakeProgram(mf)) {
return;