Skip to content

Toolchain ID #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion buildcc/lib/target/test/target/test_base_target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ TEST_GROUP(TargetBaseTestGroup)
{
};
// clang-format on
static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

TEST(TargetBaseTestGroup, InvalidTargetType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ TEST_GROUP(TargetTestCCompileFlagsGroup)
};
// clang-format on

static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

static const fs::path target_source_intermediate_path =
fs::path(BUILD_TARGET_C_COMPILE_INTERMEDIATE_DIR) / gcc.GetName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ TEST_GROUP(TargetTestCppCompileFlagsGroup)
};
// clang-format on

static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

static const fs::path target_source_intermediate_path =
fs::path(BUILD_TARGET_CPP_COMPILE_INTERMEDIATE_DIR) / gcc.GetName();

Expand Down
4 changes: 3 additions & 1 deletion buildcc/lib/target/test/target/test_target_external_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ TEST_GROUP(TargetTestExternalLib)
};
// clang-format on

static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

static const fs::path intermediate_path =
fs::path(BUILD_TARGET_EXTERNAL_LIB_INTERMEDIATE_DIR) / gcc.GetName();

Expand Down
4 changes: 3 additions & 1 deletion buildcc/lib/target/test/target/test_target_include_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ TEST_GROUP(TargetTestIncludeDirGroup)
};
// clang-format on

static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

static const fs::path target_include_dir_intermediate_path =
fs::path(BUILD_TARGET_INCLUDE_DIR_INTERMEDIATE_DIR) / gcc.GetName();

Expand Down
4 changes: 3 additions & 1 deletion buildcc/lib/target/test/target/test_target_lib_dep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ TEST_GROUP(TargetTestLibDep)
};
// clang-format on

static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

static const fs::path intermediate_path =
fs::path(BUILD_TARGET_LIB_DEP_INTERMEDIATE_DIR) / gcc.GetName();

Expand Down
4 changes: 3 additions & 1 deletion buildcc/lib/target/test/target/test_target_link_flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ TEST_GROUP(TargetTestLinkFlagsGroup)
};
// clang-format on

static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

static const fs::path target_source_intermediate_path =
fs::path(BUILD_TARGET_LINK_INTERMEDIATE_DIR) / gcc.GetName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ TEST_GROUP(TargetTestPreprocessorFlagGroup)
};
// clang-format on

static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

static const fs::path target_source_intermediate_path =
fs::path(BUILD_TARGET_PREPROCESSOR_INTERMEDIATE_DIR) / gcc.GetName();

Expand Down
4 changes: 3 additions & 1 deletion buildcc/lib/target/test/target/test_target_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ TEST_GROUP(TargetTestSourceGroup)
};
// clang-format on

static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

static const fs::path target_source_intermediate_path =
fs::path(BUILD_TARGET_SOURCE_INTERMEDIATE_DIR) / gcc.GetName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ TEST_GROUP(TargetTestSourceOutOfRootGroup)
};
// clang-format on

static const buildcc::base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar",
static const buildcc::base::Toolchain gcc(buildcc::base::Toolchain::Id::Gcc,
"gcc", "as", "gcc", "g++", "ar",
"ld");

static const fs::path target_source_intermediate_path =
fs::path(BUILD_TARGET_SOURCE_OUT_OF_ROOT_INTERMEDIATE_DIR) / gcc.GetName();

