llvm_rc: add llvm_rc option filter to correctly pick up all options

Fixes: #21315
This commit is contained in:
Thomas Bernard
2020-10-22 23:06:17 +02:00
committed by Brad King
parent b3f1a29226
commit ea03f50842
5 changed files with 79 additions and 6 deletions
+43 -3
View File
@@ -58,6 +58,7 @@
#include "cmsys/Directory.hxx"
#include "cmsys/FStream.hxx"
#include "cmsys/Process.h"
#include "cmsys/RegularExpression.hxx"
#include "cmsys/Terminal.h"
int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg,
@@ -1711,7 +1712,6 @@ int cmcmd::WindowsCEEnvironment(const char* version, const std::string& name)
int cmcmd::RunPreprocessor(const std::vector<std::string>& command,
const std::string& intermediate_file)
{
cmUVProcessChainBuilder builder;
uv_fs_t fs_req;
@@ -1743,7 +1743,6 @@ int cmcmd::RunPreprocessor(const std::vector<std::string>& command,
return 1;
}
return 0;
}
@@ -1761,19 +1760,56 @@ int cmcmd::RunLLVMRC(std::vector<std::string> const& args)
std::cerr << "Invalid cmake_llvm_rc arguments";
return 1;
}
const std::string& intermediate_file = args[3];
const std::string& source_file = args[2];
std::vector<std::string> preprocess;
std::vector<std::string> resource_compile;
std::vector<std::string>* pArgTgt = &preprocess;
static const cmsys::RegularExpression llvm_rc_only_single_arg("^[-/](N|Y)");
static const cmsys::RegularExpression llvm_rc_only_double_arg(
"^[-/](C|LN|L)(.)?");
static const cmsys::RegularExpression common_double_arg(
"^[-/](D|U|I|FO|fo|Fo)(.)?");
bool acceptNextArg = false;
bool skipNextArg = false;
for (std::string const& arg : cmMakeRange(args).advance(4)) {
if (skipNextArg) {
skipNextArg = false;
continue;
}
// We use ++ as seperator between the preprocessing step definition and the
// rc compilation step becase we need to prepend a -- to seperate the
// source file properly from other options when using clang-cl for
// preprocessing.
if (arg == "++") {
pArgTgt = &resource_compile;
skipNextArg = false;
acceptNextArg = true;
} else {
cmsys::RegularExpressionMatch match;
if (!acceptNextArg) {
if (common_double_arg.find(arg.c_str(), match)) {
acceptNextArg = match.match(2).empty();
} else {
if (llvm_rc_only_single_arg.find(arg.c_str(), match)) {
if (pArgTgt == &preprocess) {
continue;
}
} else if (llvm_rc_only_double_arg.find(arg.c_str(), match)) {
if (pArgTgt == &preprocess) {
skipNextArg = match.match(2).empty();
continue;
}
acceptNextArg = match.match(2).empty();
} else if (pArgTgt == &resource_compile) {
continue;
}
}
} else {
acceptNextArg = false;
}
if (arg.find("SOURCE_DIR") != std::string::npos) {
std::string sourceDirArg = arg;
cmSystemTools::ReplaceString(
@@ -1793,10 +1829,14 @@ int cmcmd::RunLLVMRC(std::vector<std::string> const& args)
std::cerr << "Empty resource compilation command";
return 1;
}
// Since we might have skipped the last argument to llvm-rc
// we need to make sure the llvm-rc source file is present in the commandline
if (resource_compile.back() != intermediate_file) {
resource_compile.push_back(intermediate_file);
}
auto result = RunPreprocessor(preprocess, intermediate_file);
if (result != 0) {
cmSystemTools::RemoveFile(intermediate_file);
return result;
}