diff options
author | Brad King <brad.king@kitware.com> | 2023-06-08 14:45:05 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-06-08 14:45:45 (GMT) |
commit | aebf8ad1aa2f4ee420c1c6b86f1b52eaed4d747a (patch) | |
tree | 05237f3c9cdfb8305911cf865905e41038b328f1 | |
parent | 52970dcaba0d1c00736f5319a97cb07acad3b1dd (diff) | |
parent | 0e1abf7afaa381b97cdc1435b42c7cfb00efa4e7 (diff) | |
download | CMake-aebf8ad1aa2f4ee420c1c6b86f1b52eaed4d747a.zip CMake-aebf8ad1aa2f4ee420c1c6b86f1b52eaed4d747a.tar.gz CMake-aebf8ad1aa2f4ee420c1c6b86f1b52eaed4d747a.tar.bz2 |
Merge topic 'cmcldeps-rc' into release-3.27
0e1abf7afa cmcldeps: Avoid passing /nologo more than once to RC compiler
f694e8d9c8 cmcldeps: Do not pass linker flags to cl
8600fb263b cmcldeps: Remove unused C and CXX support
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8541
-rw-r--r-- | Source/cmcldeps.cxx | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/Source/cmcldeps.cxx b/Source/cmcldeps.cxx index 69eb19e..72805d3 100644 --- a/Source/cmcldeps.cxx +++ b/Source/cmcldeps.cxx @@ -176,21 +176,6 @@ static void outputDepFile(const std::string& dfile, const std::string& objfile, fclose(out); } -bool contains(const std::string& str, const std::string& what) -{ - return str.find(what) != std::string::npos; -} - -std::string replace(const std::string& str, const std::string& what, - const std::string& replacement) -{ - size_t pos = str.find(what); - if (pos == std::string::npos) - return str; - std::string replaced = str; - return replaced.replace(pos, what.size(), replacement); -} - static int process(cm::string_view srcfilename, const std::string& dfile, const std::string& objfile, const std::string& prefix, const std::string& cmd, const std::string& dir = "", @@ -262,21 +247,26 @@ int main() srcfilename = srcfilename.substr(pos + 1); } - std::string nol = " /nologo "; - std::string show = " /showIncludes "; - if (lang == "C" || lang == "CXX") { - return process(srcfilename, dfile, objfile, prefix, - binpath + nol + show + rest); - } else if (lang == "RC") { + if (lang == "RC") { // "misuse" cl.exe to get headers from .rc files + // Make sure there is at most one /nologo option. + bool const haveNologo = (rest.find("/nologo ") != std::string::npos || + rest.find("-nologo ") != std::string::npos); + cmSystemTools::ReplaceString(rest, "-nologo ", " "); + cmSystemTools::ReplaceString(rest, "/nologo ", " "); std::string clrest = rest; - // rc: /fo x.dir\x.rc.res -> cl: /out:x.dir\x.rc.res.dep.obj - clrest = replace(clrest, "/fo ", "/out:"); - clrest = replace(clrest, "-fo ", "-out:"); - clrest = replace(clrest, objfile, objfile + ".dep.obj "); + if (haveNologo) { + rest = "/nologo " + rest; + } + + // rc /fo X.dir\x.rc.res => cl -FoX.dir\x.rc.res.obj + // The object will not actually be written. + cmSystemTools::ReplaceString(clrest, "/fo ", " "); + cmSystemTools::ReplaceString(clrest, "-fo ", " "); + cmSystemTools::ReplaceString(clrest, objfile, "-Fo" + objfile + ".obj"); - cl = "\"" + cl + "\" /P /DRC_INVOKED /TC "; + cl = "\"" + cl + "\" /P /DRC_INVOKED /nologo /showIncludes /TC "; // call cl in object dir so the .i is generated there std::string objdir; @@ -288,8 +278,8 @@ int main() } // extract dependencies with cl.exe - int exit_code = process(srcfilename, dfile, objfile, prefix, - cl + nol + show + clrest, objdir, true); + int exit_code = + process(srcfilename, dfile, objfile, prefix, cl + clrest, objdir, true); if (exit_code != 0) return exit_code; |