meson icon indicating copy to clipboard operation
meson copied to clipboard

Cannot specify c_args for subproject despite documentation saying you can

Open LunarLambda opened this issue 3 years ago • 3 comments

I have a project that contains some libraries as subprojects, cross-compiled for ARM.

Right now, every project has to duplicate the same set of default c_args, as there's no way for the main project to pass them to the subprojects. Specifying c_args in the subproject()'s default_options doesn't work, specifying -Dsubproject:c_args=... errors, and the project()'s default_options, add_project_arguments(...) and -Dc_args don't propagate either. (And on that note, specifying c_args in default_options in a subproject's project() call doesn't work either, but add_project_arguments does)

I'm avoiding use of add_global_arguments since the project itself (could) be used as a subproject, and I'm not wholly convinced that

if not meson.is_subproject()
   add_global_arguments(...)
endif

is a good idea.

I'm also not keen on putting these options into the cross files, because they're not actually necessary for successful cross-compilation, they're moreso considered 'good practice' (the flags in question are -mthumb -ffunction-sections -fdata-sections), plus with cross files it is hard to do 'composition' of options rather than overriding.

Not only is this unnecessary duplication, it also means that users have no way to provide their own flags, or override this 'recommendation'.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)? Cross
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) Arch Linux
  • what Python version are you using e.g. 3.8.0 3.10.8
  • what meson --version 0.63.3
  • what ninja --version if it's a Ninja build 1.11.1

LunarLambda avatar Nov 05 '22 10:11 LunarLambda

Per https://github.com/mesonbuild/meson/blob/master/docs/markdown/Release-notes-for-0.63.0.md#compiler-options-can-be-set-per-subproject it should be possible to override all compiler options (of which c_args is one)

I noticed that specfiying c_std and c_winlibs works, but c_args and c_link_args doesn't. Meson configure only lists those options either.

LunarLambda avatar Dec 02 '22 12:12 LunarLambda

@xclaesse Seems like commit 8867fb7999e35c6713c46af64becfd1a08146a6a accidentally excluded options defined as global, because those are tracked separately -- dunno why we don't just inherit those ones in all compilers.

eli-schwartz avatar Dec 02 '22 12:12 eli-schwartz

Right, that's a known (I guess only by me) limitation of the per-subproject compiler options, because from an implementation POV they are different. We definitely should fix this, but it requires more refactoring of how we access <lang>_args and <lang>_link_args options. At the time I wrote the patch it was non trivial.

xclaesse avatar Dec 06 '22 13:12 xclaesse