Skip to content

Commit

Permalink
meson: use features to enable options
Browse files Browse the repository at this point in the history
This allows sysdeps to declare X option is not supported, which means we
can provide an error to the user if they enable an option on a system
that doesn't support it.

Co-authored-by: Kacper Słomiński <[email protected]>
  • Loading branch information
64 and qookei committed Oct 17, 2024
1 parent 657b4e7 commit 33ed557
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 17 deletions.
21 changes: 9 additions & 12 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ no_headers = get_option('no_headers')
library_type = get_option('default_library')
build_tests = get_option('build_tests')
build_tests_host_libc = get_option('build_tests_host_libc')
posix_option = get_option('posix_option')
linux_option = get_option('linux_option')
glibc_option = get_option('glibc_option')
bsd_option = get_option('bsd_option')
libgcc_dependency = get_option('libgcc_dependency')
internal_conf = configuration_data()
mlibc_conf = configuration_data()
Expand Down Expand Up @@ -232,7 +228,6 @@ elif host_machine.system() == 'managarm'
internal_conf.set10('MLIBC_MAP_FILE_WINDOWS', true)
subdir('sysdeps/managarm')
elif host_machine.system() == 'ironclad'
linux_option = false
rtld_include_dirs += include_directories('sysdeps/ironclad/include')
libc_include_dirs += include_directories('sysdeps/ironclad/include')
subdir('sysdeps/ironclad')
Expand All @@ -243,12 +238,10 @@ elif host_machine.system() == 'keyronex'
internal_conf.set10('MLIBC_MAP_FILE_WINDOWS', true)
subdir('sysdeps/keyronex')
elif host_machine.system() == 'vinix'
linux_option = false
rtld_include_dirs += include_directories('sysdeps/vinix/include')
libc_include_dirs += include_directories('sysdeps/vinix/include')
subdir('sysdeps/vinix')
elif host_machine.system() == 'lyre'
linux_option = false
rtld_include_dirs += include_directories('sysdeps/lyre/include')
libc_include_dirs += include_directories('sysdeps/lyre/include')
subdir('sysdeps/lyre')
Expand All @@ -257,7 +250,6 @@ elif host_machine.system() == 'lemon'
libc_include_dirs += include_directories('sysdeps/lemon/include')
subdir('sysdeps/lemon')
elif host_machine.system() == 'dripos'
linux_option = false
rtld_include_dirs += include_directories('sysdeps/dripos/include')
libc_include_dirs += include_directories('sysdeps/dripos/include')
subdir('sysdeps/dripos')
Expand All @@ -275,6 +267,11 @@ endif
# Configuration based on enabled options.
#----------------------------------------------------------------------------------------

posix_option = get_option('posix_option').require(sysdep_supported_options.get('posix')).allowed()
linux_option = get_option('linux_option').require(sysdep_supported_options.get('linux')).allowed()
glibc_option = get_option('glibc_option').require(sysdep_supported_options.get('glibc')).allowed()
bsd_option = get_option('bsd_option').require(sysdep_supported_options.get('bsd')).allowed()

mlibc_conf.set10('__MLIBC_POSIX_OPTION', posix_option)
mlibc_conf.set10('__MLIBC_LINUX_OPTION', linux_option)
mlibc_conf.set10('__MLIBC_GLIBC_OPTION', glibc_option)
Expand Down Expand Up @@ -527,10 +524,10 @@ summary(summary_info, bool_yn: true, section: 'tests')

