Skip to content

Commit b7dd0c5

Browse files
committed
Add IAR support.
1 parent 0f65ff4 commit b7dd0c5

7 files changed

Lines changed: 67 additions & 1 deletion

File tree

doc/manual.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ _<<Using ccache with other compiler wrappers>>_.
629629
clang-cl.
630630
*gcc*::
631631
GCC-based compiler.
632+
*icc*::
633+
IAR compiler.
632634
*icl*::
633635
Intel compiler on Windows.
634636
*icx*::

src/ccache/argprocessing.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,43 @@ process_option_arg(const Context& ctx,
421421
return Statistic::called_for_preprocessing;
422422
}
423423

424+
if (arg == "-lC" && config.compiler_type() == CompilerType::icc) {
425+
if (i == args.size() - 1) {
426+
LOG("Expected argument after {}", args[i]);
427+
return Statistic::bad_compiler_arguments;
428+
}
429+
430+
// TODO: should the arg to output the preprocessor output
431+
// be added to the state?
432+
433+
++i;
434+
return Statistic::none;
435+
}
436+
437+
if (util::starts_with(arg, "--dependencies")
438+
&& config.compiler_type() == CompilerType::icc) {
439+
if (i == args.size() - 1) {
440+
LOG("Expected 1 arguments after {}", args[i]);
441+
return Statistic::bad_compiler_arguments;
442+
}
443+
444+
state.found_md_or_mmd_opt = true;
445+
state.found_mf_opt = true;
446+
args_info.generating_dependencies = true;
447+
state.add_compiler_only_arg(args[i]);
448+
449+
std::string dep_file{args[i+1]};
450+
if (state.output_dep_origin <= OutputDepOrigin::mf) {
451+
state.output_dep_origin = OutputDepOrigin::mf;
452+
args_info.output_dep = core::make_relative_path(ctx, dep_file);
453+
}
454+
455+
state.add_compiler_only_arg(args_info.output_dep);
456+
457+
i++;
458+
return Statistic::none;
459+
}
460+
424461
// Handle "@file" argument.
425462
if (util::starts_with(arg, "@") || util::starts_with(arg, "-@")) {
426463
const char* argpath = arg.c_str() + 1;
@@ -710,6 +747,7 @@ process_option_arg(const Context& ctx,
710747
return Statistic::bad_compiler_arguments;
711748
}
712749
args_info.output_obj = args[i + 1];
750+
LOG("Found output: {}", args_info.output_obj);
713751
i++;
714752
return Statistic::none;
715753
}
@@ -804,6 +842,12 @@ process_option_arg(const Context& ctx,
804842
return Statistic::none;
805843
}
806844

845+
if (arg == "--debug" && config.compiler_type() == CompilerType::icc) {
846+
state.add_common_arg(args[i]);
847+
args_info.generating_debuginfo = true;
848+
return Statistic::none;
849+
}
850+
807851
if (config.is_compiler_group_msvc() && !config.is_compiler_group_clang()
808852
&& is_msvc_z_debug_option(arg)) {
809853
state.last_seen_msvc_z_debug_option = args[i];
@@ -1369,7 +1413,8 @@ process_args(Context& ctx)
13691413

13701414
const bool is_link =
13711415
!(state.found_c_opt || state.found_dc_opt || state.found_S_opt
1372-
|| state.found_syntax_only || state.found_analyze_opt);
1416+
|| state.found_syntax_only || state.found_analyze_opt
1417+
|| config.compiler_type() == CompilerType::icc);
13731418

13741419
if (state.input_files.empty()) {
13751420
LOG_RAW("No input file found");

src/ccache/ccache.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ do_guess_compiler(const fs::path& path)
327327
return CompilerType::gcc;
328328
} else if (name.find("nvcc") != std::string_view::npos) {
329329
return CompilerType::nvcc;
330+
} else if (name.find("icc") != std::string_view::npos) {
331+
return CompilerType::icc;
330332
} else if (name == "icl") {
331333
return CompilerType::icl;
332334
} else if (name == "icx") {
@@ -2825,6 +2827,13 @@ do_cache_compilation(Context& ctx)
28252827
}
28262828
}
28272829

