From 5ba36c7be0a12b9b052fb172a209d3b6dffc9a99 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 9 Dec 2024 08:32:57 +0100 Subject: Add support for toolchain specific sources --- src/ctor.h | 25 +++++++++++++++++-------- src/tasks.cc | 14 ++++++++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/ctor.h b/src/ctor.h index 8204f70..1de4aec 100644 --- a/src/ctor.h +++ b/src/ctor.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace ctor { @@ -52,6 +53,14 @@ enum class arch unknown, //!< Target platform architecture has not yet detected or was not possible to detect }; +enum class toolchain +{ + any, + none, + gcc, + clang, +}; + struct source { constexpr source(const char* file) : file(file) {} // convenience ctor @@ -62,19 +71,19 @@ struct source constexpr source(std::string_view file, std::string_view output) : file(file), output(output) {} constexpr source(std::string_view file, ctor::language lang, std::string_view output) : file(file), language(lang), output(output) {} + constexpr source(ctor::toolchain toolchain, std::string_view file) : file(file), toolchain(toolchain) {} + constexpr source(ctor::toolchain toolchain, std::string_view file, ctor::language lang) : file(file), toolchain(toolchain), language(lang) {} + + constexpr source(ctor::toolchain toolchain, std::string_view file, std::string_view output) : file(file), toolchain(toolchain), output(output) {} + + constexpr source(ctor::toolchain toolchain, std::string_view file, ctor::language lang, std::string_view output) : file(file), toolchain(toolchain), language(lang), output(output) {} + std::string file; + ctor::toolchain toolchain{ctor::toolchain::any}; ctor::language language{ctor::language::automatic}; std::string output{}; }; -enum class toolchain -{ - any, - none, - gcc, - clang, -}; - enum class cxx_opt { // gcc/clang diff --git a/src/tasks.cc b/src/tasks.cc index a4c455b..0e59097 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -92,14 +92,20 @@ std::vector> taskFactory(const ctor::build_configuration& } } + const auto& c = ctor::get_configuration(); std::vector objects; if(target_type != ctor::target_type::function) { - for(const auto& file : config.sources) + for(const auto& source : config.sources) { - auto task = std::make_shared(config, settings, sourceDir, file); - tasks.push_back(task); - objects.push_back(task->targetFile().string()); + if(source.toolchain == ctor::toolchain::any || + (config.system == ctor::output_system::build && source.toolchain == c.build_toolchain) || + (config.system == ctor::output_system::host && source.toolchain == c.host_toolchain)) + { + auto task = std::make_shared(config, settings, sourceDir, source); + tasks.push_back(task); + objects.push_back(task->targetFile().string()); + } } } #ifndef BOOTSTRAP -- cgit v1.2.3