1

I have a project with a similar folder trees:

├── meson.build (1)
├── meson_options.txt
├── README.md
└── src
    └── mysub
        ├── meson.build (2)
        └── mesonTest.c

the meson.options.txt contains

option('avx_opt', type : 'combo', choices : ['avx2', 'avx512'], value : 'avx512')

the mysub project is a dependency of the main proj so the meson.build (1) :

project(
  'my_proj',
  'c',
  version : '1.1.0',
  default_options : ['buildtype=plain','warning_level=3'],
  subproject_dir : 'src'
)

project_source_files = [
  ''
]


message('## source root : ' +   meson.project_source_root() + ' ##')

project_dependencies = [
  dependency('mysub', fallback : ['mysub', 'mysub_dep']),
]

build_args = [
]


# ===================================================================

# ======
# Target
# ======

build_args += [
  '-DPROJECT_NAME=' + meson.project_name(),
  '-DPROJECT_VERSION=' + meson.project_version(),
]

the meson.build (2) of the mysub proj is:

project(
  'mysub',
  'c',
  version : '1.1.0',
  default_options : ['warning_level=3']
)

project_description = 'mysub binary'


project_source_files = [
  'mesonTest.c'
]


project_headers = [

]

avx_type = get_option('avx_opt')

if (avx_type == 'avx512')
   build_args_avx512 = [
     '-mavx512f',
     '-mavx512cd',
     '-mavx512vl',
     '-mavx512bw',
     '-mavx512dq',
     '-DNEWLDPC=1'
  ]
else
   build_args_avx512 = [
     '-DNEWLDPC=0'
  ]
endif

project_target = executable(
  meson.project_name(),
  project_source_files,
  install : true,
  c_args : build_args,
  link_args : '-Wl,--allow-shlib-undefined',
)


# =======
# Project
# =======

# Make this library usable as a Meson subproject.
project_dep = declare_dependency(
  include_directories: public_headers,
  link_with : project_target
)
set_variable(meson.project_name() + '_dep', project_dep)

# Make this library usable from the system's
# package manager.
install_headers(project_headers, subdir : meson.project_name())

pkg_mod = import('pkgconfig')
pkg_mod.generate(
  name : meson.project_name(),
  filebase : meson.project_name(),
  description : project_description,
  subdirs : meson.project_name(),
 # libraries : project_target,
)

I have tried to configure in the following way:

meson builddir -Davx_opt=avx512
or 
meson builddir -Davx_opt:mysub=avx512

but in both case I got:

The Meson build system
Version: 0.59.1
Source dir: /home/roccasal/wsEclipse/Intel/mesonTest/proj
Build dir: /home/roccasal/wsEclipse/Intel/mesonTest/proj/builddir
Build type: native build
Project name: my_proj
Project version: 1.1.0
C compiler for the host machine: cc (gcc 8.5.0 "cc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)")
C linker for the host machine: cc ld.bfd 2.30-108
Host machine cpu family: x86_64
Host machine cpu: x86_64
Message: ## source root : /home/roccasal/wsEclipse/Intel/mesonTest/proj ##
Found pkg-config: /usr/bin/pkg-config (1.4.2)
Found CMake: /usr/bin/cmake (3.20.2)
Run-time dependency mysub found: NO (tried pkgconfig and cmake)
Looking for a fallback subproject for the dependency mysub

Executing subproject mysub 

mysub| Project name: mysub
mysub| Project version: 1.1.0
mysub| C compiler for the host machine: cc (gcc 8.5.0 "cc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)")
mysub| C linker for the host machine: cc ld.bfd 2.30-108

src/mysub/meson.build:32:0: ERROR: Tried to access unknown option "avx_opt".

what is wrong in the meson build configuration?

the meson ver used is 0.59.1

//thanks

Mariano
  • 240
  • 3
  • 15

1 Answers1

1

Check Build-options page in reference manual:

To change values in subprojects prepend the name of the subproject and a colon:

$ meson configure -Dsubproject:option=newvalue

Thus, try create new build dir with:

meson builddir -Dmysub:avx_opt=avx512

