From: Joel Rosdahl Date: Thu, 25 Aug 2022 19:15:01 +0000 (+0200) Subject: fix: Use -P -Fi for saving MSVC preprocessor output X-Git-Tag: v4.7~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80a228c3c2014d9953b51ed3ade7ad21f50912f8;p=thirdparty%2Fccache.git fix: Use -P -Fi for saving MSVC preprocessor output Even though MSVC supports "-E" and "-c -o" it apparently doesn't support "-E -o", so [1] broke MSVC. [1]: 64fc42ca2c5c9fe60ef4f1dc3882edb5f35579d6 Fixes #1146. --- diff --git a/src/ccache.cpp b/src/ccache.cpp index 6b44e39e7..4f2ae2a34 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1146,16 +1146,22 @@ get_result_key_from_cpp(Context& ctx, Args& args, Hash& hash) ctx.register_pending_tmp_file(preprocessed_path); const size_t orig_args_size = args.size(); - args.push_back("-E"); + if (ctx.config.keep_comments_cpp()) { args.push_back("-C"); } - // Pass -o instead of sending the preprocessor output to stdout to work - // around compilers that don't exit with a proper status on write error to - // stdout. See also . - args.push_back("-o"); - args.push_back(preprocessed_path); + // Send preprocessor output to a file instead of stdout to work around + // compilers that don't exit with a proper status on write error to stdout. + // See also . + if (ctx.config.is_compiler_group_msvc()) { + args.push_back("-P"); + args.push_back(FMT("-Fi{}", preprocessed_path)); + } else { + args.push_back("-E"); + args.push_back("-o"); + args.push_back(preprocessed_path); + } args.push_back(ctx.args_info.input_file);