diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2023-12-20 15:28:53 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2023-12-20 16:05:09 (GMT) |
commit | 255c2e14309a4861b929f65698b7326cff6c63ad (patch) | |
tree | ca95124b1313e52251e59c4ff33922916b5626ae | |
parent | 158316dc0c0fb856feb67ca3cacd7681170b5e0a (diff) | |
download | CMake-255c2e14309a4861b929f65698b7326cff6c63ad.zip CMake-255c2e14309a4861b929f65698b7326cff6c63ad.tar.gz CMake-255c2e14309a4861b929f65698b7326cff6c63ad.tar.bz2 |
Ninja: LINK_OPTIONS property should support newlines
Fixes: #25513
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 1 | ||||
-rw-r--r-- | Source/cmOutputConverter.cxx | 9 | ||||
-rw-r--r-- | Source/cmOutputConverter.h | 5 | ||||
-rw-r--r-- | Source/cmState.cxx | 10 | ||||
-rw-r--r-- | Source/cmState.h | 3 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/LINK_OPTIONSWithNewlines.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/RunCMakeTest.cmake | 2 |
7 files changed, 36 insertions, 1 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index cba48f4..22fd90d 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -564,6 +564,7 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm) this->Comspec = "cmd.exe"; } #endif + cm->GetState()->SetNinja(true); this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake"; } diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index 9c30d74..f4a8d0c 100644 --- a/Source/cmOutputConverter.cxx +++ b/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; diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h index 0ee7afb..424f004 100644 --- a/Source/cmOutputConverter.h +++ b/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, diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 8ae2166..d104268 100644 --- a/Source/cmState.cxx +++ b/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; diff --git a/Source/cmState.h b/Source/cmState.h index 702b06f..ae0d52b 100644 --- a/Source/cmState.h +++ b/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; diff --git a/Tests/RunCMake/Ninja/LINK_OPTIONSWithNewlines.cmake b/Tests/RunCMake/Ninja/LINK_OPTIONSWithNewlines.cmake new file mode 100644 index 0000000..285966e --- /dev/null +++ b/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]") diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index 42ab1d8..13d9620 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake @@ -405,3 +405,5 @@ endfunction() if(CMake_TEST_Qt_version) run_QtAutoMocSkipPch() endif() + +run_cmake(LINK_OPTIONSWithNewlines) |