mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-30 11:10:06 -05:00
VS: Fix nowarn compiler option to accept warning numbers.
Warning disables are transferred to the VS IDE `<NoWarn>` node. Fixes: #18878
This commit is contained in:
@@ -1136,6 +1136,8 @@ static unsigned int cmLoadFlagTableSpecial(Json::Value entry,
|
|||||||
value |= cmIDEFlagTable::CaseInsensitive;
|
value |= cmIDEFlagTable::CaseInsensitive;
|
||||||
} else if (s == "SpaceAppendable") {
|
} else if (s == "SpaceAppendable") {
|
||||||
value |= cmIDEFlagTable::SpaceAppendable;
|
value |= cmIDEFlagTable::SpaceAppendable;
|
||||||
|
} else if (s == "CommaAppendable") {
|
||||||
|
value |= cmIDEFlagTable::CommaAppendable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ struct cmIDEFlagTable
|
|||||||
SpaceAppendable = (1 << 7), // a flag that if specified multiple times
|
SpaceAppendable = (1 << 7), // a flag that if specified multiple times
|
||||||
// should have its value appended to the
|
// should have its value appended to the
|
||||||
// old value with spaces
|
// old value with spaces
|
||||||
|
CommaAppendable = (1 << 8), // a flag that if specified multiple times
|
||||||
|
// should have its value appended to the
|
||||||
|
// old value with commas (e.g. C# /nowarn
|
||||||
|
|
||||||
UserValueIgnored = UserValue | UserIgnored,
|
UserValueIgnored = UserValue | UserIgnored,
|
||||||
UserValueRequired = UserValue | UserRequired
|
UserValueRequired = UserValue | UserRequired
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry,
|
|||||||
this->FlagMap[entry->IDEName].push_back(new_value);
|
this->FlagMap[entry->IDEName].push_back(new_value);
|
||||||
} else if (entry->special & cmIDEFlagTable::SpaceAppendable) {
|
} else if (entry->special & cmIDEFlagTable::SpaceAppendable) {
|
||||||
this->FlagMap[entry->IDEName].append_with_space(new_value);
|
this->FlagMap[entry->IDEName].append_with_space(new_value);
|
||||||
|
} else if (entry->special & cmIDEFlagTable::CommaAppendable) {
|
||||||
|
this->FlagMap[entry->IDEName].append_with_comma(new_value);
|
||||||
} else {
|
} else {
|
||||||
// Use the user-specified value.
|
// Use the user-specified value.
|
||||||
this->FlagMap[entry->IDEName] = new_value;
|
this->FlagMap[entry->IDEName] = new_value;
|
||||||
|
|||||||
+11
-1
@@ -65,12 +65,22 @@ protected:
|
|||||||
this->derived::operator=(r);
|
this->derived::operator=(r);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
FlagValue& append_with_comma(std::string const& r)
|
||||||
|
{
|
||||||
|
return append_with_separator(r, ',');
|
||||||
|
}
|
||||||
FlagValue& append_with_space(std::string const& r)
|
FlagValue& append_with_space(std::string const& r)
|
||||||
|
{
|
||||||
|
return append_with_separator(r, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
FlagValue& append_with_separator(std::string const& r, char separator)
|
||||||
{
|
{
|
||||||
this->resize(1);
|
this->resize(1);
|
||||||
std::string& l = this->operator[](0);
|
std::string& l = this->operator[](0);
|
||||||
if (!l.empty()) {
|
if (!l.empty()) {
|
||||||
l += " ";
|
l += separator;
|
||||||
}
|
}
|
||||||
l += r;
|
l += r;
|
||||||
return *this;
|
return *this;
|
||||||
|
|||||||
@@ -299,11 +299,15 @@
|
|||||||
"flags": []
|
"flags": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DisabledWarnings",
|
"name": "NoWarn",
|
||||||
"switch": "nowarn",
|
"switch": "nowarn:",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"value": "",
|
"value": "",
|
||||||
"flags": []
|
"flags": [
|
||||||
|
"UserValue",
|
||||||
|
"UserRequired",
|
||||||
|
"CommaAppendable"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "CheckForOverflowUnderflow",
|
"name": "CheckForOverflowUnderflow",
|
||||||
|
|||||||
@@ -299,11 +299,15 @@
|
|||||||
"flags": []
|
"flags": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DisabledWarnings",
|
"name": "NoWarn",
|
||||||
"switch": "nowarn",
|
"switch": "nowarn:",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"value": "",
|
"value": "",
|
||||||
"flags": []
|
"flags": [
|
||||||
|
"UserValue",
|
||||||
|
"UserRequired",
|
||||||
|
"CommaAppendable"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "CheckForOverflowUnderflow",
|
"name": "CheckForOverflowUnderflow",
|
||||||
|
|||||||
@@ -299,11 +299,15 @@
|
|||||||
"flags": []
|
"flags": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DisabledWarnings",
|
"name": "NoWarn",
|
||||||
"switch": "nowarn",
|
"switch": "nowarn:",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"value": "",
|
"value": "",
|
||||||
"flags": []
|
"flags": [
|
||||||
|
"UserValue",
|
||||||
|
"UserRequired",
|
||||||
|
"CommaAppendable"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "CheckForOverflowUnderflow",
|
"name": "CheckForOverflowUnderflow",
|
||||||
|
|||||||
@@ -299,11 +299,15 @@
|
|||||||
"flags": []
|
"flags": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DisabledWarnings",
|
"name": "NoWarn",
|
||||||
"switch": "nowarn",
|
"switch": "nowarn:",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"value": "",
|
"value": "",
|
||||||
"flags": []
|
"flags": [
|
||||||
|
"UserValue",
|
||||||
|
"UserRequired",
|
||||||
|
"CommaAppendable"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "CheckForOverflowUnderflow",
|
"name": "CheckForOverflowUnderflow",
|
||||||
|
|||||||
@@ -299,11 +299,15 @@
|
|||||||
"flags": []
|
"flags": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DisabledWarnings",
|
"name": "NoWarn",
|
||||||
"switch": "nowarn",
|
"switch": "nowarn:",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"value": "",
|
"value": "",
|
||||||
"flags": []
|
"flags": [
|
||||||
|
"UserValue",
|
||||||
|
"UserRequired",
|
||||||
|
"CommaAppendable"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "CheckForOverflowUnderflow",
|
"name": "CheckForOverflowUnderflow",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
include(RunCMake)
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(VsCSharpCompilerOpts)
|
||||||
run_cmake(ExplicitCMakeLists)
|
run_cmake(ExplicitCMakeLists)
|
||||||
run_cmake(SourceGroupCMakeLists)
|
run_cmake(SourceGroupCMakeLists)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#
|
||||||
|
# Check C# VS project for required elements.
|
||||||
|
#
|
||||||
|
set(csProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.csproj")
|
||||||
|
if(NOT EXISTS "${csProjectFile}")
|
||||||
|
set(RunCMake_TEST_FAILED "Project file ${csProjectFile} does not exist.")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
set(inDebug FALSE)
|
||||||
|
set(inRelease FALSE)
|
||||||
|
set(debugOK FALSE)
|
||||||
|
set(releaseOK FALSE)
|
||||||
|
|
||||||
|
|
||||||
|
file(STRINGS "${csProjectFile}" lines)
|
||||||
|
foreach(line IN LISTS lines)
|
||||||
|
#message(STATUS ${line})
|
||||||
|
if(line MATCHES "^ *<PropertyGroup .*Debug\\|(Win32|x64).*")
|
||||||
|
set(inDebug TRUE)
|
||||||
|
elseif(line MATCHES "^ *<PropertyGroup .*Release\\|(Win32|x64).*")
|
||||||
|
set(inRelease TRUE)
|
||||||
|
elseif(line MATCHES "^ *</PropertyGroup> *$")
|
||||||
|
set(inRelease FALSE)
|
||||||
|
set(inDebug FALSE)
|
||||||
|
elseif(inDebug AND
|
||||||
|
(line MATCHES "^ *<NoWarn>.*505.*</NoWarn> *$") AND
|
||||||
|
(line MATCHES "^ *<NoWarn>.*707.*</NoWarn> *$") AND
|
||||||
|
(line MATCHES "^ *<NoWarn>.*808.*</NoWarn> *$") AND
|
||||||
|
(line MATCHES "^ *<NoWarn>.*909.*</NoWarn> *$")
|
||||||
|
)
|
||||||
|
set(debugOK TRUE)
|
||||||
|
elseif(inRelease AND
|
||||||
|
(NOT (line MATCHES "^ *<NoWarn>.*505.*</NoWarn> *$")) AND
|
||||||
|
(line MATCHES "^ *<NoWarn>.*707.*</NoWarn> *$") AND
|
||||||
|
(line MATCHES "^ *<NoWarn>.*808.*</NoWarn> *$") AND
|
||||||
|
(line MATCHES "^ *<NoWarn>.*909.*</NoWarn> *$")
|
||||||
|
)
|
||||||
|
set(releaseOK TRUE)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
function(print_csprojfile)
|
||||||
|
file(STRINGS "${csProjectFile}" lines)
|
||||||
|
foreach(line IN LISTS lines)
|
||||||
|
message(STATUS ${line})
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
if(NOT debugOK)
|
||||||
|
message(STATUS "Failed to set Debug configuration warning config correctly.")
|
||||||
|
set(RunCMake_TEST_FAILED "Failed to set Debug configuration defines correctly.")
|
||||||
|
print_csprojfile()
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT releaseOK)
|
||||||
|
message(STATUS "Failed to set Release configuration warning config correctly.")
|
||||||
|
set(RunCMake_TEST_FAILED "Failed to set Release configuration defines correctly.")
|
||||||
|
print_csprojfile()
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
enable_language(CSharp)
|
||||||
|
|
||||||
|
add_library(foo SHARED
|
||||||
|
foo.cs)
|
||||||
|
|
||||||
|
set_target_properties(foo PROPERTIES
|
||||||
|
LINKER_LANGUAGE CSharp)
|
||||||
|
|
||||||
|
|
||||||
|
# Issue 18878
|
||||||
|
target_compile_options(foo PRIVATE "/platform:anycpu" "/nowarn:707,808" "/nowarn:909" )
|
||||||
|
|
||||||
|
# Debug only warning disable
|
||||||
|
set(CMAKE_CSharp_FLAGS_DEBUG "${CMAKE_CSharp_FLAGS_DEBUG} /nowarn:505")
|
||||||
Reference in New Issue
Block a user