Skip to content

Instantly share code, notes, and snippets.

@vtorri
Last active January 11, 2025 11:16
Show Gist options
  • Save vtorri/99384d4564f2a1494f529855ea0686eb to your computer and use it in GitHub Desktop.
Save vtorri/99384d4564f2a1494f529855ea0686eb to your computer and use it in GitHub Desktop.
get preprocessor macros from add_project_arguments()
static bool
vs_preproc_nodup(struct workspace *wk, obj preproc, obj str)
{
obj v;
obj_array_for(wk, preproc, v) {
if (str_eql(get_str(wk, v), get_str(wk, str))) {
return false;
}
}
return true;
}
static void
vs_get_preprocessor(struct workspace *wk, struct vs_ctx *ctx)
{
make_obj(wk, &ctx->preprocessor, obj_array);
for (uint32_t i = 0; i < wk->projects.len; ++i) {
obj tgt_id;
ctx->project = arr_get(&wk->projects, i);
obj_array_for(wk, ctx->project->targets, tgt_id) {
if (get_obj_type(wk, tgt_id) == obj_build_target) {
struct obj_build_target *tgt = get_obj_build_target(wk, tgt_id);
obj _lang, _count;
(void)_count;
obj_dict_for(wk, tgt->required_compilers, _lang, _count) {
enum compiler_language lang = _lang;
obj arg_id;
if (obj_dict_geti(wk, current_project(wk)->args[tgt->machine], lang, &arg_id)) {
obj v;
obj_array_for(wk, arg_id, v) {
const struct str *s = get_str(wk, v);
if (str_startswith(s, &WKSTR("-D")) && s->len > 2) {
obj str = make_str(wk, s->s + 2);
if (vs_preproc_nodup(wk, ctx->preprocessor, str)) {
obj_array_push(wk, ctx->preprocessor, str);
}
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment