summaryrefslogtreecommitdiffstats
path: root/Source/CPack/cmCPackGenerator.cxx
diff options
context:
space:
mode:
authorDeniz Bahadir <deniz@code.bahadir.email>2024-04-24 09:08:32 (GMT)
committerDeniz Bahadir <deniz@code.bahadir.email>2024-04-24 09:08:32 (GMT)
commit60f5118c7b8c037b79e7f8595c75a75c59cc5aa9 (patch)
treec6ab9a286aa76cc9ff8eae1361368aaad714bda4 /Source/CPack/cmCPackGenerator.cxx
parent30fd6df0b175c697f448df72ef82459e55d4ec52 (diff)
downloadCMake-60f5118c7b8c037b79e7f8595c75a75c59cc5aa9.zip
CMake-60f5118c7b8c037b79e7f8595c75a75c59cc5aa9.tar.gz
CMake-60f5118c7b8c037b79e7f8595c75a75c59cc5aa9.tar.bz2
cmCPackGenerator: Handle CPACK_TEMPORARY_[INSTALL]_DIRECTORY properly
The variable `CPACK_TEMPORARY_DIRECTORY` is an internal variable that is required for proper packaging. Historically, a second variable `CPACK_TEMPORARY_INSTALL_DIRECTORY` existed as well which had the same purpose. Both variables had to be set to the same value. Otherwise, CPack would not succeed with packaging. In order to ease CPack's usage, the variable `CPACK_TEMPORARY_INSTALL_DIRECTORY` is now no longer used. However, as it cannot be guaranteed that neither of these two (internal) variables have been used in the wild, some mechanism was introduced to preserve backwards-compatibility: If one of these variables is set, the other variable will be set to the same value. If, however, both are set to different values, CPack still fails but with an explicit error-message. Fixes: #25046
Diffstat (limited to 'Source/CPack/cmCPackGenerator.cxx')
-rw-r--r--Source/CPack/cmCPackGenerator.cxx58
1 files changed, 56 insertions, 2 deletions
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index b7786d3..6889656 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -187,7 +187,7 @@ int cmCPackGenerator::InstallProject()
this->CleanTemporaryDirectory();
std::string bareTempInstallDirectory =
- this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
+ this->GetOption("CPACK_TEMPORARY_DIRECTORY");
std::string tempInstallDirectoryStr = bareTempInstallDirectory;
bool setDestDir = this->GetOption("CPACK_SET_DESTDIR").IsOn() ||
cmIsInternallyOn(this->GetOption("CPACK_SET_DESTDIR"));
@@ -1218,6 +1218,60 @@ int cmCPackGenerator::Initialize(const std::string& name, cmMakefile* mf)
// it, the default value should be:
this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
+ // Special handling for CPACK_TEMPORARY[_INSTALL]_DIRECTORY.
+ // Note: Make sure that if only one of these variables is already set, the
+ // other will be set to the same value. If they are set to different
+ // values, however, we cannot proceed.
+ cmValue val1 =
+ this->MakefileMap->GetDefinition("CPACK_TEMPORARY_INSTALL_DIRECTORY");
+ cmValue val2 = this->MakefileMap->GetDefinition("CPACK_TEMPORARY_DIRECTORY");
+ if (val1 != val2) {
+ // One variable is set but not the other?
+ // Then set the other variable to the same value (even if it is invalid).
+ if (val1.Get() != nullptr && val2.Get() == nullptr) {
+ cmCPackLogger(cmCPackLog::LOG_WARNING,
+ "Variable CPACK_TEMPORARY_INSTALL_DIRECTORY is set, which "
+ "is not recommended. For backwards-compatibility we will "
+ "also set CPACK_TEMPORARY_DIRECTORY to the same value and "
+ "proceed. However, better set neither of them!"
+ << std::endl);
+ this->MakefileMap->AddDefinition("CPACK_TEMPORARY_DIRECTORY", val1);
+ } else if (val1.Get() == nullptr && val2.Get() != nullptr) {
+ cmCPackLogger(
+ cmCPackLog::LOG_WARNING,
+ "Variable CPACK_TEMPORARY_DIRECTORY is set, which is not recommended."
+ << std::endl);
+ cmCPackLogger(
+ cmCPackLog::LOG_DEBUG,
+ "For backwards-compatibility we will set "
+ "CPACK_TEMPORARY_INSTALL_DIRECTORY to the same value as "
+ "CPACK_TEMPORARY_DIRECTORY. However, better set neither of them!"
+ << std::endl);
+ this->MakefileMap->AddDefinition("CPACK_TEMPORARY_INSTALL_DIRECTORY",
+ val2);
+ } else {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "CPACK_TEMPORARY_INSTALL_DIRECTORY is already set to: "
+ << val1 << std::endl);
+ cmCPackLogger(
+ cmCPackLog::LOG_VERBOSE,
+ "CPACK_TEMPORARY_DIRECTORY is already set to: " << val2 << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Variables CPACK_TEMPORARY_DIRECTORY and "
+ "CPACK_TEMPORARY_INSTALL_DIRECTORY are both set but to "
+ "different values. This is not supported!"
+ << std::endl);
+ return 0;
+ }
+ } else if (val1.Get() != nullptr && val2.Get() != nullptr) {
+ cmCPackLogger(cmCPackLog::LOG_WARNING,
+ "Variables CPACK_TEMPORARY_DIRECTORY and "
+ "CPACK_TEMPORARY_INSTALL_DIRECTORY are both set. Because "
+ "they are set to the same value we can still proceed. "
+ "However, better set neither of them!"
+ << std::endl);
+ }
+
return result;
}
@@ -1356,7 +1410,7 @@ bool cmCPackGenerator::ConfigureFile(const std::string& inName,
int cmCPackGenerator::CleanTemporaryDirectory()
{
std::string tempInstallDirectory =
- this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
+ this->GetOption("CPACK_TEMPORARY_DIRECTORY");
if (cmsys::SystemTools::FileExists(tempInstallDirectory)) {
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
"- Clean temporary : " << tempInstallDirectory << std::endl);