Browse Source

cmMessenger: Decouple from cmState

Bruno Manganelli 7 years ago
parent
commit
8a803d784b
3 changed files with 61 additions and 44 deletions
  1. 0 34
      Source/cmMessenger.cxx
  2. 31 9
      Source/cmMessenger.h
  3. 30 1
      Source/cmake.cxx

+ 0 - 34
Source/cmMessenger.cxx

@@ -4,7 +4,6 @@
 
 #include "cmAlgorithms.h"
 #include "cmDocumentationFormatter.h"
-#include "cmState.h"
 #include "cmSystemTools.h"
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -131,11 +130,6 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
   }
 }
 
-cmMessenger::cmMessenger(cmState* state)
-  : State(state)
-{
-}
-
 void cmMessenger::IssueMessage(cmake::MessageType t, const std::string& text,
                                const cmListFileBacktrace& backtrace) const
 {
@@ -173,31 +167,3 @@ void cmMessenger::DisplayMessage(cmake::MessageType t, const std::string& text,
 
   displayMessage(t, msg);
 }
-
-bool cmMessenger::GetSuppressDevWarnings() const
-{
-  const char* cacheEntryValue =
-    this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
-  return cmSystemTools::IsOn(cacheEntryValue);
-}
-
-bool cmMessenger::GetSuppressDeprecatedWarnings() const
-{
-  const char* cacheEntryValue =
-    this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED");
-  return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
-}
-
-bool cmMessenger::GetDevWarningsAsErrors() const
-{
-  const char* cacheEntryValue =
-    this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS");
-  return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
-}
-
-bool cmMessenger::GetDeprecatedWarningsAsErrors() const
-{
-  const char* cacheEntryValue =
-    this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
-  return cmSystemTools::IsOn(cacheEntryValue);
-}

+ 31 - 9
Source/cmMessenger.h

@@ -10,13 +10,9 @@
 
 #include <string>
 
-class cmState;
-
 class cmMessenger
 {
 public:
-  cmMessenger(cmState* state);
-
   void IssueMessage(
     cmake::MessageType t, std::string const& text,
     cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
@@ -24,16 +20,42 @@ public:
   void DisplayMessage(cmake::MessageType t, std::string const& text,
                       cmListFileBacktrace const& backtrace) const;
 
-  bool GetSuppressDevWarnings() const;
-  bool GetSuppressDeprecatedWarnings() const;
-  bool GetDevWarningsAsErrors() const;
-  bool GetDeprecatedWarningsAsErrors() const;
+  void SetSuppressDevWarnings(bool suppress)
+  {
+    this->SuppressDevWarnings = suppress;
+  }
+  void SetSuppressDeprecatedWarnings(bool suppress)
+  {
+    this->SuppressDeprecatedWarnings = suppress;
+  }
+  void SetDevWarningsAsErrors(bool error)
+  {
+    this->DevWarningsAsErrors = error;
+  }
+  void SetDeprecatedWarningsAsErrors(bool error)
+  {
+    this->DeprecatedWarningsAsErrors = error;
+  }
+
+  bool GetSuppressDevWarnings() const { return this->SuppressDevWarnings; }
+  bool GetSuppressDeprecatedWarnings() const
+  {
+    return this->SuppressDeprecatedWarnings;
+  }
+  bool GetDevWarningsAsErrors() const { return this->DevWarningsAsErrors; }
+  bool GetDeprecatedWarningsAsErrors() const
+  {
+    return this->DeprecatedWarningsAsErrors;
+  }
 
 private:
   bool IsMessageTypeVisible(cmake::MessageType t) const;
   cmake::MessageType ConvertMessageType(cmake::MessageType t) const;
 
-  cmState* State;
+  bool SuppressDevWarnings = false;
+  bool SuppressDeprecatedWarnings = false;
+  bool DevWarningsAsErrors = false;
+  bool DeprecatedWarningsAsErrors = false;
 };
 
 #endif

+ 30 - 1
Source/cmake.cxx

@@ -140,7 +140,7 @@ cmake::cmake(Role role)
 
   this->State = new cmState;
   this->CurrentSnapshot = this->State->CreateBaseSnapshot();
-  this->Messenger = new cmMessenger(this->State);
+  this->Messenger = new cmMessenger;
 
 #ifdef __APPLE__
   struct rlimit rlp;
@@ -1299,6 +1299,23 @@ int cmake::Configure()
     }
   }
 
+  // Cache variables may have already been set by a previous invocation,
+  // so we cannot rely on command line options alone. Always ensure our
+  // messenger is in sync with the cache.
+  const char* value = this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED");
+  this->Messenger->SetSuppressDeprecatedWarnings(value &&
+                                                 cmSystemTools::IsOff(value));
+
+  value = this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
+  this->Messenger->SetDeprecatedWarningsAsErrors(cmSystemTools::IsOn(value));
+
+  value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
+  this->Messenger->SetSuppressDevWarnings(cmSystemTools::IsOn(value));
+
+  value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS");
+  this->Messenger->SetDevWarningsAsErrors(value &&
+                                          cmSystemTools::IsOff(value));
+
   int ret = this->ActualConfigure();
   const char* delCacheVars =
     this->State->GetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
@@ -1691,6 +1708,18 @@ void cmake::AddCacheEntry(const std::string& key, const char* value,
   this->State->AddCacheEntry(key, value, helpString,
                              cmStateEnums::CacheEntryType(type));
   this->UnwatchUnusedCli(key);
+
+  if (key == "CMAKE_WARN_DEPRECATED") {
+    this->Messenger->SetSuppressDeprecatedWarnings(
+      value && cmSystemTools::IsOff(value));
+  } else if (key == "CMAKE_ERROR_DEPRECATED") {
+    this->Messenger->SetDeprecatedWarningsAsErrors(cmSystemTools::IsOn(value));
+  } else if (key == "CMAKE_SUPPRESS_DEVELOPER_WARNINGS") {
+    this->Messenger->SetSuppressDevWarnings(cmSystemTools::IsOn(value));
+  } else if (key == "CMAKE_SUPPRESS_DEVELOPER_ERRORS") {
+    this->Messenger->SetDevWarningsAsErrors(value &&
+                                            cmSystemTools::IsOff(value));
+  }
 }
 
 bool cmake::DoWriteGlobVerifyTarget() const