Quellcode durchsuchen

fix *_compile_file, add base_compile_flags option

default_compile_flags
John Robinson vor 3 Jahren
Ursprung
Commit
9fe4263fad
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
3 geänderte Dateien mit 58 neuen und 12 gelöschten Zeilen
  1. +5
    -1
      res/toolchain-schema.json
  2. +35
    -9
      src/dds/toolchain/from_json.cpp
  3. +18
    -2
      src/dds/toolchain/from_json.test.cpp

+ 5
- 1
res/toolchain-schema.json Datei anzeigen

@@ -164,6 +164,10 @@
"description": "Set the base warning flags for the toolchain. These are always prepended to `warning_flags`.",
"$ref": "#/definitions/command_line_flags"
},
"base_compile_flags": {
"description": "Set the base compile flags for the toolchain. These are always prepended to `flags`.",
"$ref": "#/definitions/command_line_flags"
},
"c_compile_file": {
"description": "Set the command template for compiling C source files",
"$ref": "#/definitions/command_line_flags"
@@ -211,4 +215,4 @@
}
}
}
}
}

+ 35
- 9
src/dds/toolchain/from_json.cpp Datei anzeigen

@@ -76,6 +76,7 @@ toolchain dds::parse_toolchain_json_data(const json5::data& dat, std::string_vie
opt_string exe_prefix;
opt_string exe_suffix;
opt_string_seq base_warning_flags;
opt_string_seq base_compile_flags;
opt_string_seq include_template;
opt_string_seq external_include_template;
opt_string_seq define_template;
@@ -163,6 +164,7 @@ toolchain dds::parse_toolchain_json_data(const json5::data& dat, std::string_vie
KEY_EXTEND_FLAGS(external_include_template),
KEY_EXTEND_FLAGS(define_template),
KEY_EXTEND_FLAGS(base_warning_flags),
KEY_EXTEND_FLAGS(base_compile_flags),
KEY_EXTEND_FLAGS(c_compile_file),
KEY_EXTEND_FLAGS(cxx_compile_file),
KEY_EXTEND_FLAGS(create_archive),
@@ -182,6 +184,7 @@ toolchain dds::parse_toolchain_json_data(const json5::data& dat, std::string_vie
"external_include_template",
"define_template",
"base_warning_flags",
"base_compile_flags",
"c_compile_file",
"cxx_compile_file",
"create_archive",
@@ -504,19 +507,34 @@ toolchain dds::parse_toolchain_json_data(const json5::data& dat, std::string_vie
return ret;
};

auto get_flags = [&](language lang) -> string_seq {
auto get_default_compile_command = [&]() -> string_seq {
string_seq ret;
if (is_msvc) {
extend(ret, {"[flags]", "/c", "[in]", "/Fo[out]"});
} else if (is_gnu_like) {
extend(ret, {"[flags]", "-c", "[in]", "-o[out]"});
}
return ret;
};

auto get_base_compile_flags = [&](language lang) -> string_seq {
string_seq ret;
extend(ret, get_runtime_flags());
extend(ret, get_optim_flags());
extend(ret, get_debug_flags());
if (is_msvc) {
if (lang == language::cxx) {
extend(ret, {"/EHsc"});
}
extend(ret, {"/nologo", "/permissive-", "[flags]", "/c", "[in]", "/Fo[out]"});
extend(ret, {"/nologo", "/permissive-"});
} else if (is_gnu_like) {
extend(ret, {"-fPIC", "-pthread", "[flags]", "-c", "[in]", "-o[out]"});
extend(ret, {"-fPIC", "-pthread"});
}
return ret;
};

auto get_flags = [&](language lang) -> string_seq {
string_seq ret;
extend(ret, get_runtime_flags());
extend(ret, get_optim_flags());
extend(ret, get_debug_flags());
if (common_flags) {
extend(ret, *common_flags);
}
@@ -543,9 +561,13 @@ toolchain dds::parse_toolchain_json_data(const json5::data& dat, std::string_vie
extend(c, *compiler_launcher);
}
c.push_back(get_compiler_executable_path(language::c));
extend(c, get_flags(language::c));
return c;
});
extend(tc.c_compile, get_flags(language::c));
extend(tc.c_compile, read_opt(base_compile_flags, [&]() -> string_seq {
return get_base_compile_flags(language::c);
}));
extend(tc.c_compile, get_default_compile_command());

tc.cxx_compile = read_opt(cxx_compile_file, [&] {
string_seq cxx;
@@ -553,9 +575,13 @@ toolchain dds::parse_toolchain_json_data(const json5::data& dat, std::string_vie
extend(cxx, *compiler_launcher);
}
cxx.push_back(get_compiler_executable_path(language::cxx));
extend(cxx, get_flags(language::cxx));
return cxx;
});
extend(tc.cxx_compile, get_flags(language::cxx));
extend(tc.cxx_compile, read_opt(base_compile_flags, [&]() -> string_seq {
return get_base_compile_flags(language::cxx);
}));
extend(tc.cxx_compile, get_default_compile_command());

tc.include_template = read_opt(include_template, [&]() -> string_seq {
if (!compiler_id) {
@@ -712,4 +738,4 @@ toolchain dds::parse_toolchain_json_data(const json5::data& dat, std::string_vie
});

return tc.realize();
}
}

+ 18
- 2
src/dds/toolchain/from_json.test.cpp Datei anzeigen

@@ -77,6 +77,22 @@ TEST_CASE("Generating toolchain commands") {
"ar rcs stuff.a foo.o bar.o",
"g++ -fPIC foo.o bar.a -pthread -omeow.exe -O2 -g -gsplit-dwarf");

check_tc_compile(
"{compiler_id: 'gnu', flags: '-fno-rtti', advanced: {c_compile_file: 'g++ [flags] -c [in] -o[out]'}}",
"g++ -fno-rtti -fPIC -pthread -MD -MF foo.o.d -MQ foo.o -c foo.cpp -ofoo.o",
"g++ -fno-rtti -fPIC -pthread -Wall -Wextra -Wpedantic -Wconversion "
"-MD -MF foo.o.d -MQ foo.o -c foo.cpp -ofoo.o",
"ar rcs stuff.a foo.o bar.o",
"g++ -fPIC foo.o bar.a -pthread -omeow.exe");

check_tc_compile(
"{compiler_id: 'gnu', flags: '-fno-rtti', advanced: {base_compile_flags: '-fno-exceptions'}}",
"g++ -fno-rtti -fno-exceptions -MD -MF foo.o.d -MQ foo.o -c foo.cpp -ofoo.o",
"g++ -fno-rtti -fno-exceptions -Wall -Wextra -Wpedantic -Wconversion "
"-MD -MF foo.o.d -MQ foo.o -c foo.cpp -ofoo.o",
"ar rcs stuff.a foo.o bar.o",
"g++ -fPIC foo.o bar.a -pthread -omeow.exe");

check_tc_compile("{compiler_id: 'msvc'}",
"cl.exe /MT /EHsc /nologo /permissive- /showIncludes /c foo.cpp /Fofoo.o",
"cl.exe /MT /EHsc /nologo /permissive- /W4 /showIncludes /c foo.cpp /Fofoo.o",
@@ -106,8 +122,8 @@ TEST_CASE("Generating toolchain commands") {

check_tc_compile(
"{compiler_id: 'msvc', flags: '-DFOO'}",
"cl.exe /MT /EHsc /nologo /permissive- /showIncludes /c foo.cpp /Fofoo.o -DFOO",
"cl.exe /MT /EHsc /nologo /permissive- /W4 /showIncludes /c foo.cpp /Fofoo.o -DFOO",
"cl.exe /MT -DFOO /EHsc /nologo /permissive- /showIncludes /c foo.cpp /Fofoo.o",
"cl.exe /MT -DFOO /EHsc /nologo /permissive- /W4 /showIncludes /c foo.cpp /Fofoo.o",
"lib /nologo /OUT:stuff.a foo.o bar.o",
"cl.exe /nologo /EHsc foo.o bar.a /Femeow.exe /MT");


Laden…
Abbrechen
Speichern