|
@@ -20,6 +20,7 @@
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
#include "cmMakefile.h"
|
|
|
#include "cmMessageType.h"
|
|
|
+#include "cmPolicies.h"
|
|
|
#include "cmStringAlgorithms.h"
|
|
|
#include "cmTarget.h"
|
|
|
#include "cmValue.h"
|
|
@@ -83,25 +84,62 @@ struct StandardLevelComputer
|
|
|
return std::string{};
|
|
|
}
|
|
|
|
|
|
+ cmPolicies::PolicyStatus const cmp0128{ makefile->GetPolicyStatus(
|
|
|
+ cmPolicies::CMP0128) };
|
|
|
+ bool const defaultExt{ cmIsOn(*makefile->GetDefinition(
|
|
|
+ cmStrCat("CMAKE_", this->Language, "_EXTENSIONS_DEFAULT"))) };
|
|
|
bool ext = true;
|
|
|
+
|
|
|
+ if (cmp0128 == cmPolicies::NEW) {
|
|
|
+ ext = defaultExt;
|
|
|
+ }
|
|
|
+
|
|
|
if (cmValue extPropValue = target->GetLanguageExtensions(this->Language)) {
|
|
|
- if (cmIsOff(*extPropValue)) {
|
|
|
- ext = false;
|
|
|
- }
|
|
|
+ ext = cmIsOn(*extPropValue);
|
|
|
}
|
|
|
|
|
|
+ std::string const type{ ext ? "EXTENSION" : "STANDARD" };
|
|
|
+
|
|
|
cmValue standardProp = target->GetLanguageStandard(this->Language, config);
|
|
|
if (!standardProp) {
|
|
|
- if (ext) {
|
|
|
- // No language standard is specified and extensions are not disabled.
|
|
|
- // Check if this compiler needs a flag to enable extensions.
|
|
|
- return cmStrCat("CMAKE_", this->Language, "_EXTENSION_COMPILE_OPTION");
|
|
|
+ if (cmp0128 == cmPolicies::NEW) {
|
|
|
+ // Add extension flag if compiler's default doesn't match.
|
|
|
+ if (ext != defaultExt) {
|
|
|
+ return cmStrCat("CMAKE_", this->Language, *defaultStd, "_", type,
|
|
|
+ "_COMPILE_OPTION");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (cmp0128 == cmPolicies::WARN &&
|
|
|
+ makefile->PolicyOptionalWarningEnabled(
|
|
|
+ "CMAKE_POLICY_WARNING_CMP0128") &&
|
|
|
+ ext != defaultExt) {
|
|
|
+ const char* state{};
|
|
|
+ if (ext) {
|
|
|
+ if (!makefile->GetDefinition(cmStrCat(
|
|
|
+ "CMAKE_", this->Language, "_EXTENSION_COMPILE_OPTION"))) {
|
|
|
+ state = "enabled";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ state = "disabled";
|
|
|
+ }
|
|
|
+ if (state) {
|
|
|
+ makefile->IssueMessage(
|
|
|
+ MessageType::AUTHOR_WARNING,
|
|
|
+ cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0128),
|
|
|
+ "\nFor compatibility with older versions of CMake, "
|
|
|
+ "compiler extensions won't be ",
|
|
|
+ state, "."));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ext) {
|
|
|
+ return cmStrCat("CMAKE_", this->Language,
|
|
|
+ "_EXTENSION_COMPILE_OPTION");
|
|
|
+ }
|
|
|
}
|
|
|
return std::string{};
|
|
|
}
|
|
|
|
|
|
- std::string const type = ext ? "EXTENSION" : "STANDARD";
|
|
|
-
|
|
|
if (target->GetLanguageStandardRequired(this->Language)) {
|
|
|
std::string option_flag = cmStrCat(
|
|
|
"CMAKE_", this->Language, *standardProp, "_", type, "_COMPILE_OPTION");
|
|
@@ -121,6 +159,25 @@ struct StandardLevelComputer
|
|
|
return option_flag;
|
|
|
}
|
|
|
|
|
|
+ // If the request matches the compiler's defaults we don't need to add
|
|
|
+ // anything.
|
|
|
+ if (*standardProp == *defaultStd && ext == defaultExt) {
|
|
|
+ if (cmp0128 == cmPolicies::NEW) {
|
|
|
+ return std::string{};
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cmp0128 == cmPolicies::WARN &&
|
|
|
+ makefile->PolicyOptionalWarningEnabled(
|
|
|
+ "CMAKE_POLICY_WARNING_CMP0128")) {
|
|
|
+ makefile->IssueMessage(
|
|
|
+ MessageType::AUTHOR_WARNING,
|
|
|
+ cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0128),
|
|
|
+ "\nFor compatibility with older versions of CMake, "
|
|
|
+ "unnecessary flags for language standard or compiler "
|
|
|
+ "extensions may be added."));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
std::string standardStr(*standardProp);
|
|
|
if (this->Language == "CUDA" && standardStr == "98") {
|
|
|
standardStr = "03";
|
|
@@ -147,17 +204,17 @@ struct StandardLevelComputer
|
|
|
return std::string{};
|
|
|
}
|
|
|
|
|
|
- // If the standard requested is older than the compiler's default
|
|
|
- // then we need to use a flag to change it.
|
|
|
- if (stdIt <= defaultStdIt) {
|
|
|
+ // If the standard requested is older than the compiler's default or the
|
|
|
+ // extension mode doesn't match then we need to use a flag.
|
|
|
+ if (stdIt < defaultStdIt) {
|
|
|
auto offset = std::distance(cm::cbegin(stds), stdIt);
|
|
|
return cmStrCat("CMAKE_", this->Language, stdsStrings[offset], "_", type,
|
|
|
"_COMPILE_OPTION");
|
|
|
}
|
|
|
|
|
|
- // The standard requested is at least as new as the compiler's default,
|
|
|
- // and the standard request is not required. Decay to the newest standard
|
|
|
- // for which a flag is defined.
|
|
|
+ // The compiler's default is at least as new as the requested standard,
|
|
|
+ // and the requested standard is not required. Decay to the newest
|
|
|
+ // standard for which a flag is defined.
|
|
|
for (; defaultStdIt < stdIt; --stdIt) {
|
|
|
auto offset = std::distance(cm::cbegin(stds), stdIt);
|
|
|
std::string option_flag =
|