소스 검색

toolchain_prep simplifies creation of toolchain objects

default_compile_flags
vector-of-bool 5 년 전
부모
커밋
a5251f877e
4개의 변경된 파일93개의 추가작업 그리고 26개의 파일을 삭제
  1. +7
    -0
      src/dds/toolchain/prep.cpp
  2. +30
    -0
      src/dds/toolchain/prep.hpp
  3. +38
    -17
      src/dds/toolchain/toolchain.cpp
  4. +18
    -9
      src/dds/toolchain/toolchain.hpp

+ 7
- 0
src/dds/toolchain/prep.cpp 파일 보기

@@ -0,0 +1,7 @@
#include "./prep.hpp"

#include <dds/toolchain/toolchain.hpp>

using namespace dds;

toolchain toolchain_prep::realize() const { return toolchain::realize(*this); }

+ 30
- 0
src/dds/toolchain/prep.hpp 파일 보기

@@ -0,0 +1,30 @@
#pragma once

#include <string>
#include <vector>

namespace dds {

class toolchain;

struct toolchain_prep {
using string_seq = std::vector<std::string>;
string_seq c_compile;
string_seq cxx_compile;
string_seq include_template;
string_seq define_template;
string_seq link_archive;
string_seq link_exe;
string_seq warning_flags;

std::string archive_prefix;
std::string archive_suffix;
std::string object_prefix;
std::string object_suffix;
std::string exe_prefix;
std::string exe_suffix;

toolchain realize() const;
};

} // namespace dds

+ 38
- 17
src/dds/toolchain/toolchain.cpp 파일 보기

@@ -1,5 +1,6 @@
#include "./toolchain.hpp"

#include <dds/toolchain/prep.hpp>
#include <dds/util/algo.hpp>
#include <dds/util/string.hpp>

@@ -27,6 +28,24 @@ struct invalid_toolchain : std::runtime_error {

} // namespace

toolchain toolchain::realize(const toolchain_prep& prep) {
toolchain ret;
ret._c_compile = prep.c_compile;
ret._cxx_compile = prep.cxx_compile;
ret._inc_template = prep.include_template;
ret._def_template = prep.define_template;
ret._link_archive = prep.link_archive;
ret._link_exe = prep.link_exe;
ret._warning_flags = prep.warning_flags;
ret._archive_prefix = prep.archive_prefix;
ret._archive_suffix = prep.archive_suffix;
ret._object_prefix = prep.object_prefix;
ret._object_suffix = prep.object_suffix;
ret._exe_prefix = prep.exe_prefix;
ret._exe_suffix = prep.exe_suffix;
return ret;
}

