summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-05-22 16:39:01 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-05-22 16:39:27 (GMT)
commitfc29c5f1bf11d018278a08ae35e2672955f9871b (patch)
tree0eb0a180f39d03da8e12626091a4a9b46083511f /Source
parent8ce4e76dbf068779c2664c28142eead093f29edf (diff)
parent8c066045ec02cdfc7396a20b842838ae87610512 (diff)
downloadCMake-fc29c5f1bf11d018278a08ae35e2672955f9871b.zip
CMake-fc29c5f1bf11d018278a08ae35e2672955f9871b.tar.gz
CMake-fc29c5f1bf11d018278a08ae35e2672955f9871b.tar.bz2
Merge topic 'minor-refactoring'
8c066045ec Source: Improve some code readability and efficiency f64a774b49 Source: Reuse some existing variable declarations Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8492
Diffstat (limited to 'Source')
-rw-r--r--Source/cmExternalMakefileProjectGenerator.cxx13
-rw-r--r--Source/cmMessenger.cxx53
-rw-r--r--Source/cmState.cxx12
-rw-r--r--Source/cmake.cxx10
4 files changed, 37 insertions, 51 deletions
diff --git a/Source/cmExternalMakefileProjectGenerator.cxx b/Source/cmExternalMakefileProjectGenerator.cxx
index 5895d66..5fecb35 100644
--- a/Source/cmExternalMakefileProjectGenerator.cxx
+++ b/Source/cmExternalMakefileProjectGenerator.cxx
@@ -17,14 +17,13 @@ void cmExternalMakefileProjectGenerator::EnableLanguage(
std::string cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
const std::string& globalGenerator, const std::string& extraGenerator)
{
- std::string fullName;
- if (!globalGenerator.empty()) {
- if (!extraGenerator.empty()) {
- fullName = cmStrCat(extraGenerator, " - ");
- }
- fullName += globalGenerator;
+ if (globalGenerator.empty()) {
+ return {};
}
- return fullName;
+ if (extraGenerator.empty()) {
+ return globalGenerator;
+ }
+ return cmStrCat(extraGenerator, " - ", globalGenerator);
}
bool cmExternalMakefileProjectGenerator::Open(
diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx
index ff513be..7de8936 100644
--- a/Source/cmMessenger.cxx
+++ b/Source/cmMessenger.cxx
@@ -18,51 +18,38 @@
MessageType cmMessenger::ConvertMessageType(MessageType t) const
{
- bool warningsAsErrors;
-
if (t == MessageType::AUTHOR_WARNING || t == MessageType::AUTHOR_ERROR) {
- warningsAsErrors = this->GetDevWarningsAsErrors();
- if (warningsAsErrors && t == MessageType::AUTHOR_WARNING) {
- t = MessageType::AUTHOR_ERROR;
- } else if (!warningsAsErrors && t == MessageType::AUTHOR_ERROR) {
- t = MessageType::AUTHOR_WARNING;
+ if (this->GetDevWarningsAsErrors()) {
+ return MessageType::AUTHOR_ERROR;
}
- } else if (t == MessageType::DEPRECATION_WARNING ||
- t == MessageType::DEPRECATION_ERROR) {
- warningsAsErrors = this->GetDeprecatedWarningsAsErrors();
- if (warningsAsErrors && t == MessageType::DEPRECATION_WARNING) {
- t = MessageType::DEPRECATION_ERROR;
- } else if (!warningsAsErrors && t == MessageType::DEPRECATION_ERROR) {
- t = MessageType::DEPRECATION_WARNING;
+ return MessageType::AUTHOR_WARNING;
+ }
+ if (t == MessageType::DEPRECATION_WARNING ||
+ t == MessageType::DEPRECATION_ERROR) {
+ if (this->GetDeprecatedWarningsAsErrors()) {
+ return MessageType::DEPRECATION_ERROR;
}
+ return MessageType::DEPRECATION_WARNING;
}
-
return t;
}
bool cmMessenger::IsMessageTypeVisible(MessageType t) const
{
- bool isVisible = true;
-
if (t == MessageType::DEPRECATION_ERROR) {
- if (!this->GetDeprecatedWarningsAsErrors()) {
- isVisible = false;
- }
- } else if (t == MessageType::DEPRECATION_WARNING) {
- if (this->GetSuppressDeprecatedWarnings()) {
- isVisible = false;
- }
- } else if (t == MessageType::AUTHOR_ERROR) {
- if (!this->GetDevWarningsAsErrors()) {
- isVisible = false;
- }
- } else if (t == MessageType::AUTHOR_WARNING) {
- if (this->GetSuppressDevWarnings()) {
- isVisible = false;
- }
+ return this->GetDeprecatedWarningsAsErrors();
+ }
+ if (t == MessageType::DEPRECATION_WARNING) {
+ return !this->GetSuppressDeprecatedWarnings();
+ }
+ if (t == MessageType::AUTHOR_ERROR) {
+ return this->GetDevWarningsAsErrors();
+ }
+ if (t == MessageType::AUTHOR_WARNING) {
+ return !this->GetSuppressDevWarnings();
}
- return isVisible;
+ return true;
}
static bool printMessagePreamble(MessageType t, std::ostream& msg)
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index f12f91f..bbafc92 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -101,11 +101,13 @@ cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(
bool cmState::StringToCacheEntryType(const std::string& s,
cmStateEnums::CacheEntryType& type)
{
- for (size_t i = 0; i < cmCacheEntryTypes.size(); ++i) {
- if (s == cmCacheEntryTypes[i]) {
- type = static_cast<cmStateEnums::CacheEntryType>(i);
- return true;
- }
+ // NOLINTNEXTLINE(readability-qualified-auto)
+ auto const entry =
+ std::find(cmCacheEntryTypes.begin(), cmCacheEntryTypes.end(), s);
+ if (entry != cmCacheEntryTypes.end()) {
+ type = static_cast<cmStateEnums::CacheEntryType>(
+ entry - cmCacheEntryTypes.begin());
+ return true;
}
return false;
}
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 0fd7461..7b13552 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -2138,12 +2138,10 @@ int cmake::DoPreConfigureChecks()
std::string cacheStart =
cmStrCat(*this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"),
"/CMakeLists.txt");
- std::string currentStart =
- cmStrCat(this->GetHomeDirectory(), "/CMakeLists.txt");
- if (!cmSystemTools::SameFile(cacheStart, currentStart)) {
+ if (!cmSystemTools::SameFile(cacheStart, srcList)) {
std::string message =
- cmStrCat("The source \"", currentStart,
- "\" does not match the source \"", cacheStart,
+ cmStrCat("The source \"", srcList, "\" does not match the source \"",
+ cacheStart,
"\" used to generate cache. Re-run cmake with a different "
"source directory.");
cmSystemTools::Error(message);
@@ -2380,7 +2378,7 @@ int cmake::ActualConfigure()
return -2;
}
}
- if (!this->State->GetInitializedCacheValue("CMAKE_GENERATOR")) {
+ if (!genName) {
this->AddCacheEntry("CMAKE_GENERATOR", this->GlobalGenerator->GetName(),
"Name of generator.", cmStateEnums::INTERNAL);
this->AddCacheEntry(