@@ -452,15 +452,16 @@ static auto generate_dylib_imports( //
452
452
struct compile_options {
453
453
fs::path work_dir;
454
454
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;
464
465
};
465
466
466
467
struct tracy_compile_options {
@@ -519,6 +520,14 @@ auto clang_gcc_compile(compile_options options) -> int {
519
520
520
521
compile_proc_args.push_back (" -DECSACT_BUILD" );
521
522
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
+
522
531
for (auto def : generated_defines) {
523
532
compile_proc_args.push_back (std::format (" -D{}" , def));
524
533
}
@@ -756,6 +765,15 @@ auto cl_compile(compile_options options) -> int {
756
765
cl_args.push_back (" /D_WIN32_WINNT=0x0A00" );
757
766
cl_args.push_back (" /diagnostics:column" );
758
767
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
+
759
777
if (options.tracy_dir ) {
760
778
cl_args.push_back (" /DTRACY_ENABLE" );
761
779
cl_args.push_back (" /DTRACY_DELAYED_INIT" );
@@ -836,8 +854,8 @@ auto cl_compile(compile_options options) -> int {
836
854
src_compile_exit_code_futures.reserve (valid_srcs.size ());
837
855
838
856
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] {
841
859
auto src_cl_args = cl_args;
842
860
src_cl_args.push_back (" /c" );
843
861
src_cl_args.push_back (std::format (" @{}" , main_params_file.string ()));
@@ -850,17 +868,20 @@ auto cl_compile(compile_options options) -> int {
850
868
src_cl_args.push_back (" /std:c++20" );
851
869
}
852
870
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
+ );
857
877
858
878
return ecsact::cli::detail::spawn_and_report (
859
879
options.compiler .compiler_path ,
860
880
src_cl_args,
861
881
reporter
862
882
);
863
- }));
883
+ })
884
+ );
864
885
}
865
886
866
887
auto any_src_compile_failures = false ;
@@ -890,9 +911,9 @@ auto cl_compile(compile_options options) -> int {
890
911
cl_args.push_back (obj_f.string ());
891
912
}
892
913
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
+ );
896
917
897
918
cl_args.push_back (" /Fo:" ); // typos:disable-line
898
919
cl_args.push_back (
@@ -1078,6 +1099,7 @@ auto ecsact::cli::cook_recipe( //
1078
1099
.compiler = compiler,
1079
1100
.inc_dirs = inc_dirs,
1080
1101
.system_libs = as_vec (recipe.system_libs ()),
1102
+ .defines = recipe.defines (),
1081
1103
.srcs = source_files,
1082
1104
.output_path = output_path,
1083
1105
.imports = as_vec (recipe.imports ()),
@@ -1091,6 +1113,7 @@ auto ecsact::cli::cook_recipe( //
1091
1113
.compiler = compiler,
1092
1114
.inc_dirs = inc_dirs,
1093
1115
.system_libs = as_vec (recipe.system_libs ()),
1116
+ .defines = recipe.defines (),
1094
1117
.srcs = source_files,
1095
1118
.output_path = output_path,
1096
1119
.imports = as_vec (recipe.imports ()),
0 commit comments