2830+
if (ctx.config.compiler_type() == CompilerType::icc
2831+
&& (!ctx.config.depend_mode() || !ctx.config.direct_mode())) {
2832+
LOG_RAW("IAR icc is only supported when both depend mode and direct mode are "
2833+
"enabled.");
2834+
return tl::unexpected(Statistic::disabled);
2835+
}
2836+
28282837
if (ctx.config.depend_mode()
28292838
&& !(ctx.args_info.generating_dependencies
28302839
|| ctx.args_info.generating_includes)) {

src/ccache/compopt.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ const CompOpt compopts[] = {
5656
{"--compiler-options", AFFECTS_CPP | TAKES_ARG }, // nvcc
5757
{"--config", TAKES_ARG }, // Clang
5858
{"--em-config", TAKES_ARG }, // emcc
59+
{"--f", TOO_HARD }, // icc
5960
{"--gcc-toolchain=", TAKES_CONCAT_ARG | TAKES_PATH }, // Clang
6061
{"--include", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
6162
{"--libdevice-directory", AFFECTS_CPP | TAKES_ARG }, // nvcc
6263
{"--offload-compress", AFFECTS_COMP }, // Clang
6364
{"--output-directory", AFFECTS_CPP | TAKES_ARG }, // nvcc
6465
{"--param", TAKES_ARG },
66+
{"--predef_macros", TOO_HARD }, // icc
67+
{"--preprocess", TOO_HARD }, // icc
6568
{"--save-temps", TOO_HARD },
6669
{"--save-temps=cwd", TOO_HARD },
6770
{"--save-temps=obj", TOO_HARD },
@@ -124,6 +127,7 @@ const CompOpt compopts[] = {
124127
{"-emit-pth", AFFECTS_COMP }, // Clang
125128
{"-external:I",
126129
AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH }, // msvc
130+
{"-f", TOO_HARD }, // icc
127131
{"-fbuild-session-file=", TAKES_CONCAT_ARG | TAKES_PATH },
128132
{"-fmodule-header", TOO_HARD },
129133
{"-fmodule-map-file=", TAKES_CONCAT_ARG | TAKES_PATH },

src/ccache/config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ parse_compiler_type(const std::string& value)
287287
return CompilerType::clang_cl;
288288
} else if (value == "gcc") {
289289
return CompilerType::gcc;
290+
} else if (value == "icc") {
291+
return CompilerType::icc;
290292
} else if (value == "icl") {
291293
return CompilerType::icl;
292294
} else if (value == "icx") {
@@ -546,6 +548,7 @@ compiler_type_to_string(CompilerType compiler_type)
546548

547549
CASE(clang);
548550
CASE(gcc);
551+
CASE(icc);
549552
CASE(icl);
550553
CASE(icx);
551554
CASE(msvc);

src/ccache/config.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum class CompilerType {
4040
clang,
4141
clang_cl,
4242
gcc,
43+
icc,
4344
icl,
4445
icx,
4546
icx_cl,

unittest/test_ccache.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ TEST_CASE("guess_compiler")
197197
CHECK(guess_compiler("/test/prefix/nvcc") == CompilerType::nvcc);
198198
CHECK(guess_compiler("/test/prefix/nvcc-10.1.243") == CompilerType::nvcc);
199199

200+
CHECK(guess_compiler("/test/prefix/iccarm") == CompilerType::icc);
201+
200202
CHECK(guess_compiler("/test/prefix/x") == CompilerType::other);
201203
CHECK(guess_compiler("/test/prefix/cc") == CompilerType::other);
202204
CHECK(guess_compiler("/test/prefix/c++") == CompilerType::other);

0 commit comments

Comments
 (0)