summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMichael Scott <michael.scott250@gmail.com>2015-12-21 21:39:27 (GMT)
committerBrad King <brad.king@kitware.com>2016-01-12 19:02:51 (GMT)
commit28f2d750edaf6ee1af660d3a0ae6792c65c47997 (patch)
tree3e22c760e48a58d34c9e337c9ffef0f6295f0ebe /Source
parentb5009720d3020021f189570d72c099963795a5c5 (diff)
downloadCMake-28f2d750edaf6ee1af660d3a0ae6792c65c47997.zip
CMake-28f2d750edaf6ee1af660d3a0ae6792c65c47997.tar.gz
CMake-28f2d750edaf6ee1af660d3a0ae6792c65c47997.tar.bz2
Add -Werror and -Wno-error command-line options
Expand the -W set of cmake options to include support for the -Werror and -Wno-error format, which is used to control upgrading and downgrading warning and error messages. Implement support for these new formats for the dev and deprecated message types. Add tests and updated documentation for new options.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmMessageCommand.cxx29
-rw-r--r--Source/cmake.cxx200
-rw-r--r--Source/cmake.h42
3 files changed, 245 insertions, 26 deletions
diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx
index 8272eb0..1c67cea 100644
--- a/Source/cmMessageCommand.cxx
+++ b/Source/cmMessageCommand.cxx
@@ -25,6 +25,7 @@ bool cmMessageCommand
cmake::MessageType type = cmake::MESSAGE;
bool status = false;
bool fatal = false;
+ cmake* cm = this->Makefile->GetCMakeInstance();
if (*i == "SEND_ERROR")
{
type = cmake::FATAL_ERROR;
@@ -43,15 +44,19 @@ bool cmMessageCommand
}
else if (*i == "AUTHOR_WARNING")
{
- if (this->Makefile->GetCMakeInstance()->GetSuppressDevWarnings(
- this->Makefile))
+ if (cm->GetDevWarningsAsErrors(this->Makefile))
{
- return true;
+ fatal = true;
+ type = cmake::AUTHOR_ERROR;
}
- else
+ else if (!cm->GetSuppressDevWarnings(this->Makefile))
{
type = cmake::AUTHOR_WARNING;
}
+ else
+ {
+ return true;
+ }
++i;
}
else if (*i == "STATUS")
@@ -61,22 +66,18 @@ bool cmMessageCommand
}
else if (*i == "DEPRECATION")
{
- if (this->Makefile->IsOn("CMAKE_ERROR_DEPRECATED"))
+ if (cm->GetDeprecatedWarningsAsErrors(this->Makefile))
{
fatal = true;
type = cmake::DEPRECATION_ERROR;
}
+ else if (!cm->GetSuppressDeprecatedWarnings(this->Makefile))
+ {
+ type = cmake::DEPRECATION_WARNING;
+ }
else
{
- if (this->Makefile->GetCMakeInstance()->GetSuppressDeprecatedWarnings(
- this->Makefile))
- {
- return true;
- }
- else
- {
- type = cmake::DEPRECATION_WARNING;
- }
+ return true;
}
++i;
}
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 7992495..8f6b952 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -291,6 +291,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
std::string name;
bool foundNo = false;
+ bool foundError = false;
unsigned int nameStartPosition = 0;
if (entry.find("no-", nameStartPosition) == 0)
@@ -299,6 +300,12 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
nameStartPosition += 3;
}
+ if (entry.find("error=", nameStartPosition) == 0)
+ {
+ foundError = true;
+ nameStartPosition += 6;
+ }
+
name = entry.substr(nameStartPosition);
if (name.empty())
{
@@ -306,16 +313,27 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
return false;
}
- if (!foundNo)
+ if (!foundNo && !foundError)
{
// -W<name>
this->DiagLevels[name] = std::max(this->DiagLevels[name],
DIAG_WARN);
}
+ else if (foundNo && !foundError)
+ {
+ // -Wno<name>
+ this->DiagLevels[name] = DIAG_IGNORE;
+ }
+ else if (!foundNo && foundError)
+ {
+ // -Werror=<name>
+ this->DiagLevels[name] = DIAG_ERROR;
+ }
else
{
- // -Wno<name>
- this->DiagLevels[name] = DIAG_IGNORE;
+ // -Wno-error=<name>
+ this->DiagLevels[name] = std::min(this->DiagLevels[name],
+ DIAG_WARN);
}
}
else if(arg.find("-U",0) == 0)
@@ -1270,10 +1288,17 @@ int cmake::Configure()
if (diagLevel == DIAG_IGNORE)
{
this->SetSuppressDeprecatedWarnings(true);
+ this->SetDeprecatedWarningsAsErrors(false);
}
else if (diagLevel == DIAG_WARN)
{
this->SetSuppressDeprecatedWarnings(false);
+ this->SetDeprecatedWarningsAsErrors(false);
+ }
+ else if (diagLevel == DIAG_ERROR)
+ {
+ this->SetSuppressDeprecatedWarnings(false);
+ this->SetDeprecatedWarningsAsErrors(true);
}
}
@@ -1283,9 +1308,11 @@ int cmake::Configure()
const char* cachedWarnDeprecated =
this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED");
+ const char* cachedErrorDeprecated =
+ this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
// don't overwrite deprecated warning setting from a previous invocation
- if (!cachedWarnDeprecated)
+ if (!cachedWarnDeprecated && !cachedErrorDeprecated)
{
setDeprecatedVariables = true;
}
@@ -1294,19 +1321,34 @@ int cmake::Configure()
if (diagLevel == DIAG_IGNORE)
{
this->SetSuppressDevWarnings(true);
+ this->SetDevWarningsAsErrors(false);
if (setDeprecatedVariables)
{
this->SetSuppressDeprecatedWarnings(true);
+ this->SetDeprecatedWarningsAsErrors(false);
}
}
else if (diagLevel == DIAG_WARN)
{
this->SetSuppressDevWarnings(false);
+ this->SetDevWarningsAsErrors(false);
+
+ if (setDeprecatedVariables)
+ {
+ this->SetSuppressDeprecatedWarnings(false);
+ this->SetDeprecatedWarningsAsErrors(false);
+ }
+ }
+ else if (diagLevel == DIAG_ERROR)
+ {
+ this->SetSuppressDevWarnings(false);
+ this->SetDevWarningsAsErrors(true);
if (setDeprecatedVariables)
{
this->SetSuppressDeprecatedWarnings(false);
+ this->SetDeprecatedWarningsAsErrors(true);
}
}
}
@@ -2547,16 +2589,45 @@ static bool cmakeCheckStampList(const char* stampList)
return true;
}
+cmake::MessageType cmake::ConvertMessageType(cmake::MessageType t)
+{
+ bool warningsAsErrors;
+
+ if (t == cmake::AUTHOR_WARNING || t == cmake::AUTHOR_ERROR)
+ {
+ warningsAsErrors = this->GetDevWarningsAsErrors();
+ if (warningsAsErrors && t == cmake::AUTHOR_WARNING)
+ {
+ t = cmake::AUTHOR_ERROR;
+ }
+ else if (!warningsAsErrors && t == cmake::AUTHOR_ERROR)
+ {
+ t = cmake::AUTHOR_WARNING;
+ }
+ }
+ else if (t == cmake::DEPRECATION_WARNING || t == cmake::DEPRECATION_ERROR)
+ {
+ warningsAsErrors = this->GetDeprecatedWarningsAsErrors();
+ if (warningsAsErrors && t == cmake::DEPRECATION_WARNING)
+ {
+ t = cmake::DEPRECATION_ERROR;
+ }
+ else if (!warningsAsErrors && t == cmake::DEPRECATION_ERROR)
+ {
+ t = cmake::DEPRECATION_WARNING;
+ }
+ }
+
+ return t;
+}
+
bool cmake::IsMessageTypeVisible(cmake::MessageType t)
{
bool isVisible = true;
if(t == cmake::DEPRECATION_ERROR)
{
- // if CMAKE_ERROR_DEPRECATED is on, show the message, otherwise suppress it
- const char* errorDeprecated = this->State->GetCacheEntryValue(
- "CMAKE_ERROR_DEPRECATED");
- if(cmSystemTools::IsOff(errorDeprecated))
+ if(!this->GetDeprecatedWarningsAsErrors())
{
isVisible = false;
}
@@ -2568,6 +2639,13 @@ bool cmake::IsMessageTypeVisible(cmake::MessageType t)
isVisible = false;
}
}
+ else if (t == cmake::AUTHOR_ERROR)
+ {
+ if (!this->GetDevWarningsAsErrors())
+ {
+ isVisible = false;
+ }
+ }
else if (t == cmake::AUTHOR_WARNING)
{
if (this->GetSuppressDevWarnings())
@@ -2606,6 +2684,10 @@ bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg)
{
msg << "CMake Warning (dev)";
}
+ else if (t == cmake::AUTHOR_ERROR)
+ {
+ msg << "CMake Error (dev)";
+ }
else
{
msg << "CMake Warning";
@@ -2630,6 +2712,12 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
msg <<
"This warning is for project developers. Use -Wno-dev to suppress it.";
}
+ else if (t == cmake::AUTHOR_ERROR)
+ {
+ msg <<
+ "This error is for project developers. Use -Wno-error=dev to suppress "
+ "it.";
+ }
// Add a terminating blank line.
msg << "\n";
@@ -2653,7 +2741,8 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
// Output the message.
if(t == cmake::FATAL_ERROR
|| t == cmake::INTERNAL_ERROR
- || t == cmake::DEPRECATION_ERROR)
+ || t == cmake::DEPRECATION_ERROR
+ || t == cmake::AUTHOR_ERROR)
{
cmSystemTools::SetErrorOccured();
cmSystemTools::Message(msg.str().c_str(), "Error");
@@ -2671,6 +2760,17 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
{
cmListFileBacktrace backtrace = bt;
+ if (!force)
+ {
+ // override the message type, if needed, for warnings and errors
+ cmake::MessageType override = this->ConvertMessageType(t);
+ if (override != t)
+ {
+ t = override;
+ force = true;
+ }
+ }
+
if (!force && !this->IsMessageTypeVisible(t))
{
return;
@@ -2698,6 +2798,17 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileContext const& lfc,
bool force)
{
+ if (!force)
+ {
+ // override the message type, if needed, for warnings and errors
+ cmake::MessageType override = this->ConvertMessageType(t);
+ if (override != t)
+ {
+ t = override;
+ force = true;
+ }
+ }
+
if (!force && !this->IsMessageTypeVisible(t))
{
return;
@@ -2941,3 +3052,74 @@ void cmake::SetSuppressDeprecatedWarnings(bool b)
"functionality.",
cmState::INTERNAL);
}
+
+bool cmake::GetDevWarningsAsErrors(cmMakefile const* mf)
+{
+ if (mf)
+ {
+ return (mf->IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") &&
+ !mf->IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS"));
+ }
+ else
+ {
+ const char* cacheEntryValue = this->State->GetCacheEntryValue(
+ "CMAKE_SUPPRESS_DEVELOPER_ERRORS");
+ return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
+ }
+}
+
+void cmake::SetDevWarningsAsErrors(bool b)
+{
+ std::string value;
+
+ // equivalent to -Werror=dev
+ if (b)
+ {
+ value = "FALSE";
+ }
+ // equivalent to -Wno-error=dev
+ else
+ {
+ value = "TRUE";
+ }
+
+ this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_ERRORS", value.c_str(),
+ "Suppress errors that are meant for"
+ " the author of the CMakeLists.txt files.",
+ cmState::INTERNAL);
+}
+
+bool cmake::GetDeprecatedWarningsAsErrors(cmMakefile const* mf)
+{
+ if (mf)
+ {
+ return mf->IsOn("CMAKE_ERROR_DEPRECATED");
+ }
+ else
+ {
+ const char* cacheEntryValue = this->State->GetCacheEntryValue(
+ "CMAKE_ERROR_DEPRECATED");
+ return cmSystemTools::IsOn(cacheEntryValue);
+ }
+}
+
+void cmake::SetDeprecatedWarningsAsErrors(bool b)
+{
+ std::string value;
+
+ // equivalent to -Werror=deprecated
+ if (b)
+ {
+ value = "TRUE";
+ }
+ // equivalent to -Wno-error=deprecated
+ else
+ {
+ value = "FALSE";
+ }
+
+ this->AddCacheEntry("CMAKE_ERROR_DEPRECATED", value.c_str(),
+ "Whether to issue deprecation errors for macros"
+ " and functions.",
+ cmState::INTERNAL);
+}
diff --git a/Source/cmake.h b/Source/cmake.h
index 298d82b..8496705 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -59,6 +59,7 @@ class cmake
public:
enum MessageType
{ AUTHOR_WARNING,
+ AUTHOR_ERROR,
FATAL_ERROR,
INTERNAL_ERROR,
MESSAGE,
@@ -71,7 +72,8 @@ class cmake
enum DiagLevel
{
DIAG_IGNORE,
- DIAG_WARN
+ DIAG_WARN,
+ DIAG_ERROR
};
/** \brief Describes the working modes of cmake */
@@ -330,6 +332,28 @@ class cmake
*/
void SetSuppressDeprecatedWarnings(bool v);
+ /*
+ * Get the state of treating developer (author) warnings as errors.
+ * Returns false, by default, if warnings should not be treated as errors,
+ * true otherwise.
+ */
+ bool GetDevWarningsAsErrors(cmMakefile const* mf = NULL);
+ /**
+ * Set the state of treating developer (author) warnings as errors.
+ */
+ void SetDevWarningsAsErrors(bool v);
+
+ /*
+ * Get the state of treating deprecated warnings as errors.
+ * Returns false, by default, if warnings should not be treated as errors,
+ * true otherwise.
+ */
+ bool GetDeprecatedWarningsAsErrors(cmMakefile const* mf = NULL);
+ /**
+ * Set the state of treating developer (author) warnings as errors.
+ */
+ void SetDeprecatedWarningsAsErrors(bool v);
+
/** Display a message to the user. */
void IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileBacktrace const& backtrace = cmListFileBacktrace(),
@@ -441,6 +465,12 @@ private:
// Print a list of valid generators to stderr.
void PrintGeneratorList();
+ /**
+ * Convert a message type between a warning and an error, based on the state
+ * of the error output CMake variables, in the cache.
+ */
+ cmake::MessageType ConvertMessageType(cmake::MessageType t);
+
/*
* Check if messages of this type should be output, based on the state of the
* warning and error output CMake variables, in the cache.
@@ -457,10 +487,16 @@ private:
{"-G <generator-name>", "Specify a build system generator."},\
{"-T <toolset-name>", "Specify toolset name if supported by generator."}, \
{"-A <platform-name>", "Specify platform name if supported by generator."}, \
- {"-Wno-dev", "Suppress developer warnings."},\
{"-Wdev", "Enable developer warnings."},\
+ {"-Wno-dev", "Suppress developer warnings."},\
+ {"-Werror=dev", "Make developer warnings errors."},\
+ {"-Wno-error=dev", "Make developer warnings not errors."},\
{"-Wdeprecated", "Enable deprecation warnings."},\
- {"-Wno-deprecated", "Suppress deprecation warnings."}
+ {"-Wno-deprecated", "Suppress deprecation warnings."},\
+ {"-Werror=deprecated", "Make deprecated macro and function warnings " \
+ "errors."},\
+ {"-Wno-error=deprecated", "Make deprecated macro and function warnings " \
+ "not errors."}
#define FOR_EACH_C_FEATURE(F) \
F(c_function_prototypes) \