or configure existing with:

meson configure builddir -Dmysub:avx_opt=avx512 

To make it working you also need this option defined in meson_options.txt in every subproject that uses it, but to simplify configuration you can as @dcbaker suggested use yielding, i.e. update option definition for the main project:

option('avx_opt', ...., yield : true)

This will give you possibility to configure it the same way for main and subprojects with just:

meson configure builddir -Davx_opt=avx512

Also, (I guess it's just typo in question) file with options should have name meson_options.txt (with underscore).

pmod
  • 10,450
  • 1
  • 37
  • 50
  • Hi @pmod with your suggestion I got: ' .............................:meson builddir -Dmysub:avx_opt=avx512 The Meson build system ................ Executing subproject mysub mysub| WARNING: In subproject mysub: Unknown options: "mysub:avx_opt" mysub| The value of new options can be set with: mysub| meson setup --reconfigure -Dnew_option=new_value ... mysub| Project name: mysub src/mysub/meson.build:32:0: ERROR: Tried to access unknown option "avx_opt". A full log can be found at /home/mariano/wsEclipse/Intel/mesonTest/proj/builddir/meson-logs/meson-log.txt' – Mariano Nov 19 '21 at 11:12
  • @Mariano ok, if this option is needed only for subproject (as far as I see, it's so), then meson.options.txt with that option should be in subproject dir, alongside with meson.build (2) – pmod Nov 19 '21 at 11:55
  • Hi @pmod, In reality my project is more complex, I heve more subproj: "... proj mysub mysub1 mysub2 ..." .... end i would pass the option to all of them from the "main" mason.build, so in this case which is the correct way to do it? – Mariano Nov 19 '21 at 12:40
  • @Mariano hmmm, and all subprojects use the same option, i.e. have meson.build files with get_option('avx_opt') with if/else block? – pmod Nov 19 '21 at 13:51
  • some of them yes use the get_option('avx_opt') with if/else block, maybe could I use someting like the env variable instead the meson option? Othervise all the subproj with this option should have thee meson.options.txt file, but this is so nice as final solution. – Mariano Nov 19 '21 at 15:21
  • You have a stuation where there is an option named "opt" in multiple subprojects? You might want to use what meson calls a "yielding" option, which allows subprojects to inhert an option value from the super project. https://mesonbuild.com/Build-options.html#yielding-to-superproject-option – dcbaker Nov 19 '21 at 19:04
  • @Mariano yes, you'll need to have this option in meson_options.txt in all subprojects where you use it, it's good advice in this case from dcbaker regarding yield, I will post update – pmod Nov 20 '21 at 00:19
  • @dcbaker yes, it simpifies configuration but option must be copied around all meson_options.txt files ans processed the same way in all meson.build files which is not good design – pmod Nov 20 '21 at 00:20
  • Yeah, it's a really hard design problem when strict subproject isolation is a requirement, like it is in Meson. Suggestions for better solutions are welcome – dcbaker Nov 20 '21 at 03:08
  • @dcbaker Hi I have modified the option: # Please keep these options sorted alphabetically. option('avx_opt', type : 'combo', choices : ['avx2', 'avx512'], value : 'avx512', yield : true)' and configured: meson setup builddir -Davx_opt=avx512 but I have still the same problem: mysub| Project name: mysub mysub| Project version: 1.1.0 mysub| C compiler for the host machine: cc (gcc 8.5.0 "cc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)") mysub| C linker for the host machine: cc ld.bfd 2.30-108 src/mysub/meson.build:32:0: ERROR: Tried to access unknown option "avx_opt". – Mariano Nov 22 '21 at 07:57
  • Hi @dcbaker I have understood yours suggestion, so in addition to yield option i need replicate the meson_options.txt in all subproj that need it, it this case with I hame able to configure the subprojects correctly, ok for the moment this is an acceptable work around even if it is not so nice from the design point of view, maybe in next meson release should be allowed to propagate "global " optionn to the suprojects. I understood that subproj isolation is better but sometimes you need overcome it. – Mariano Nov 22 '21 at 08:27