toolchain toolchain::load_from_file(fs::path p) {
opt_string inc_template;
opt_string def_template;
@@ -37,6 +56,7 @@ toolchain toolchain::load_from_file(fs::path p) {
opt_string link_exe_template;
opt_string warning_flags;

opt_string archive_prefix;
opt_string archive_suffix;
opt_string object_suffix;
opt_string exe_suffix;
@@ -75,6 +95,7 @@ toolchain toolchain::load_from_file(fs::path p) {
|| try_single("Create-Archive-Template", create_archive_template)
|| try_single("Link-Executable-Template", link_exe_template)
|| try_single("Warning-Flags", warning_flags)
|| try_single("Archive-Prefix", archive_prefix)
|| try_single("Archive-Suffix", archive_suffix)
|| try_single("Object-Suffix", object_suffix)
|| try_single("Executable-Suffix", exe_suffix)
@@ -108,6 +129,7 @@ toolchain toolchain::load_from_file(fs::path p) {
create_archive_template.value(),
link_exe_template.value(),
warning_flags.value_or(""),
archive_prefix.value_or("lib"),
archive_suffix.value(),
object_suffix.value(),
exe_suffix.value(),
@@ -210,7 +232,7 @@ vector<string> toolchain::create_compile_command(const compile_file_spec& spec)

vector<string> toolchain::create_archive_command(const archive_spec& spec) const noexcept {
vector<string> cmd;
for (auto& arg : _archive_template) {
for (auto& arg : _link_archive) {
if (arg == "<IN>") {
std::transform(spec.input_files.begin(),
spec.input_files.end(),
@@ -225,7 +247,7 @@ vector<string> toolchain::create_archive_command(const archive_spec& spec) const

vector<string> toolchain::create_link_executable_command(const link_exe_spec& spec) const noexcept {
vector<string> cmd;
for (auto& arg : _link_exe_template) {
for (auto& arg : _link_exe) {
if (arg == "<IN>") {
std::transform(spec.inputs.begin(),
spec.inputs.end(),
@@ -250,12 +272,12 @@ std::optional<toolchain> toolchain::get_builtin(std::string_view s) noexcept {
}

if (starts_with(s, "gcc") || starts_with(s, "clang")) {
ret._inc_template = {"-isystem", "<PATH>"};
ret._def_template = {"-D", "<DEF>"};
ret._archive_suffix = ".a";
ret._object_suffix = ".o";
ret._warning_flags = {"-Wall", "-Wextra"};
ret._archive_template = {"ar", "rcs", "<OUT>", "<IN>"};
ret._inc_template = {"-isystem", "<PATH>"};
ret._def_template = {"-D", "<DEF>"};
ret._archive_suffix = ".a";
ret._object_suffix = ".o";
ret._warning_flags = {"-Wall", "-Wextra"};
ret._link_archive = {"ar", "rcs", "<OUT>", "<IN>"};

std::vector<std::string> common_flags = {
"<FLAGS>",
@@ -311,8 +333,8 @@ std::optional<toolchain> toolchain::get_builtin(std::string_view s) noexcept {
extend(ret._cxx_compile, common_flags);
extend(ret._cxx_compile, cxx_flags);

ret._link_exe_template.push_back(cxx_compiler_name);
extend(ret._link_exe_template,
ret._link_exe.push_back(cxx_compiler_name);
extend(ret._link_exe,
{
"-g",
"-fPIC",
@@ -339,13 +361,12 @@ std::optional<toolchain> toolchain::get_builtin(std::string_view s) noexcept {
std::vector<std::string_view> common_flags = {"/Z7", "/O2", "/MT", "/DEBUG"};
extend(ret._c_compile, common_flags);
extend(ret._cxx_compile, common_flags);
ret._archive_suffix = ".lib";
ret._object_suffix = ".obj";
ret._exe_suffix = ".exe";
ret._archive_template = {"lib", "/nologo", "/OUT:<OUT>", "<IN>"};
ret._link_exe_template
= {"cl.exe", "/nologo", "/std:c++latest", "/EHsc", "<IN>", "/Fe<OUT>"};
ret._warning_flags = {"/W4"};
ret._archive_suffix = ".lib";
ret._object_suffix = ".obj";
ret._exe_suffix = ".exe";
ret._link_archive = {"lib", "/nologo", "/OUT:<OUT>", "<IN>"};
ret._link_exe = {"cl.exe", "/nologo", "/std:c++latest", "/EHsc", "<IN>", "/Fe<OUT>"};
ret._warning_flags = {"/W4"};
} else {
return std::nullopt;
}

+ 18
- 9
src/dds/toolchain/toolchain.hpp 파일 보기

@@ -35,18 +35,24 @@ struct link_exe_spec {
fs::path output;
};

class toolchain_prep;

class toolchain {
using string_seq = std::vector<std::string>;

string_seq _c_compile;
string_seq _cxx_compile;
string_seq _inc_template;
string_seq _def_template;
string_seq _archive_template;
string_seq _link_exe_template;
string_seq _warning_flags;
string_seq _c_compile;
string_seq _cxx_compile;
string_seq _inc_template;
string_seq _def_template;
string_seq _link_archive;
string_seq _link_exe;
string_seq _warning_flags;

std::string _archive_prefix;
std::string _archive_suffix;
std::string _object_prefix;
std::string _object_suffix;
std::string _exe_prefix;
std::string _exe_suffix;

public:
@@ -59,6 +65,7 @@ public:
std::string_view archive_template,
std::string_view link_exe_template,
std::string_view warning_flags,
std::string_view archive_prefix,
std::string_view archive_suffix,
std::string_view object_suffix,
std::string_view exe_suffix)
@@ -66,13 +73,15 @@ public:
, _cxx_compile(split_shell_string(cxx_compile))
, _inc_template(split_shell_string(inc_template))
, _def_template(split_shell_string(def_template))
, _archive_template(split_shell_string(archive_template))
, _link_exe_template(split_shell_string(link_exe_template))
, _link_archive(split_shell_string(archive_template))
, _link_exe(split_shell_string(link_exe_template))
, _warning_flags(split_shell_string(warning_flags))
, _archive_prefix(archive_prefix)
, _archive_suffix(archive_suffix)
, _object_suffix(object_suffix)
, _exe_suffix(exe_suffix) {}

static toolchain realize(const toolchain_prep&);
static toolchain load_from_file(fs::path);

auto& archive_suffix() const noexcept { return _archive_suffix; }

Loading…
취소
저장