Browse Source

fix *_compile_file, add base_compile_flags option

default_compile_flags
John Robinson 3 years ago
parent
commit
9fe4263fad
No known key found for this signature in database
3 changed files with 58 additions and 12 deletions
  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 View File

"description": "Set the base warning flags for the toolchain. These are always prepended to `warning_flags`.", "description": "Set the base warning flags for the toolchain. These are always prepended to `warning_flags`.",
"$ref": "#/definitions/command_line_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": { "c_compile_file": {
"description": "Set the command template for compiling C source files", "description": "Set the command template for compiling C source files",
"$ref": "#/definitions/command_line_flags" "$ref": "#/definitions/command_line_flags"
} }
} }
} }
}
}

+ 35
- 9
src/dds/toolchain/from_json.cpp View File

opt_string exe_prefix; opt_string exe_prefix;
opt_string exe_suffix; opt_string exe_suffix;
opt_string_seq base_warning_flags; opt_string_seq base_warning_flags;
opt_string_seq base_compile_flags;
opt_string_seq include_template; opt_string_seq include_template;
opt_string_seq external_include_template; opt_string_seq external_include_template;
opt_string_seq define_template; opt_string_seq define_template;
KEY_EXTEND_FLAGS(external_include_template), KEY_EXTEND_FLAGS(external_include_template),
KEY_EXTEND_FLAGS(define_template), KEY_EXTEND_FLAGS(define_template),
KEY_EXTEND_FLAGS(base_warning_flags), KEY_EXTEND_FLAGS(base_warning_flags),
KEY_EXTEND_FLAGS(base_compile_flags),
KEY_EXTEND_FLAGS(c_compile_file), KEY_EXTEND_FLAGS(c_compile_file),
KEY_EXTEND_FLAGS(cxx_compile_file), KEY_EXTEND_FLAGS(cxx_compile_file),
KEY_EXTEND_FLAGS(create_archive), KEY_EXTEND_FLAGS(create_archive),
"external_include_template", "external_include_template",
"define_template", "define_template",
"base_warning_flags", "base_warning_flags",
"base_compile_flags",
"c_compile_file", "c_compile_file",
"cxx_compile_file", "cxx_compile_file",
"create_archive", "create_archive",
return ret; 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; string_seq ret;
extend(ret, get_runtime_flags());
extend(ret, get_optim_flags());
extend(ret, get_debug_flags());
if (is_msvc) { if (is_msvc) {
if (lang == language::cxx) { if (lang == language::cxx) {
extend(ret, {"/EHsc"}); extend(ret, {"/EHsc"});
} }
extend(ret, {"/nologo", "/permissive-", "[flags]", "/c", "[in]", "/Fo[out]"});
extend(ret, {"/nologo", "/permissive-"});
} else if (is_gnu_like) { } 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) { if (common_flags) {
extend(ret, *common_flags); extend(ret, *common_flags);
} }
extend(c, *compiler_launcher); extend(c, *compiler_launcher);
} }
c.push_back(get_compiler_executable_path(language::c)); c.push_back(get_compiler_executable_path(language::c));
extend(c, get_flags(language::c));
return 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, [&] { tc.cxx_compile = read_opt(cxx_compile_file, [&] {
string_seq cxx; string_seq cxx;
extend(cxx, *compiler_launcher); extend(cxx, *compiler_launcher);
} }
cxx.push_back(get_compiler_executable_path(language::cxx)); cxx.push_back(get_compiler_executable_path(language::cxx));
extend(cxx, get_flags(language::cxx));
return 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 { tc.include_template = read_opt(include_template, [&]() -> string_seq {
if (!compiler_id) { if (!compiler_id) {
}); });


return tc.realize(); return tc.realize();
}
}

+ 18
- 2
src/dds/toolchain/from_json.test.cpp View File

"ar rcs stuff.a foo.o bar.o", "ar rcs stuff.a foo.o bar.o",
"g++ -fPIC foo.o bar.a -pthread -omeow.exe -O2 -g -gsplit-dwarf"); "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'}", check_tc_compile("{compiler_id: 'msvc'}",
"cl.exe /MT /EHsc /nologo /permissive- /showIncludes /c foo.cpp /Fofoo.o", "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", "cl.exe /MT /EHsc /nologo /permissive- /W4 /showIncludes /c foo.cpp /Fofoo.o",


check_tc_compile( check_tc_compile(
"{compiler_id: 'msvc', flags: '-DFOO'}", "{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", "lib /nologo /OUT:stuff.a foo.o bar.o",
"cl.exe /nologo /EHsc foo.o bar.a /Femeow.exe /MT"); "cl.exe /nologo /EHsc foo.o bar.a /Femeow.exe /MT");



Loading…
Cancel
Save