Browse Source

Merge topic 'Ninja-LINK_OPTIONS-with-newlines' into release-3.28

255c2e1430 Ninja: LINK_OPTIONS property should support newlines

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Merge-request: !9096
Marc Chevrier 1 year ago
parent
commit
73d0160134

+ 1 - 0
Source/cmGlobalNinjaGenerator.cxx

@@ -564,6 +564,7 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm)
     this->Comspec = "cmd.exe";
   }
 #endif
+  cm->GetState()->SetNinja(true);
   this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake";
 }
 

+ 9 - 0
Source/cmOutputConverter.cxx

@@ -275,6 +275,9 @@ std::string cmOutputConverter::EscapeForShell(cm::string_view str,
   if (this->GetState()->UseNMake()) {
     flags |= Shell_Flag_NMake;
   }
+  if (this->GetState()->UseNinja()) {
+    flags |= Shell_Flag_Ninja;
+  }
   if (!this->GetState()->UseWindowsShell()) {
     flags |= Shell_Flag_IsUnix;
   }
@@ -677,6 +680,12 @@ std::string cmOutputConverter::Shell_GetArgument(cm::string_view in, int flags)
         /* Otherwise a semicolon is written just ;. */
         out += ';';
       }
+    } else if (*cit == '\n') {
+      if (flags & Shell_Flag_Ninja) {
+        out += "$\n";
+      } else {
+        out += '\n';
+      }
     } else {
       /* Store this character.  */
       out += *cit;

+ 4 - 1
Source/cmOutputConverter.h

@@ -100,7 +100,10 @@ public:
 
     Shell_Flag_UnescapeNinjaConfiguration = (1 << 9),
 
-    Shell_Flag_IsResponse = (1 << 10)
+    Shell_Flag_IsResponse = (1 << 10),
+
+    /** The target shell is in a Ninja build file.  */
+    Shell_Flag_Ninja = (1 << 11)
   };
 
   std::string EscapeForShell(cm::string_view str, bool makeVars = false,

+ 10 - 0
Source/cmState.cxx

@@ -752,6 +752,16 @@ bool cmState::UseMSYSShell() const
   return this->MSYSShell;
 }
 
+void cmState::SetNinja(bool ninja)
+{
+  this->Ninja = ninja;
+}
+
+bool cmState::UseNinja() const
+{
+  return this->Ninja;
+}
+
 void cmState::SetNinjaMulti(bool ninjaMulti)
 {
   this->NinjaMulti = ninjaMulti;

+ 3 - 0
Source/cmState.h

@@ -220,6 +220,8 @@ public:
   bool UseNMake() const;
   void SetMSYSShell(bool mSYSShell);
   bool UseMSYSShell() const;
+  void SetNinja(bool ninja);
+  bool UseNinja() const;
   void SetNinjaMulti(bool ninjaMulti);
   bool UseNinjaMulti() const;
 
@@ -297,6 +299,7 @@ private:
   bool MinGWMake = false;
   bool NMake = false;
   bool MSYSShell = false;
+  bool Ninja = false;
   bool NinjaMulti = false;
   Mode StateMode = Unknown;
   ProjectKind StateProjectKind = ProjectKind::Normal;

+ 7 - 0
Tests/RunCMake/Ninja/LINK_OPTIONSWithNewlines.cmake

@@ -0,0 +1,7 @@
+enable_language(C)
+
+add_library(hello STATIC hello.c)
+
+target_link_options(hello PRIVATE "-FLAGS=[
+  FLAG1,
+  FLAG2]")

+ 2 - 0
Tests/RunCMake/Ninja/RunCMakeTest.cmake

@@ -405,3 +405,5 @@ endfunction()
 if(CMake_TEST_Qt_version)
   run_QtAutoMocSkipPch()
 endif()
+
+run_cmake(LINK_OPTIONSWithNewlines)