Expand Down
7 changes: 2 additions & 5 deletions buildcc/lib/toolchain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Toolchain lib
m_clangtidy("toolchain")
add_library(toolchain
toolchain.cpp
add_library(toolchain INTERFACE
toolchain.h
)
target_include_directories(toolchain PUBLIC
target_include_directories(toolchain INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${BUILDCC_INSTALL_HEADER_PREFIX}>
)
target_compile_options(toolchain PRIVATE ${BUILD_COMPILE_FLAGS})
target_link_options(toolchain PRIVATE ${BUILD_LINK_FLAGS})

# TODO, Add Mocks here if required

Expand Down
17 changes: 0 additions & 17 deletions buildcc/lib/toolchain/toolchain.cpp

This file was deleted.

20 changes: 15 additions & 5 deletions buildcc/lib/toolchain/toolchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ namespace buildcc::base {
// Base toolchain class
class Toolchain {
public:
explicit Toolchain(std::string_view name, std::string_view asm_compiler,
std::string_view c_compiler, std::string_view cpp_compiler,
std::string_view archiver, std::string_view linker)
: name_(name), asm_compiler_(asm_compiler), c_compiler_(c_compiler),
cpp_compiler_(cpp_compiler), archiver_(archiver), linker_(linker) {}
enum class Id {
Gcc = 0,
Msvc,
Clang,
};

public:
explicit Toolchain(Id id, std::string_view name,
std::string_view asm_compiler, std::string_view c_compiler,
std::string_view cpp_compiler, std::string_view archiver,
std::string_view linker)
: id_(id), name_(name), asm_compiler_(asm_compiler),
c_compiler_(c_compiler), cpp_compiler_(cpp_compiler),
archiver_(archiver), linker_(linker) {}

Toolchain(const Toolchain &toolchain) = delete;

Expand All @@ -43,6 +52,7 @@ class Toolchain {
const std::string &GetLinker() const { return linker_; }

private:
Id id_;
std::string name_;
std::string asm_compiler_;
std::string c_compiler_;
Expand Down
3 changes: 2 additions & 1 deletion buildcc/toolchains/toolchain_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace buildcc {

class Toolchain_gcc : public base::Toolchain {
public:
Toolchain_gcc() : Toolchain("gcc", "as", "gcc", "g++", "ar", "ld") {}
Toolchain_gcc()
: Toolchain(Toolchain::Id::Gcc, "gcc", "as", "gcc", "g++", "ar", "ld") {}
Toolchain_gcc(const Toolchain_gcc &gcc) = delete;
};

Expand Down
4 changes: 3 additions & 1 deletion buildcc/toolchains/toolchain_msvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ namespace buildcc {

class Toolchain_msvc : public base::Toolchain {
public:
Toolchain_msvc() : Toolchain("msvc", "cl", "cl", "cl", "lib", "link") {}
Toolchain_msvc()
: Toolchain(Toolchain::Id::Msvc, "msvc", "cl", "cl", "cl", "lib",
"link") {}
Toolchain_msvc(const Toolchain_msvc &gcc) = delete;
};

Expand Down
3 changes: 2 additions & 1 deletion example/gcc/AfterInstall/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ int main(void) {
env::set_log_level(env::LogLevel::Trace);

// Stored as a const & in target
base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar", "ld");
base::Toolchain gcc(base::Toolchain::Id::Gcc, "gcc", "as", "gcc", "g++", "ar",
"ld");

// CppTarget
ExecutableTarget_gcc cpptarget("CppFlags.exe", gcc, "files");
Expand Down
3 changes: 2 additions & 1 deletion example/gcc/DynamicLib/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ int main(void) {
env::init(BUILD_ROOT, BUILD_INTERMEDIATE_DIR);
env::set_log_level(env::LogLevel::Trace);

base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar", "ld");
base::Toolchain gcc(base::Toolchain::Id::Gcc, "gcc", "as", "gcc", "g++", "ar",
"ld");

// Linux GCC
#if OS == LINUX
Expand Down
3 changes: 2 additions & 1 deletion example/gcc/Flags/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ int main(void) {
env::set_log_level(env::LogLevel::Trace);

// Stored as a const & in target
base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar", "ld");
base::Toolchain gcc(base::Toolchain::Id::Gcc, "gcc", "as", "gcc", "g++", "ar",
"ld");

// CppTarget
ExecutableTarget_gcc cpptarget("CppFlags.exe", gcc, "files");
Expand Down
3 changes: 2 additions & 1 deletion example/gcc/IncludeDir/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ int main(void) {
env::set_log_level(env::LogLevel::Trace);

// Stored as const & in target
base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar", "ld");
base::Toolchain gcc(base::Toolchain::Id::Gcc, "gcc", "as", "gcc", "g++", "ar",
"ld");

ExecutableTarget_gcc target("IncludeDir.exe", gcc, "files");
target.AddSource("main.cpp", "src");
Expand Down
3 changes: 2 additions & 1 deletion example/gcc/Plugins/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ int main(void) {
env::set_log_level(env::LogLevel::Trace);

// CppTarget
base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar", "ld");
base::Toolchain gcc(base::Toolchain::Id::Gcc, "gcc", "as", "gcc", "g++", "ar",
"ld");
ExecutableTarget_gcc cppflags("CppFlags.exe", gcc, "files");

cppflags.AddSource("main.cpp", "src");
Expand Down
3 changes: 2 additions & 1 deletion example/gcc/Simple/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ int main(void) {
env::set_log_level(env::LogLevel::Trace);

// Stored as const & in target
base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar", "ld");
base::Toolchain gcc(base::Toolchain::Id::Gcc, "gcc", "as", "gcc", "g++", "ar",
"ld");

ExecutableTarget_gcc target("Simple.exe", gcc, "");
target.AddSource("main.cpp");
Expand Down
3 changes: 2 additions & 1 deletion example/gcc/StaticLib/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ int main(void) {
env::init(BUILD_ROOT, BUILD_INTERMEDIATE_DIR);
env::set_log_level(env::LogLevel::Trace);

base::Toolchain gcc("gcc", "as", "gcc", "g++", "ar", "ld");
base::Toolchain gcc(base::Toolchain::Id::Gcc, "gcc", "as", "gcc", "g++", "ar",
"ld");

StaticTarget_gcc randomLib("libran.a", gcc, "files");
randomLib.AddSource("src/random.cpp");
Expand Down
4 changes: 2 additions & 2 deletions example/hybrid/custom_target/build.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ int main(int argc, char **argv) {
reg.Build(args.GetMsvcToolchain(), m_foolib, mfoolib_build_cb);

// * NOTE, This is how we add our custom toolchain
base::Toolchain clang("clang_gnu", "llvm-as", "clang", "clang++", "llvm-ar",
"ld");
base::Toolchain clang(base::Toolchain::Id::Clang, "clang_gnu", "llvm-as",
"clang", "clang++", "llvm-ar", "ld");
// * NOTE, Custom clang target added above
ExecutableTarget_clang c_foolib("CFoolib.exe", clang, "");
reg.Build(clang_gnu, c_foolib, cfoolib_build_cb);
Expand Down
1 change: 0 additions & 1 deletion example/msvc/DynamicLib/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ int main(void) {
env::init(BUILD_SCRIPT_SOURCE, BUILD_SCRIPT_FOLDER);
env::set_log_level(env::LogLevel::Debug);

// base::Toolchain msvc("msvc", "cl", "cl", "cl", "lib", "link");
Toolchain_msvc msvc;

DynamicTarget_msvc dynamictarget("librandom.lib", msvc, "");
Expand Down
1 change: 0 additions & 1 deletion example/msvc/Executable/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ int main(void) {
env::init(BUILD_SCRIPT_SOURCE, BUILD_SCRIPT_FOLDER);
env::set_log_level(env::LogLevel::Trace);

// base::Toolchain msvc("msvc", "cl", "cl", "cl", "lib", "link");
Toolchain_msvc msvc;

ExecutableTarget_msvc target_msvc("Simple.exe", msvc, "");
Expand Down
1 change: 0 additions & 1 deletion example/msvc/StaticLib/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ int main(void) {
env::init(BUILD_SCRIPT_SOURCE, BUILD_SCRIPT_FOLDER);
env::set_log_level(env::LogLevel::Trace);

// base::Toolchain msvc("msvc", "cl", "cl", "cl", "lib", "link");
Toolchain_msvc msvc;

StaticTarget_msvc statictarget_msvc("librandom.lib", msvc, "");
Expand Down