Browse Source

MSVC: Recognize -XYZ as well as /XYZ when parsing MS tool command lines

Fixes: #23772
Dubach, Joev 3 years ago
parent
commit
9dbcfb8fdd

+ 7 - 3
Source/cmVisualStudio10TargetGenerator.cxx

@@ -3148,12 +3148,14 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
   }
 
   // Check if ASan is enabled.
-  if (flags.find("/fsanitize=address") != std::string::npos) {
+  if (flags.find("/fsanitize=address") != std::string::npos ||
+      flags.find("-fsanitize=address") != std::string::npos) {
     this->ASanEnabledConfigurations.insert(configName);
   }
 
   // Check if (lib)Fuzzer is enabled.
-  if (flags.find("/fsanitize=fuzzer") != std::string::npos) {
+  if (flags.find("/fsanitize=fuzzer") != std::string::npos ||
+      flags.find("-fsanitize=fuzzer") != std::string::npos) {
     this->FuzzerEnabledConfigurations.insert(configName);
   }
 
@@ -3198,7 +3200,9 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
     // anymore, because cmGeneratorTarget may not be aware that the
     // target uses C++/CLI.
     if (flags.find("/clr") != std::string::npos ||
-        defineFlags.find("/clr") != std::string::npos) {
+        flags.find("-clr") != std::string::npos ||
+        defineFlags.find("/clr") != std::string::npos ||
+        defineFlags.find("-clr") != std::string::npos) {
       if (configName == this->Configurations[0]) {
         std::string message = "For the target \"" +
           this->GeneratorTarget->GetName() +

+ 1 - 0
Source/cmcldeps.cxx

@@ -273,6 +273,7 @@ int main()
     std::string clrest = rest;
     // rc: /fo x.dir\x.rc.res  ->  cl: /out:x.dir\x.rc.res.dep.obj
     clrest = replace(clrest, "/fo ", "/out:");
+    clrest = replace(clrest, "-fo ", "-out:");
     clrest = replace(clrest, objfile, objfile + ".dep.obj ");
 
     cl = "\"" + cl + "\" /P /DRC_INVOKED /TC ";

+ 9 - 4
Source/cmcmd.cxx

@@ -2242,13 +2242,18 @@ bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg,
   // Parse the link command to extract information we need.
   for (; arg != argEnd; ++arg) {
     if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL:YES") == 0 ||
-        cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL") == 0) {
+        cmSystemTools::Strucmp(arg->c_str(), "-INCREMENTAL:YES") == 0 ||
+        cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL") == 0 ||
+        cmSystemTools::Strucmp(arg->c_str(), "-INCREMENTAL") == 0) {
       this->Incremental = true;
-    } else if (cmSystemTools::Strucmp(arg->c_str(), "/MANIFEST:NO") == 0) {
+    } else if (cmSystemTools::Strucmp(arg->c_str(), "/MANIFEST:NO") == 0 ||
+               cmSystemTools::Strucmp(arg->c_str(), "-MANIFEST:NO") == 0) {
       this->LinkGeneratesManifest = false;
-    } else if (cmHasLiteralPrefix(*arg, "/Fe")) {
+    } else if (cmHasLiteralPrefix(*arg, "/Fe") ||
+               cmHasLiteralPrefix(*arg, "-Fe")) {
       this->TargetFile = arg->substr(3);
-    } else if (cmHasLiteralPrefix(*arg, "/out:")) {
+    } else if (cmHasLiteralPrefix(*arg, "/out:") ||
+               cmHasLiteralPrefix(*arg, "-out:")) {
       this->TargetFile = arg->substr(5);
     }
   }

+ 4 - 0
Utilities/Release/WiX/CustomAction/CMakeLists.txt

@@ -7,6 +7,10 @@ if(MSVC)
         "CMAKE_CXX_FLAGS_${CONFIG}"
         "${CMAKE_CXX_FLAGS_${CONFIG}}"
         )
+      string(REPLACE "-MD" "-MT"
+        "CMAKE_CXX_FLAGS_${CONFIG}"
+        "${CMAKE_CXX_FLAGS_${CONFIG}}"
+        )
     endforeach()
   endif()
 endif()

+ 2 - 0
Utilities/cmcurl/CMakeLists.txt

@@ -1465,6 +1465,8 @@ if(MSVC)
   add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
   if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
     string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+  elseif(CMAKE_C_FLAGS MATCHES "-W[0-4]")
+    string(REGEX REPLACE "-W[0-4]" "-W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
   else()
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
   endif()