Skip to content

Commit

Permalink
build: introduce meson subprojects option
Browse files Browse the repository at this point in the history
On Gentoo Linux, downloading external dependencies via subprojects
concept is forbidden (meson setup --wrap-mode nodownload).

Then, when trying to package TRX, meson is failing with the following
error on libtrx configuration while it tries to download/unpack the
uthash library :
> Executing subproject libtrx
>
> libtrx| Project name: libtrx
> libtrx| Project version: undefined
> libtrx| C compiler for the host machine: x86_64-pc-linux-gnu-gcc (gcc 13.3.1 "x86_64-pc-linux-gnu-gcc (Gentoo 13.3.1_p20241025 p1) 13.3.1 20241024")
> libtrx| C linker for the host machine: x86_64-pc-linux-gnu-gcc ld.bfd 2.42
> libtrx| Using subprojects/libtrx/subprojects/uthash.wrap
>
> src/tr1/subprojects/libtrx/meson.build:35:9: ERROR: Automatic wrap-based subproject downloading is disabled

On Gentoo, the uthash library is distributed by the package manager and
installed in /usr/include.

This commit introduces a new boolean meson option (subprojects),
defaulting to true.

With subprojects == true, meson is using the bundled uthash subproject
library as usual.

With subprojects == false, meson is trying to find the uthash.h header
on the system (in /usr/include). It also checks for the right library
version (currently 2.3.0).

Partial meson output with -Dsubprojects=false when the header was found :
> Executing subproject libtrx
>
> libtrx| Project name: libtrx
> libtrx| Project version: undefined
> libtrx| C compiler for the host machine: ccache cc (gcc 13.3.1 "cc
> (Gentoo 13.3.1_p20241025 p1) 13.3.1 20241024")
> libtrx| C linker for the host machine: cc ld.bfd 2.42
> libtrx| Fetching value of define "UTHASH_VERSION" : 2.3.0
> libtrx| Message: Found uthash library header version: 2.3.0

Same output with -Dsubprojects=false while the header was not found :
> Executing subproject libtrx
>
> libtrx| Project name: libtrx
> libtrx| Project version: undefined
> libtrx| C compiler for the host machine: ccache cc (gcc 13.3.1 "cc
> (Gentoo 13.3.1_p20241025 p1) 13.3.1 20241024")
> libtrx| C linker for the host machine: cc ld.bfd 2.42
> [...]/TRX/src/tr1/subprojects/libtrx/meson.build:46:30: ERROR: Could not get define 'UTHASH_VERSION'

Same output with -Dsubprojects=false while the header version mismatches :
> Executing subproject libtrx
>
> libtrx| Project name: libtrx
> libtrx| Project version: undefined
> libtrx| C compiler for the host machine: ccache cc (gcc 13.3.1 "cc
> (Gentoo 13.3.1_p20241025 p1) 13.3.1 20241024")
> libtrx| C linker for the host machine: cc ld.bfd 2.42
> [..]TRX/src/tr1/subprojects/libtrx/meson.build:54:4: ERROR: Problem encountered: Found wrong uthash library header version: 2.2.0

Signed-off-by: Fabrice Delliaux <[email protected]>
  • Loading branch information
netfab committed Nov 12, 2024
1 parent 79dc750 commit 75abc96
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
26 changes: 23 additions & 3 deletions src/libtrx/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project(
],
)

subprojects = get_option('subprojects')
staticdeps = get_option('staticdeps')
tr_version = get_option('tr_version')

Expand All @@ -32,9 +33,28 @@ if host_machine.system() == 'darwin'
staticdeps = false
endif

uthash = subproject('uthash', default_options: ['warning_level=0'])

null_dep = dependency('', required: false)

dep_uthash = null_dep
if subprojects
# Use uthash bundled meson subproject
uthash = subproject('uthash', default_options: ['warning_level=0'])
dep_uthash = uthash.get_variable('uthash_dep')
else
# Searching for uthash library header provided by OS package manager
incdir = include_directories('/usr/include')
uthash_version = c_compiler.get_define('UTHASH_VERSION',
include_directories: incdir,
prefix: '#include "uthash.h"')

# make sure we found the right version
if uthash_version.version_compare('>=2.3.0')
message('Found uthash library header version: ' + uthash_version)
else
error('Found wrong uthash library header version: ' + uthash_version)
endif
endif

dep_avcodec = dependency('libavcodec', static: staticdeps)
dep_avformat = dependency('libavformat', static: staticdeps)
dep_avutil = dependency('libavutil', static: staticdeps)
Expand Down Expand Up @@ -151,7 +171,7 @@ dependencies = [
dep_swscale,
dep_zlib,
dep_opengl,
uthash.get_variable('uthash_dep'),
dep_uthash,
]

if dep_backtrace.found() and host_machine.system() == 'linux'
Expand Down
8 changes: 8 additions & 0 deletions src/libtrx/meson.options
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
option(
'subprojects',
type: 'boolean',
value: true,
description: 'Use bundled dependencies through meson subprojects. default: true.' +
'If false, try to find them on the OS.'
)

option(
'staticdeps',
type: 'boolean',
Expand Down
2 changes: 2 additions & 0 deletions src/tr1/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ project(
)

staticdeps = get_option('staticdeps')
subprojects = get_option('subprojects')

trx = subproject('libtrx', default_options: {
'tr_version': '1',
'staticdeps': staticdeps,
'subprojects': subprojects,
})
c_compiler = meson.get_compiler('c')

Expand Down
15 changes: 14 additions & 1 deletion src/tr1/meson.options
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
option('staticdeps', type: 'boolean', value: true, description: 'Try to build against static dependencies. default: true')
option(
'subprojects',
type: 'boolean',
value: true,
description: 'Use bundled dependencies through meson subprojects. default: true.' +
'If false, try to find them on the OS.'
)

option(
'staticdeps',
type: 'boolean',
value: true,
description: 'Try to build against static dependencies. default: true'
)
2 changes: 2 additions & 0 deletions src/tr2/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ project('TR2X', ['c'],
)

staticdeps = get_option('staticdeps')
subprojects = get_option('subprojects')

trx = subproject('libtrx', default_options: {
'tr_version': '2',
'staticdeps': staticdeps,
'subprojects': subprojects,
})
c_compiler = meson.get_compiler('c')

Expand Down
15 changes: 14 additions & 1 deletion src/tr2/meson.options
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
option('staticdeps', type: 'boolean', value: true, description: 'Try to build against static dependencies. default: true')
option(
'subprojects',
type: 'boolean',
value: true,
description: 'Use bundled dependencies through meson subprojects. default: true.' +
'If false, try to find them on the OS.'
)

option(
'staticdeps',
type: 'boolean',
value: true,
description: 'Try to build against static dependencies. default: true'
)

0 comments on commit 75abc96

Please sign in to comment.