summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x.gitlab/ci/docker/fedora34/install_deps.sh1
-rw-r--r--.gitlab/ci/env_fedora34_makefiles.cmake2
-rw-r--r--.gitlab/os-linux.yml2
-rw-r--r--Help/command/set.rst10
-rw-r--r--Help/manual/cmake-policies.7.rst1
-rw-r--r--Help/policy/CMP0126.rst20
-rw-r--r--Help/release/dev/message-color.rst4
-rw-r--r--Help/release/dev/set-cache-variable.rst5
-rw-r--r--Modules/ExternalProject.cmake8
-rw-r--r--Source/CMakeLists.txt1
-rw-r--r--Source/CMakeVersion.cmake2
-rw-r--r--Source/CTest/cmCTestBuildAndTestHandler.cxx4
-rw-r--r--Source/CursesDialog/ccmake.cxx5
-rw-r--r--Source/QtDialog/QCMake.cxx5
-rw-r--r--Source/cmFindBase.cxx35
-rw-r--r--Source/cmFindPackageCommand.cxx5
-rw-r--r--Source/cmGeneratorTarget.cxx29
-rw-r--r--Source/cmInstallSubdirectoryGenerator.cxx6
-rw-r--r--Source/cmInstallSubdirectoryGenerator.h1
-rw-r--r--Source/cmMakefile.cxx10
-rw-r--r--Source/cmMessageMetadata.h11
-rw-r--r--Source/cmMessenger.cxx26
-rw-r--r--Source/cmOptionCommand.cxx7
-rw-r--r--Source/cmPolicies.h5
-rw-r--r--Source/cmSystemTools.cxx10
-rw-r--r--Source/cmSystemTools.h6
-rw-r--r--Source/cmakemain.cxx27
-rw-r--r--Tests/RunCMake/CMP0126/CMP0126-NEW.cmake28
-rw-r--r--Tests/RunCMake/CMP0126/CMP0126-NEW_CL.cmake9
-rw-r--r--Tests/RunCMake/CMP0126/CMP0126-OLD.cmake25
-rw-r--r--Tests/RunCMake/CMP0126/CMP0126-OLD_CL.cmake9
-rw-r--r--Tests/RunCMake/CMP0126/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0126/RunCMakeTest.cmake6
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/Framework/ImportedFrameworkTest-build-stdout.txt1
-rw-r--r--Tests/RunCMake/Framework/ImportedFrameworkTest.cmake10
-rw-r--r--Tests/RunCMake/Framework/RunCMakeTest.cmake12
-rw-r--r--Tests/RunCMake/add_subdirectory/CMP0082-ExcludeFromAll/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/add_subdirectory/CMP0082-NEW.cmake2
-rw-r--r--Tests/RunCMake/add_subdirectory/CMP0082-OLD.cmake2
-rw-r--r--Tests/RunCMake/add_subdirectory/CMP0082-WARN.cmake2
41 files changed, 309 insertions, 50 deletions
diff --git a/.gitlab/ci/docker/fedora34/install_deps.sh b/.gitlab/ci/docker/fedora34/install_deps.sh
index ece0666..dfd7db8 100755
--- a/.gitlab/ci/docker/fedora34/install_deps.sh
+++ b/.gitlab/ci/docker/fedora34/install_deps.sh
@@ -68,6 +68,7 @@ dnf install --setopt=install_weak_deps=False -y \
libuv-devel \
libxml2-devel \
libxslt-devel \
+ mpich-devel \
openmpi-devel \
patch \
perl \
diff --git a/.gitlab/ci/env_fedora34_makefiles.cmake b/.gitlab/ci/env_fedora34_makefiles.cmake
index 1d0efa7..aa84e23 100644
--- a/.gitlab/ci/env_fedora34_makefiles.cmake
+++ b/.gitlab/ci/env_fedora34_makefiles.cmake
@@ -1,2 +1,2 @@
set(ENV{MY_RUBY_HOME} "/usr/local/rvm/rubies/ruby-2.7.0")
-set(ENV{PATH} "/usr/lib64/openmpi/bin:$ENV{PATH}")
+set(ENV{PATH} "/usr/lib64/mpich/bin:$ENV{PATH}")
diff --git a/.gitlab/os-linux.yml b/.gitlab/os-linux.yml
index 1bf4098..dcaa643 100644
--- a/.gitlab/os-linux.yml
+++ b/.gitlab/os-linux.yml
@@ -69,7 +69,7 @@
### Fedora
.fedora34:
- image: "kitware/cmake:ci-fedora34-x86_64-2021-05-10"
+ image: "kitware/cmake:ci-fedora34-x86_64-2021-05-21"
variables:
GIT_CLONE_PATH: "$CI_BUILDS_DIR/cmake ci/long file name for testing purposes"
diff --git a/Help/command/set.rst b/Help/command/set.rst
index c0e02e2..af862e4 100644
--- a/Help/command/set.rst
+++ b/Help/command/set.rst
@@ -68,9 +68,13 @@ users.
If the cache entry does not exist prior to the call or the ``FORCE``
option is given then the cache entry will be set to the given value.
-Furthermore, any normal variable binding in the current scope will
-be removed to expose the newly cached value to any immediately
-following evaluation.
+
+.. note::
+
+ The content of the cache variable will not be directly accessible if a normal
+ variable of the same name already exists (see :ref:`rules of variable
+ evaluation <CMake Language Variables>`). If policy :policy:`CMP0126` is set
+ to ``OLD``, any normal variable binding in the current scope will be removed.
It is possible for the cache entry to exist prior to the call but
have no type set if it was created on the :manual:`cmake(1)` command
diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index 62ccb01..b9e3d45 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.21
.. toctree::
:maxdepth: 1
+ CMP0126: set(CACHE) does not remove a normal variable of the same name. </policy/CMP0126>
CMP0125: find_(path|file|library|program) have consistent behavior for cache variables. </policy/CMP0125>
CMP0124: foreach() loop variables are only available in the loop scope. </policy/CMP0124>
CMP0123: ARMClang cpu/arch compile and link flags must be set explicitly. </policy/CMP0123>
diff --git a/Help/policy/CMP0126.rst b/Help/policy/CMP0126.rst
new file mode 100644
index 0000000..4c8e928
--- /dev/null
+++ b/Help/policy/CMP0126.rst
@@ -0,0 +1,20 @@
+CMP0126
+-------
+
+.. versionadded:: 3.21
+
+The :command:`set(CACHE)` does not remove a normal variable of the same name.
+
+Starting with CMake 3.21, the :command:`set(CACHE)` does not remove, in the
+current scope, any normal variable with the same name.
+
+The ``OLD`` behavior for this policy is to have the :command:`set(CACHE)`
+command removing the normal variable of the same name, if any. The ``NEW``
+behavior for this policy is to keep the normal variable of the same name.
+
+This policy was introduced in CMake version 3.21. Use the
+:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
+Unlike many policies, CMake version |release| does *not* warn when the policy
+is not set and simply uses ``OLD`` behavior.
+
+.. include:: DEPRECATED.txt
diff --git a/Help/release/dev/message-color.rst b/Help/release/dev/message-color.rst
new file mode 100644
index 0000000..4acf15e
--- /dev/null
+++ b/Help/release/dev/message-color.rst
@@ -0,0 +1,4 @@
+message-color
+-------------
+
+* Messages printed to a terminal now may be colored by message type.
diff --git a/Help/release/dev/set-cache-variable.rst b/Help/release/dev/set-cache-variable.rst
new file mode 100644
index 0000000..a96242c
--- /dev/null
+++ b/Help/release/dev/set-cache-variable.rst
@@ -0,0 +1,5 @@
+set-cache-variable
+------------------
+
+* The :command:`set(CACHE)` command no longer removes a normal variable of the
+ same name, if any. See policy :policy:`CMP0126`.
diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index 026d1fc..9e25bee 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -2680,9 +2680,11 @@ function(_ep_add_download_command name)
get_property(git_progress TARGET ${name} PROPERTY _EP_GIT_PROGRESS)
get_property(git_config TARGET ${name} PROPERTY _EP_GIT_CONFIG)
- # Make checkouts quiet when checking out a git hash (this avoids the
- # very noisy detached head message)
- list(PREPEND git_config advice.detachedHead=false)
+ # If git supports it, make checkouts quiet when checking out a git hash.
+ # This avoids the very noisy detached head message.
+ if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 1.7.7)
+ list(PREPEND git_config advice.detachedHead=false)
+ endif()
# For the download step, and the git clone operation, only the repository
# should be recorded in a configured RepositoryInfo file. If the repo
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index c19c154..bd9e4c2 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -638,6 +638,7 @@ set(SRCS
cmMathCommand.h
cmMessageCommand.cxx
cmMessageCommand.h
+ cmMessageMetadata.h
cmOptionCommand.cxx
cmOptionCommand.h
cmOutputRequiredFilesCommand.cxx
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index fc19c77..e92c2a0 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,7 +1,7 @@
# CMake version number components.
set(CMake_VERSION_MAJOR 3)
set(CMake_VERSION_MINOR 20)
-set(CMake_VERSION_PATCH 20210521)
+set(CMake_VERSION_PATCH 20210525)
#set(CMake_VERSION_RC 0)
set(CMake_VERSION_IS_DIRTY 0)
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx
index a18cbb4..adfc8ef 100644
--- a/Source/CTest/cmCTestBuildAndTestHandler.cxx
+++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx
@@ -19,6 +19,8 @@
#include "cmWorkingDirectory.h"
#include "cmake.h"
+struct cmMessageMetadata;
+
cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
{
this->BuildTwoConfig = false;
@@ -125,7 +127,7 @@ public:
: CM(cm)
{
cmSystemTools::SetMessageCallback(
- [&s](const std::string& msg, const char* /*unused*/) {
+ [&s](const std::string& msg, const cmMessageMetadata& /* unused */) {
s += msg;
s += "\n";
});
diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx
index 85e256b..1ba45e5 100644
--- a/Source/CursesDialog/ccmake.cxx
+++ b/Source/CursesDialog/ccmake.cxx
@@ -19,6 +19,7 @@
#include "cmCursesStandardIncludes.h"
#include "cmDocumentation.h"
#include "cmDocumentationEntry.h" // IWYU pragma: keep
+#include "cmMessageMetadata.h"
#include "cmState.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -181,8 +182,8 @@ int main(int argc, char const* const* argv)
return msg;
};
cmSystemTools::SetMessageCallback(
- [&](const std::string& message, const char* title) {
- myform->AddError(cleanMessage(message), title);
+ [&](const std::string& message, const cmMessageMetadata& md) {
+ myform->AddError(cleanMessage(message), md.title);
});
cmSystemTools::SetStderrCallback([&](const std::string& message) {
myform->AddError(cleanMessage(message), "");
diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx
index a83622a..e6faef4 100644
--- a/Source/QtDialog/QCMake.cxx
+++ b/Source/QtDialog/QCMake.cxx
@@ -13,6 +13,7 @@
#include "cmExternalMakefileProjectGenerator.h"
#include "cmGlobalGenerator.h"
+#include "cmMessageMetadata.h"
#include "cmState.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -37,8 +38,8 @@ QCMake::QCMake(QObject* p)
cmSystemTools::SetRunCommandHideConsole(true);
cmSystemTools::SetMessageCallback(
- [this](std::string const& msg, const char* title) {
- this->messageCallback(msg, title);
+ [this](std::string const& msg, const cmMessageMetadata& md) {
+ this->messageCallback(msg, md.title);
});
cmSystemTools::SetStdoutCallback(
[this](std::string const& msg) { this->stdoutCallback(msg); });
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index 6296d06..c1281e3 100644
--- a/Source/cmFindBase.cxx
+++ b/Source/cmFindBase.cxx
@@ -357,11 +357,17 @@ void cmFindBase::NormalizeFindResult()
this->Makefile->GetCMakeInstance()->AddCacheEntry(
this->VariableName, value.c_str(), this->VariableDocumentation.c_str(),
this->VariableType);
- // if there was a definition then remove it
- // This is required to ensure same behavior as
- // cmMakefile::AddCacheDefinition.
- // See #22038 for problems raised by this behavior.
- this->Makefile->RemoveDefinition(this->VariableName);
+ if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) ==
+ cmPolicies::NEW) {
+ if (this->Makefile->IsNormalDefinitionSet(this->VariableName)) {
+ this->Makefile->AddDefinition(this->VariableName, value);
+ }
+ } else {
+ // if there was a definition then remove it
+ // This is required to ensure same behavior as
+ // cmMakefile::AddCacheDefinition.
+ this->Makefile->RemoveDefinition(this->VariableName);
+ }
}
} else {
// If the user specifies the entry on the command line without a
@@ -371,6 +377,14 @@ void cmFindBase::NormalizeFindResult()
this->Makefile->AddCacheDefinition(this->VariableName, "",
this->VariableDocumentation.c_str(),
this->VariableType);
+ if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) ==
+ cmPolicies::NEW &&
+ this->Makefile->IsNormalDefinitionSet(this->VariableName)) {
+ this->Makefile->AddDefinition(
+ this->VariableName,
+ *this->Makefile->GetCMakeInstance()->GetCacheDefinition(
+ this->VariableName));
+ }
}
}
}
@@ -379,17 +393,28 @@ void cmFindBase::StoreFindResult(const std::string& value)
{
bool force =
this->Makefile->GetPolicyStatus(cmPolicies::CMP0125) == cmPolicies::NEW;
+ bool updateNormalVariable =
+ this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) == cmPolicies::NEW;
if (!value.empty()) {
this->Makefile->AddCacheDefinition(this->VariableName, value,
this->VariableDocumentation.c_str(),
this->VariableType, force);
+ if (updateNormalVariable &&
+ this->Makefile->IsNormalDefinitionSet(this->VariableName)) {
+ this->Makefile->AddDefinition(this->VariableName, value);
+ }
return;
}
this->Makefile->AddCacheDefinition(
this->VariableName, cmStrCat(this->VariableName, "-NOTFOUND"),
this->VariableDocumentation.c_str(), this->VariableType, force);
+ if (updateNormalVariable &&
+ this->Makefile->IsNormalDefinitionSet(this->VariableName)) {
+ this->Makefile->AddDefinition(this->VariableName,
+ cmStrCat(this->VariableName, "-NOTFOUND"));
+ }
if (this->Required) {
this->Makefile->IssueMessage(
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 3719fe1..fba736e 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -1138,6 +1138,11 @@ bool cmFindPackageCommand::FindConfig()
// We force the value since we do not get here if it was already set.
this->Makefile->AddCacheDefinition(this->Variable, init, help.c_str(),
cmStateEnums::PATH, true);
+ if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) ==
+ cmPolicies::NEW &&
+ this->Makefile->IsNormalDefinitionSet(this->Variable)) {
+ this->Makefile->AddDefinition(this->Variable, init);
+ }
return found;
}
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index bbc0050..e2ec82a 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -52,6 +52,11 @@
class cmMessenger;
+namespace {
+const cmsys::RegularExpression FrameworkRegularExpression(
+ "^(.*/)?([^/]*)\\.framework/(.*)$");
+}
+
template <>
cmProp cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
cmGeneratorTarget const* tgt, cmMessenger* /* messenger */,
@@ -2257,8 +2262,16 @@ std::string cmGeneratorTarget::GetSOName(const std::string& config) const
return cmSystemTools::GetFilenameName(info->Location);
}
// Use the soname given if any.
+ if (this->IsFrameworkOnApple()) {
+ cmsys::RegularExpressionMatch match;
+ if (FrameworkRegularExpression.find(info->SOName.c_str(), match)) {
+ auto frameworkName = match.match(2);
+ auto fileName = match.match(3);
+ return cmStrCat(frameworkName, ".framework/", fileName);
+ }
+ }
if (cmHasLiteralPrefix(info->SOName, "@rpath/")) {
- return info->SOName.substr(6);
+ return info->SOName.substr(cmStrLen("@rpath/"));
}
return info->SOName;
}
@@ -6459,9 +6472,19 @@ std::string cmGeneratorTarget::GetDirectory(
const std::string& config, cmStateEnums::ArtifactType artifact) const
{
if (this->IsImported()) {
+ auto fullPath = this->Target->ImportedGetFullPath(config, artifact);
+ if (this->IsFrameworkOnApple()) {
+ cmsys::RegularExpressionMatch match;
+ if (FrameworkRegularExpression.find(fullPath.c_str(), match)) {
+ auto path = match.match(1);
+ if (!path.empty()) {
+ path.erase(path.length() - 1);
+ }
+ return path;
+ }
+ }
// Return the directory from which the target is imported.
- return cmSystemTools::GetFilenamePath(
- this->Target->ImportedGetFullPath(config, artifact));
+ return cmSystemTools::GetFilenamePath(fullPath);
}
if (OutputInfo const* info = this->GetOutputInfo(config)) {
// Return the directory in which the target will be built.
diff --git a/Source/cmInstallSubdirectoryGenerator.cxx b/Source/cmInstallSubdirectoryGenerator.cxx
index 0fcfa54..794694e 100644
--- a/Source/cmInstallSubdirectoryGenerator.cxx
+++ b/Source/cmInstallSubdirectoryGenerator.cxx
@@ -14,10 +14,10 @@
#include "cmSystemTools.h"
cmInstallSubdirectoryGenerator::cmInstallSubdirectoryGenerator(
- cmMakefile* makefile, std::string binaryDirectory, bool excludeFromAll,
+ cmMakefile* makefile, std::string binaryDirectory,
cmListFileBacktrace backtrace)
: cmInstallGenerator("", std::vector<std::string>(), "", MessageDefault,
- excludeFromAll, false, std::move(backtrace))
+ false, false, std::move(backtrace))
, Makefile(makefile)
, BinaryDirectory(std::move(binaryDirectory))
{
@@ -52,7 +52,7 @@ bool cmInstallSubdirectoryGenerator::Compute(cmLocalGenerator* lg)
void cmInstallSubdirectoryGenerator::GenerateScript(std::ostream& os)
{
- if (!this->ExcludeFromAll) {
+ if (!this->Makefile->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
cmPolicies::PolicyStatus status =
this->LocalGenerator->GetPolicyStatus(cmPolicies::CMP0082);
switch (status) {
diff --git a/Source/cmInstallSubdirectoryGenerator.h b/Source/cmInstallSubdirectoryGenerator.h
index 614cef9..f174d07 100644
--- a/Source/cmInstallSubdirectoryGenerator.h
+++ b/Source/cmInstallSubdirectoryGenerator.h
@@ -21,7 +21,6 @@ class cmInstallSubdirectoryGenerator : public cmInstallGenerator
public:
cmInstallSubdirectoryGenerator(cmMakefile* makefile,
std::string binaryDirectory,
- bool excludeFromAll,
cmListFileBacktrace backtrace);
~cmInstallSubdirectoryGenerator() override;
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 4ffd47b..ffe94ba 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1844,7 +1844,7 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
}
this->AddInstallGenerator(cm::make_unique<cmInstallSubdirectoryGenerator>(
- subMf, binPath, excludeFromAll, this->GetBacktrace()));
+ subMf, binPath, this->GetBacktrace()));
}
const std::string& cmMakefile::GetCurrentSourceDirectory() const
@@ -1962,10 +1962,10 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
}
}
this->GetCMakeInstance()->AddCacheEntry(name, value, doc, type);
- // if there was a definition then remove it
- // The method cmFindBase::NormalizeFindResult also apply same workflow.
- // See #22038 for problems raised by this behavior.
- this->StateSnapshot.RemoveDefinition(name);
+ if (this->GetPolicyStatus(cmPolicies::CMP0126) != cmPolicies::NEW) {
+ // if there was a definition then remove it
+ this->StateSnapshot.RemoveDefinition(name);
+ }
}
void cmMakefile::MarkVariableAsUsed(const std::string& var)
diff --git a/Source/cmMessageMetadata.h b/Source/cmMessageMetadata.h
new file mode 100644
index 0000000..7b56fae
--- /dev/null
+++ b/Source/cmMessageMetadata.h
@@ -0,0 +1,11 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#pragma once
+
+#include "cmsys/Terminal.h"
+
+struct cmMessageMetadata
+{
+ const char* title = nullptr;
+ int desiredColor = cmsysTerminal_Color_Normal;
+};
diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx
index af83478..1cb638a 100644
--- a/Source/cmMessenger.cxx
+++ b/Source/cmMessenger.cxx
@@ -3,6 +3,7 @@
#include "cmMessenger.h"
#include "cmDocumentationFormatter.h"
+#include "cmMessageMetadata.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -12,6 +13,8 @@
#include <sstream>
+#include "cmsys/Terminal.h"
+
MessageType cmMessenger::ConvertMessageType(MessageType t) const
{
bool warningsAsErrors;
@@ -84,6 +87,21 @@ static bool printMessagePreamble(MessageType t, std::ostream& msg)
return true;
}
+static int getMessageColor(MessageType t)
+{
+ switch (t) {
+ case MessageType::INTERNAL_ERROR:
+ case MessageType::FATAL_ERROR:
+ case MessageType::AUTHOR_ERROR:
+ return cmsysTerminal_Color_ForegroundRed;
+ case MessageType::AUTHOR_WARNING:
+ case MessageType::WARNING:
+ return cmsysTerminal_Color_ForegroundYellow;
+ default:
+ return cmsysTerminal_Color_Normal;
+ }
+}
+
void printMessageText(std::ostream& msg, std::string const& text)
{
msg << ":\n";
@@ -120,12 +138,16 @@ void displayMessage(MessageType t, std::ostringstream& msg)
#endif
// Output the message.
+ cmMessageMetadata md;
+ md.desiredColor = getMessageColor(t);
if (t == MessageType::FATAL_ERROR || t == MessageType::INTERNAL_ERROR ||
t == MessageType::DEPRECATION_ERROR || t == MessageType::AUTHOR_ERROR) {
cmSystemTools::SetErrorOccured();
- cmSystemTools::Message(msg.str(), "Error");
+ md.title = "Error";
+ cmSystemTools::Message(msg.str(), md);
} else {
- cmSystemTools::Message(msg.str(), "Warning");
+ md.title = "Warning";
+ cmSystemTools::Message(msg.str(), md);
}
}
diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx
index a58e2f8..bae67e0 100644
--- a/Source/cmOptionCommand.cxx
+++ b/Source/cmOptionCommand.cxx
@@ -68,6 +68,13 @@ bool cmOptionCommand(std::vector<std::string> const& args,
bool init = cmIsOn(initialValue);
status.GetMakefile().AddCacheDefinition(args[0], init ? "ON" : "OFF",
args[1].c_str(), cmStateEnums::BOOL);
+ if (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0077) !=
+ cmPolicies::NEW &&
+ status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0126) ==
+ cmPolicies::NEW) {
+ // if there was a definition then remove it
+ status.GetMakefile().GetStateSnapshot().RemoveDefinition(args[0]);
+ }
if (checkAndWarn) {
const auto* existsAfterSet =
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 3ebb17d..f7c0d25 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -376,7 +376,10 @@ class cmMakefile;
SELECT(POLICY, CMP0125, \
"find_(path|file|library|program) have consistent behavior for " \
"cache variables.", \
- 3, 21, 0, cmPolicies::WARN)
+ 3, 21, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0126, \
+ "set(CACHE) does not remove a normal variable of the same name.", 3, \
+ 21, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 2fba13f..9b81bf2 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -19,6 +19,7 @@
#include <cm3p/uv.h>
#include "cmDuration.h"
+#include "cmMessageMetadata.h"
#include "cmProcessOutput.h"
#include "cmRange.h"
#include "cmStringAlgorithms.h"
@@ -263,8 +264,15 @@ void cmSystemTools::Stdout(const std::string& s)
void cmSystemTools::Message(const std::string& m, const char* title)
{
+ cmMessageMetadata md;
+ md.title = title;
+ Message(m, md);
+}
+
+void cmSystemTools::Message(const std::string& m, const cmMessageMetadata& md)
+{
if (s_MessageCallback) {
- s_MessageCallback(m, title);
+ s_MessageCallback(m, md);
} else {
std::cerr << m << std::endl;
}
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 474f591..5c3b5a9 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -19,6 +19,8 @@
#include "cmDuration.h"
#include "cmProcessOutput.h"
+struct cmMessageMetadata;
+
/** \class cmSystemTools
* \brief A collection of useful functions for CMake.
*
@@ -40,7 +42,8 @@ public:
/** Map help document name to file name. */
static std::string HelpFileName(cm::string_view);
- using MessageCallback = std::function<void(const std::string&, const char*)>;
+ using MessageCallback =
+ std::function<void(const std::string&, const cmMessageMetadata&)>;
/**
* Set the function used by GUIs to display error messages
* Function gets passed: message as a const char*,
@@ -57,6 +60,7 @@ public:
* Display a message.
*/
static void Message(const std::string& m, const char* title = nullptr);
+ static void Message(const std::string& m, const cmMessageMetadata& md);
using OutputCallback = std::function<void(std::string const&)>;
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 997d855..d83183f 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -6,6 +6,7 @@
#include <algorithm>
#include <cassert>
#include <climits>
+#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
@@ -23,6 +24,7 @@
#include "cmDocumentationEntry.h" // IWYU pragma: keep
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageMetadata.h"
#include "cmProperty.h"
#include "cmState.h"
#include "cmStateTypes.h"
@@ -37,6 +39,7 @@
#endif
#include "cmsys/Encoding.hxx"
+#include "cmsys/Terminal.h"
namespace {
#ifndef CMAKE_BOOTSTRAP
@@ -147,10 +150,12 @@ std::string cmakemainGetStack(cmake* cm)
return msg;
}
-void cmakemainMessageCallback(const std::string& m, const char* /*unused*/,
- cmake* cm)
+void cmakemainMessageCallback(const std::string& m,
+ const cmMessageMetadata& md, cmake* cm)
{
- std::cerr << m << cmakemainGetStack(cm) << std::endl;
+ cmsysTerminal_cfprintf(md.desiredColor, stderr, "%s", m.c_str());
+ fflush(stderr); // stderr is buffered in some cases.
+ std::cerr << cmakemainGetStack(cm) << "\n";
}
void cmakemainProgressCallback(const std::string& m, float prog, cmake* cm)
@@ -343,8 +348,8 @@ int do_cmake(int ac, char const* const* av)
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cmSystemTools::SetMessageCallback(
- [&cm](const std::string& msg, const char* title) {
- cmakemainMessageCallback(msg, title, &cm);
+ [&cm](const std::string& msg, const cmMessageMetadata& md) {
+ cmakemainMessageCallback(msg, md, &cm);
});
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
@@ -626,8 +631,8 @@ int do_build(int ac, char const* const* av)
cmake cm(cmake::RoleInternal, cmState::Project);
cmSystemTools::SetMessageCallback(
- [&cm](const std::string& msg, const char* title) {
- cmakemainMessageCallback(msg, title, &cm);
+ [&cm](const std::string& msg, const cmMessageMetadata& md) {
+ cmakemainMessageCallback(msg, md, &cm);
});
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
@@ -859,8 +864,8 @@ int do_install(int ac, char const* const* av)
cmake cm(cmake::RoleScript, cmState::Script);
cmSystemTools::SetMessageCallback(
- [&cm](const std::string& msg, const char* title) {
- cmakemainMessageCallback(msg, title, &cm);
+ [&cm](const std::string& msg, const cmMessageMetadata& md) {
+ cmakemainMessageCallback(msg, md, &cm);
});
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
@@ -940,8 +945,8 @@ int do_open(int ac, char const* const* av)
cmake cm(cmake::RoleInternal, cmState::Unknown);
cmSystemTools::SetMessageCallback(
- [&cm](const std::string& msg, const char* title) {
- cmakemainMessageCallback(msg, title, &cm);
+ [&cm](const std::string& msg, const cmMessageMetadata& md) {
+ cmakemainMessageCallback(msg, md, &cm);
});
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
diff --git a/Tests/RunCMake/CMP0126/CMP0126-NEW.cmake b/Tests/RunCMake/CMP0126/CMP0126-NEW.cmake
new file mode 100644
index 0000000..2f8562b
--- /dev/null
+++ b/Tests/RunCMake/CMP0126/CMP0126-NEW.cmake
@@ -0,0 +1,28 @@
+
+# enforce policy CMP0125 to ensure predictable result of find_* commands
+cmake_policy(SET CMP0125 NEW)
+
+cmake_policy(SET CMP0126 NEW)
+
+set(VAR 1)
+set(VAR 2 CACHE STRING "")
+
+if (NOT VAR EQUAL 1)
+ message(FATAL_ERROR "normal variable does not exist anymore.")
+endif()
+
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/file.txt" "")
+set(VAR file.txt)
+set(VAR "" CACHE STRING "" FORCE)
+set_property(CACHE VAR PROPERTY TYPE UNINITIALIZED)
+
+find_file(VAR NAMES file.txt PATHS "${CMAKE_CURRENT_BINARY_DIR}")
+
+unset(VAR CACHE)
+if (NOT DEFINED VAR)
+ message(FATAL_ERROR "find_file: normal variable does not exist anymore.")
+endif()
+if (NOT VAR STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/file.txt")
+ message(FATAL_ERROR "find_file: failed to set normal variable.")
+endif()
diff --git a/Tests/RunCMake/CMP0126/CMP0126-NEW_CL.cmake b/Tests/RunCMake/CMP0126/CMP0126-NEW_CL.cmake
new file mode 100644
index 0000000..cfaa1e3
--- /dev/null
+++ b/Tests/RunCMake/CMP0126/CMP0126-NEW_CL.cmake
@@ -0,0 +1,9 @@
+
+cmake_policy(SET CMP0126 NEW)
+
+set(VAR 1)
+set(VAR 2 CACHE STRING "")
+
+if (NOT VAR EQUAL 1)
+ message(FATAL_ERROR "normal variable does not exist anymore.")
+endif()
diff --git a/Tests/RunCMake/CMP0126/CMP0126-OLD.cmake b/Tests/RunCMake/CMP0126/CMP0126-OLD.cmake
new file mode 100644
index 0000000..22a5037
--- /dev/null
+++ b/Tests/RunCMake/CMP0126/CMP0126-OLD.cmake
@@ -0,0 +1,25 @@
+
+# enforce policy CMP0125 to ensure predictable result of find_* commands
+cmake_policy(SET CMP0125 NEW)
+
+cmake_policy(SET CMP0126 OLD)
+
+set(VAR 1)
+set(VAR 2 CACHE STRING "")
+
+if (VAR EQUAL 1)
+ message(FATAL_ERROR "normal variable still exist.")
+endif()
+
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/file.txt" "")
+set(VAR file.txt)
+set(VAR "" CACHE STRING "" FORCE)
+set_property(CACHE VAR PROPERTY TYPE UNINITIALIZED)
+
+find_file(VAR NAMES file.txt PATHS "${CMAKE_CURRENT_BINARY_DIR}")
+
+unset(VAR CACHE)
+if (DEFINED VAR)
+ message(FATAL_ERROR "find_file: normal variable still exist.")
+endif()
diff --git a/Tests/RunCMake/CMP0126/CMP0126-OLD_CL.cmake b/Tests/RunCMake/CMP0126/CMP0126-OLD_CL.cmake
new file mode 100644
index 0000000..5d72a87
--- /dev/null
+++ b/Tests/RunCMake/CMP0126/CMP0126-OLD_CL.cmake
@@ -0,0 +1,9 @@
+
+cmake_policy(SET CMP0126 OLD)
+
+set(VAR 1)
+set(VAR 2 CACHE STRING "")
+
+if (NOT VAR EQUAL 3)
+ message(FATAL_ERROR "normal variable still exist.")
+endif()
diff --git a/Tests/RunCMake/CMP0126/CMakeLists.txt b/Tests/RunCMake/CMP0126/CMakeLists.txt
new file mode 100644
index 0000000..7cabeb6
--- /dev/null
+++ b/Tests/RunCMake/CMP0126/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.20)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0126/RunCMakeTest.cmake b/Tests/RunCMake/CMP0126/RunCMakeTest.cmake
new file mode 100644
index 0000000..ae988f4
--- /dev/null
+++ b/Tests/RunCMake/CMP0126/RunCMakeTest.cmake
@@ -0,0 +1,6 @@
+include(RunCMake)
+
+run_cmake(CMP0126-OLD)
+run_cmake_with_options(CMP0126-OLD_CL -DVAR=3)
+run_cmake(CMP0126-NEW)
+run_cmake_with_options(CMP0126-NEW_CL -DVAR=3)
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index afaeaef..14a7fa3 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -140,6 +140,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "(Linux|Darwin)")
add_RunCMake_test(CMP0125 -DCMAKE_SHARED_LIBRARY_PREFIX=${CMAKE_SHARED_LIBRARY_PREFIX}
-DCMAKE_SHARED_LIBRARY_SUFFIX=${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
+add_RunCMake_test(CMP0126)
# The test for Policy 65 requires the use of the
# CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode
diff --git a/Tests/RunCMake/Framework/ImportedFrameworkTest-build-stdout.txt b/Tests/RunCMake/Framework/ImportedFrameworkTest-build-stdout.txt
new file mode 100644
index 0000000..bd75ccd
--- /dev/null
+++ b/Tests/RunCMake/Framework/ImportedFrameworkTest-build-stdout.txt
@@ -0,0 +1 @@
+xxx/no/exist/fw\.framework/Versions/A/fwxxx
diff --git a/Tests/RunCMake/Framework/ImportedFrameworkTest.cmake b/Tests/RunCMake/Framework/ImportedFrameworkTest.cmake
new file mode 100644
index 0000000..42edaea
--- /dev/null
+++ b/Tests/RunCMake/Framework/ImportedFrameworkTest.cmake
@@ -0,0 +1,10 @@
+add_library(fw SHARED IMPORTED)
+set_target_properties(fw PROPERTIES
+ FRAMEWORK TRUE
+ IMPORTED_LOCATION "/no/exist/fw.framework/Versions/A/fw"
+ IMPORTED_SONAME "@rpath/fw.framework/Versions/A/fw"
+ )
+
+add_custom_target(print_fw ALL COMMAND
+ ${CMAKE_COMMAND} -E echo "xxx$<TARGET_SONAME_FILE:fw>xxx"
+ )
diff --git a/Tests/RunCMake/Framework/RunCMakeTest.cmake b/Tests/RunCMake/Framework/RunCMakeTest.cmake
index 6ee61a3..36eaf5c 100644
--- a/Tests/RunCMake/Framework/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Framework/RunCMakeTest.cmake
@@ -81,3 +81,15 @@ function(framework_multi_config_postfix_test)
endfunction()
framework_multi_config_postfix_test()
+
+function(imported_framework_test)
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/ImportedFrameworkTest-build")
+ set(RunCMake_TEST_NO_CLEAN 1)
+
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(ImportedFrameworkTest)
+ run_cmake_command(ImportedFrameworkTest-build ${CMAKE_COMMAND} --build .)
+endfunction()
+
+imported_framework_test()
diff --git a/Tests/RunCMake/add_subdirectory/CMP0082-ExcludeFromAll/CMakeLists.txt b/Tests/RunCMake/add_subdirectory/CMP0082-ExcludeFromAll/CMakeLists.txt
index 1bd7f49..32bb1a9 100644
--- a/Tests/RunCMake/add_subdirectory/CMP0082-ExcludeFromAll/CMakeLists.txt
+++ b/Tests/RunCMake/add_subdirectory/CMP0082-ExcludeFromAll/CMakeLists.txt
@@ -1 +1,2 @@
install(CODE "message(STATUS \"exclude\")")
+set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL TRUE)
diff --git a/Tests/RunCMake/add_subdirectory/CMP0082-NEW.cmake b/Tests/RunCMake/add_subdirectory/CMP0082-NEW.cmake
index 56c1b81..8ebf21b 100644
--- a/Tests/RunCMake/add_subdirectory/CMP0082-NEW.cmake
+++ b/Tests/RunCMake/add_subdirectory/CMP0082-NEW.cmake
@@ -1,3 +1,3 @@
add_subdirectory(CMP0082)
-add_subdirectory(CMP0082-ExcludeFromAll EXCLUDE_FROM_ALL)
+add_subdirectory(CMP0082-ExcludeFromAll)
install(CODE "message(STATUS \"top\")")
diff --git a/Tests/RunCMake/add_subdirectory/CMP0082-OLD.cmake b/Tests/RunCMake/add_subdirectory/CMP0082-OLD.cmake
index 56c1b81..8ebf21b 100644
--- a/Tests/RunCMake/add_subdirectory/CMP0082-OLD.cmake
+++ b/Tests/RunCMake/add_subdirectory/CMP0082-OLD.cmake
@@ -1,3 +1,3 @@
add_subdirectory(CMP0082)
-add_subdirectory(CMP0082-ExcludeFromAll EXCLUDE_FROM_ALL)
+add_subdirectory(CMP0082-ExcludeFromAll)
install(CODE "message(STATUS \"top\")")
diff --git a/Tests/RunCMake/add_subdirectory/CMP0082-WARN.cmake b/Tests/RunCMake/add_subdirectory/CMP0082-WARN.cmake
index 56c1b81..8ebf21b 100644
--- a/Tests/RunCMake/add_subdirectory/CMP0082-WARN.cmake
+++ b/Tests/RunCMake/add_subdirectory/CMP0082-WARN.cmake
@@ -1,3 +1,3 @@
add_subdirectory(CMP0082)
-add_subdirectory(CMP0082-ExcludeFromAll EXCLUDE_FROM_ALL)
+add_subdirectory(CMP0082-ExcludeFromAll)
install(CODE "message(STATUS \"top\")")