@@ -452,15 +452,16 @@ static auto generate_dylib_imports( //
452452struct compile_options {
453453 fs::path work_dir;
454454
455- ecsact::cli::cc_compiler compiler;
456- std::vector<fs::path> inc_dirs;
457- std::vector<std::string> system_libs;
458- std::vector<fs::path> srcs;
459- fs::path output_path;
460- std::vector<std::string> imports;
461- std::vector<std::string> exports;
462- std::optional<fs::path> tracy_dir;
463- bool debug;
455+ ecsact::cli::cc_compiler compiler;
456+ std::vector<fs::path> inc_dirs;
457+ std::vector<std::string> system_libs;
458+ std::unordered_map<std::string, std::string> defines;
459+ std::vector<fs::path> srcs;
460+ fs::path output_path;
461+ std::vector<std::string> imports;
462+ std::vector<std::string> exports;
463+ std::optional<fs::path> tracy_dir;
464+ bool debug;
464465};
465466
466467struct tracy_compile_options {
@@ -519,6 +520,14 @@ auto clang_gcc_compile(compile_options options) -> int {
519520
520521 compile_proc_args.push_back (" -DECSACT_BUILD" );
521522
523+ for (auto && [name, value] : options.defines ) {
524+ if (value.empty ()) {
525+ compile_proc_args.push_back (std::format (" -D{}" , name));
526+ } else {
527+ compile_proc_args.push_back (std::format (" -D{}={}" , name, value));
528+ }
529+ }
530+
522531 for (auto def : generated_defines) {
523532 compile_proc_args.push_back (std::format (" -D{}" , def));
524533 }
@@ -756,6 +765,15 @@ auto cl_compile(compile_options options) -> int {
756765 cl_args.push_back (" /D_WIN32_WINNT=0x0A00" );
757766 cl_args.push_back (" /diagnostics:column" );
758767 cl_args.push_back (" /DECSACT_BUILD" );
768+
769+ for (auto && [name, value] : options.defines ) {
770+ if (value.empty ()) {
771+ cl_args.push_back (std::format (" /D{}" , name));
772+ } else {
773+ cl_args.push_back (std::format (" /D{}={}" , name, value));
774+ }
775+ }
776+
759777 if (options.tracy_dir ) {
760778 cl_args.push_back (" /DTRACY_ENABLE" );
761779 cl_args.push_back (" /DTRACY_DELAYED_INIT" );
@@ -836,8 +854,8 @@ auto cl_compile(compile_options options) -> int {
836854 src_compile_exit_code_futures.reserve (valid_srcs.size ());
837855
838856 for (auto src : valid_srcs) {
839- src_compile_exit_code_futures
840- . emplace_back ( std::async (std::launch::async, [&, src] {
857+ src_compile_exit_code_futures. emplace_back (
858+ std::async (std::launch::async, [&, src] {
841859 auto src_cl_args = cl_args;
842860 src_cl_args.push_back (" /c" );
843861 src_cl_args.push_back (std::format (" @{}" , main_params_file.string ()));
@@ -850,17 +868,20 @@ auto cl_compile(compile_options options) -> int {
850868 src_cl_args.push_back (" /std:c++20" );
851869 }
852870
853- src_cl_args.push_back (std::format (
854- " /Fo{}\\ " , // typos:disable-line
855- long_path_workaround (intermediate_dir).string ()
856- ));
871+ src_cl_args.push_back (
872+ std::format (
873+ " /Fo{}\\ " , // typos:disable-line
874+ long_path_workaround (intermediate_dir).string ()
875+ )
876+ );
857877
858878 return ecsact::cli::detail::spawn_and_report (
859879 options.compiler .compiler_path ,
860880 src_cl_args,
861881 reporter
862882 );
863- }));
883+ })
884+ );
864885 }
865886
866887 auto any_src_compile_failures = false ;
@@ -890,9 +911,9 @@ auto cl_compile(compile_options options) -> int {
890911 cl_args.push_back (obj_f.string ());
891912 }
892913
893- auto obj_params_file =
894- create_params_file ( long_path_workaround (options.work_dir / " object.params" )
895- );
914+ auto obj_params_file = create_params_file (
915+ long_path_workaround (options.work_dir / " object.params" )
916+ );
896917
897918 cl_args.push_back (" /Fo:" ); // typos:disable-line
898919 cl_args.push_back (
@@ -1078,6 +1099,7 @@ auto ecsact::cli::cook_recipe( //
10781099 .compiler = compiler,
10791100 .inc_dirs = inc_dirs,
10801101 .system_libs = as_vec (recipe.system_libs ()),
1102+ .defines = recipe.defines (),
10811103 .srcs = source_files,
10821104 .output_path = output_path,
10831105 .imports = as_vec (recipe.imports ()),
@@ -1091,6 +1113,7 @@ auto ecsact::cli::cook_recipe( //
10911113 .compiler = compiler,
10921114 .inc_dirs = inc_dirs,
10931115 .system_libs = as_vec (recipe.system_libs ()),
1116+ .defines = recipe.defines (),
10941117 .srcs = source_files,
10951118 .output_path = output_path,
10961119 .imports = as_vec (recipe.imports ()),
0 commit comments