summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorThomas Bernard <thomas@famillebernardgouriou.fr>2020-10-22 21:06:17 (GMT)
committerBrad King <brad.king@kitware.com>2020-10-28 11:19:31 (GMT)
commitea03f508420845fef72fef06ba4c9a7dacbca5fe (patch)
tree4f81062ce233b38f76f36111b290ae26f53c2906 /Source/cmcmd.cxx
parentb3f1a292266099865e0896be9fd0d40803bda7e0 (diff)
downloadCMake-ea03f508420845fef72fef06ba4c9a7dacbca5fe.zip
CMake-ea03f508420845fef72fef06ba4c9a7dacbca5fe.tar.gz
CMake-ea03f508420845fef72fef06ba4c9a7dacbca5fe.tar.bz2
llvm_rc: add llvm_rc option filter to correctly pick up all options
Fixes: #21315
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx46
1 files changed, 43 insertions, 3 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index ea1f968..f094085 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -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;
}