summary_info = {}
summary_info += {'headers-only': headers_only}
summary_info += {'POSIX option': posix_option}
summary_info += {'Linux option': linux_option}
summary_info += {'glibc option': glibc_option}
summary_info += {'BSD option': bsd_option}
summary_info += {'POSIX option': get_option('posix_option')}
summary_info += {'Linux option': get_option('linux_option')}
summary_info += {'glibc option': get_option('glibc_option')}
summary_info += {'BSD option': get_option('bsd_option')}
summary_info += {'debug allocator': get_option('debug_allocator')}
summary_info += {'libgcc dependency': libgcc_dependency}
summary(summary_info, bool_yn: true, section: 'mlibc options')
Expand Down
8 changes: 4 additions & 4 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ option('headers_only', type : 'boolean', value : false)
option('no_headers', type : 'boolean', value : false)
option('build_tests', type: 'boolean', value : false)
option('build_tests_host_libc', type: 'boolean', value : true)
option('posix_option', type: 'boolean', value : true)
option('linux_option', type: 'boolean', value : true)
option('glibc_option', type: 'boolean', value : true)
option('bsd_option', type: 'boolean', value : true)
option('posix_option', type: 'feature', value : 'auto')
option('linux_option', type: 'feature', value : 'auto')
option('glibc_option', type: 'feature', value : 'auto')
option('bsd_option', type: 'feature', value : 'auto')
option('libgcc_dependency', type : 'boolean', value : true)
option('linux_kernel_headers', type: 'string', value : '')
option('default_library_paths', type: 'array', value: [])
Expand Down
7 changes: 7 additions & 0 deletions sysdeps/aero/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
sysdep_supported_options = {
'posix': true,
'linux': true,
'glibc': true,
'bsd': true,
}

rtld_dso_sources += files(
'generic/aero.cpp',
'generic/filesystem.cpp',
Expand Down
6 changes: 6 additions & 0 deletions sysdeps/astral/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
sysdep_supported_options = {
'posix': true,
'linux': true,
'glibc': true,
'bsd': true,
}

rtld_sources += files(
'generic/generic.cpp',
Expand Down
6 changes: 6 additions & 0 deletions sysdeps/dripos/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
sysdep_supported_options = {
'posix': true,
'linux': false,
'glibc': true,
'bsd': true,
}

rtld_sources += files(
'generic/generic.cpp'
Expand Down
6 changes: 6 additions & 0 deletions sysdeps/ironclad/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
sysdep_supported_options = {
'posix': true,
'linux': false,
'glibc': true,
'bsd': true,
}

rtld_sources += files(
'generic/generic.cpp'
Expand Down
7 changes: 7 additions & 0 deletions sysdeps/keyronex/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
sysdep_supported_options = {
'posix': true,
'linux': true,
'glibc': true,
'bsd': true,
}


rtld_sources += files(
'generic/generic.cpp'
Expand Down
6 changes: 6 additions & 0 deletions sysdeps/lemon/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
sysdep_supported_options = {
'posix': true,
'linux': true,
'glibc': true,
'bsd': true,
}

rtld_sources += files(
'generic/filesystem.cpp',
Expand Down
9 changes: 8 additions & 1 deletion sysdeps/linux/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
sysdep_supported_options = {
'posix': true,
'linux': true,
'glibc': true,
'bsd': true,
}

rtld_dso_sources += files(
host_machine.cpu_family() / 'arch-syscall.cpp',
'generic/sysdeps.cpp',
Expand All @@ -17,7 +24,7 @@ libc_sources += files(
'generic/sysdeps.cpp',
)

if posix_option
if get_option('posix_option').allowed()
libc_sources += files(
'generic/thread.cpp',
host_machine.cpu_family() / 'cp_syscall.S',
Expand Down
6 changes: 6 additions & 0 deletions sysdeps/lyre/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
sysdep_supported_options = {
'posix': true,
'linux': false,
'glibc': true,
'bsd': true,
}

rtld_sources += files(
'generic/generic.cpp'
Expand Down
7 changes: 7 additions & 0 deletions sysdeps/managarm/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
sysdep_supported_options = {
'posix': true,
'linux': true,
'glibc': true,
'bsd': true,
}

managarm = subproject('managarm', default_options: [ 'provide_deps=true' ])
hel_dep = managarm.get_variable('hel_dep')
proto_posix_dep = managarm.get_variable('posix_extra_dep')
Expand Down
6 changes: 6 additions & 0 deletions sysdeps/vinix/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
sysdep_supported_options = {
'posix': true,
'linux': false,
'glibc': true,
'bsd': true,
}

rtld_sources += files(
'generic/generic.cpp'
Expand Down

0 comments on commit 33ed557

Please sign in to comment.