Per subdirectory and/or file compiler args in meson for c

106 Views Asked by At

CONTEXT
I have an embedded project that includes different target platforms (eg. ARM using Arm GNU Toolchain, Microchip using MPLAB XC32, Windows using MSVC). Each has it's own "port" subdirectory containing the platform-dependant code. Additionally I have different third-party source files (eg. SDK with auto-generated code, CANOpen stack with auto-generated code, ...).

PROBLEM
I need to compile specific subdirectories with different compiler args for example:

  • warnings
    unreadable output due to third-party sources and unable to use werror
  • optimization levels
    optimize already tested or not interested modules on debugging/inspection, due to size constraints (currently done using gcc attributes)
  • defines
    enabling detailed logging or other debugging options for the inspecting module

APPROACHES

  • The solution to think of was to generate the object files in the subdirectories and link everything together in the root build_target. I would probably be able to get this done by manually compiling the subdirectories using run_command, custom_target or compiler.run but that seems to be a lot of work and I would probably need to add all the different options and args manually.
  • I also tried using declare_dependency but the compiler_args are basically just inherited by the build_target.
  • My third idea is using static_library with b_lundef=true (or /FORCE:UNRESOLVED respectively), but I am not entirely sure how to set that up to not break debugging or memory sections (eg. initcalls, parameterizable constants, ...).
0

There are 0 best solutions below