watcom: support '+' symbol in file names

Fixes: #27986
This commit is contained in:
AJIOB
2026-07-29 18:35:25 +03:00
parent b5efecc945
commit 0bccfbcf0a
4 changed files with 33 additions and 6 deletions
+23 -6
View File
@@ -470,10 +470,15 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2(
}
namespace {
std::string ConvertToMakefilePathForUnix(std::string const& path)
std::string ConvertToMakefilePathForUnix(std::string const& path,
bool isForceQuote)
{
bool const quote = isForceQuote;
std::string result;
result.reserve(path.size());
result.reserve(path.size() + (quote ? 2 : 0));
if (quote) {
result.push_back('"');
}
for (char c : path) {
switch (c) {
case '=':
@@ -493,13 +498,18 @@ std::string ConvertToMakefilePathForUnix(std::string const& path)
break;
}
}
if (quote) {
result.push_back('"');
}
return result;
}
#if defined(_WIN32) && !defined(__CYGWIN__)
std::string ConvertToMakefilePathForWindows(std::string const& path)
std::string ConvertToMakefilePathForWindows(std::string const& path,
bool isForceQuote)
{
bool const quote = path.find_first_of(" #") != std::string::npos;
bool const quote =
isForceQuote || path.find_first_of(" #") != std::string::npos;
std::string result;
result.reserve(path.size() + (quote ? 2 : 0));
if (quote) {
@@ -533,12 +543,19 @@ std::string ConvertToMakefilePathForWindows(std::string const& path)
std::string cmGlobalUnixMakefileGenerator3::ConvertToMakefilePath(
std::string const& path) const
{
// Watcom WMake treats '+' as special. Quote the whole path so names
// containing '+' (e.g. test+1.c, stdc++.cmake) are accepted.
bool const isWatcomWMake =
this->GetCMakeInstance()->GetState()->UseWatcomWMake();
bool const isForceQuote =
isWatcomWMake && path.find('+') != std::string::npos;
#if defined(_WIN32) && !defined(__CYGWIN__)
if (!this->ForceUnixPaths) {
return ConvertToMakefilePathForWindows(path);
return ConvertToMakefilePathForWindows(path, isForceQuote);
}
#endif
return ConvertToMakefilePathForUnix(path);
return ConvertToMakefilePathForUnix(path, isForceQuote);
}
std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+2
View File
@@ -925,6 +925,8 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(CommandLength CommandLength)
ADD_TEST_MACRO(PlusInFileName PlusInFileName)
ADD_TEST_MACRO(EmptyDepends ${CMAKE_CTEST_COMMAND})
add_test(CustomCommandWorkingDirectory ${CMAKE_CTEST_COMMAND}
+4
View File
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.10)
project(PlusInFileName C)
add_executable(PlusInFileName test+1.c)
+4
View File
@@ -0,0 +1,4 @@
int main(void)
{
return 0;
}