For example, I can add definitions for C/C++ preprocessor with CMake
add_definitions(-DFOO -DBAR ...)
and then I can use them for conditional compilation
#ifdef FOO
code ...
#endif
#ifdef BAR
code ...
#endif
Is there a way to do the same thing with Zig and its build system using compilation arguments or something like that?
You can do something similar using the build system. This requires some boilerplate code to do the option handling. Following the tutorial on https://zig.news/xq/zig-build-explained-part-1-59lf for the build system and https://ziggit.dev/t/custom-build-options/138/8 for the option handling:
build.zigthat contains a functionbuild():hello.zigusing@import("build_options"):zig-out/bin/hellogives the following output: