From 668158a83bc9e5af7bf65fe88d22d1958e33443f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 6 Feb 2026 18:25:41 +0100 Subject: New syntax --- src/ctor.h | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 199 insertions(+), 3 deletions(-) (limited to 'src/ctor.h') diff --git a/src/ctor.h b/src/ctor.h index 29c8f6d..890c257 100644 --- a/src/ctor.h +++ b/src/ctor.h @@ -269,6 +269,41 @@ using asm_flags = std::vector; struct flags { + template + requires (( + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v + ) && ...) + constexpr flags(Args && ... arg) + { + ([&] + { + if constexpr(std::is_same_v) + { + cflags = arg; + } + else if constexpr(std::is_same_v) + { + cxxflags = arg; + } + else if constexpr(std::is_same_v) + { + ldflags = arg; + } + else if constexpr(std::is_same_v) + { + arflags = arg; + } + else if constexpr(std::is_same_v) + { + asmflags = arg; + } + }(), ...); + } + ctor::c_flags cflags; // flags for c compiler ctor::cxx_flags cxxflags; // flags for c++ compiler ctor::ld_flags ldflags; // flags for linker @@ -297,8 +332,110 @@ using GeneratorManyToOne = const ctor::build_configuration& config, const ctor::settings& settings)>; +struct name +{ + std::string name; +}; + +struct target +{ + std::string target; +}; + +using sources = std::vector; + +struct depends +{ + std::vector depends; +}; + +struct externals +{ + std::vector externals; +}; + struct build_configuration { + template + requires (( + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_convertible_v || + std::is_convertible_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v + ) && ...) + constexpr build_configuration(Args && ... arg) + { + ([&] + { + if constexpr(std::is_same_v) + { + name = arg.name; + } + else if constexpr(std::is_same_v) + { + type = arg; + } + else if constexpr(std::is_same_v) + { + system = arg; + } + else if constexpr(std::is_same_v) + { + target = arg.target; + } + else if constexpr(std::is_same_v) + { + sources = arg; + } + else if constexpr(std::is_same_v) + { + depends = arg.depends; + } + else if constexpr(std::is_same_v) + { + externals = arg.externals; + } + else if constexpr(std::is_convertible_v) + { + function_one_to_one = arg; + } + else if constexpr(std::is_convertible_v) + { + function_many_to_one = arg; + } + else if constexpr(std::is_same_v) + { + flags.cflags = arg; + } + else if constexpr(std::is_same_v) + { + flags.cxxflags = arg; + } + else if constexpr(std::is_same_v) + { + flags.ldflags = arg; + } + else if constexpr(std::is_same_v) + { + flags.arflags = arg; + } + else if constexpr(std::is_same_v) + { + flags.asmflags = arg; + } + }(), ...); + } + std::string name; // Name - used for referring in other configurations. ctor::target_type type{ctor::target_type::automatic}; ctor::output_system system{ctor::output_system::build}; @@ -307,9 +444,8 @@ struct build_configuration std::vector depends; // internal target dependencies ctor::flags flags; std::vector externals; // externals used by this configuration - std::variant function; + ctor::GeneratorOneToOne function_one_to_one; + ctor::GeneratorManyToOne function_many_to_one; }; using build_configurations = std::vector; @@ -320,12 +456,72 @@ int reg(std::function cb, // This type will use flags verbatim struct external_manual { + template + requires (( + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v + ) && ...) + constexpr external_manual(Args && ... arg) + { + ([&] + { + if constexpr(std::is_same_v) + { + flags.cflags = arg; + } + else if constexpr(std::is_same_v) + { + flags.cxxflags = arg; + } + else if constexpr(std::is_same_v) + { + flags.ldflags = arg; + } + else if constexpr(std::is_same_v) + { + flags.arflags = arg; + } + else if constexpr(std::is_same_v) + { + flags.asmflags = arg; + } + }(), ...); + } + ctor::flags flags; }; struct external_configuration { + template + requires (( + std::is_same_v || + std::is_same_v || + std::is_same_v + ) && ...) + constexpr external_configuration(Args && ... arg) + { + ([&] + { + if constexpr(std::is_same_v) + { + name = arg.name; + } + else if constexpr(std::is_same_v) + { + system = arg; + } + else if constexpr(std::is_same_v) + { + external = arg; + } + }(), ...); + } + std::string name; // Name for configuration ctor::output_system system{ctor::output_system::build}; std::variant external; -- cgit v1.2.3