From 381faf9bc11a87819f8904ebe3d3cdc7daba002a Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Tue, 9 Apr 2024 16:58:27 -0500 Subject: [PATCH 1/2] meson: Add build-lsfd option and make rt dependency optional A dependency on the rt library is unnecessarily required when checking for the clock_gettime and timer_create functions. This causes the build to fail if the rt library is not found. This should not fail the build as rt is only required for the checks. Additionally, the lsfd executable and some tests require rt. There is currently no option to toggle building lsfd. This PR makes it possible to build without the rt library. Function checks no longer require rt for the build. The function checks for the rt library only run when rt is available. This PR adds an option to allow building without lsfd. This makes it possible to build without the executable that requires rt. To not require rt for the test, a additional check has been added. The effected tests won't be built unless rt has been found. Signed-off-by: Jordan Williams (cherry picked from commit 06b27058a04c1ac9eba44f19e320ecd862f6d75f) --- meson.build | 32 +++++++++++++++++++++----------- meson_options.txt | 2 ++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/meson.build b/meson.build index 66a90b66fed..d2a1654762c 100644 --- a/meson.build +++ b/meson.build @@ -732,9 +732,12 @@ endif realtime_libs = [] have = cc.has_function('clock_gettime') if not have - realtime_libs += cc.find_library('rt', required : true) - have = cc.has_function('clock_gettime', - dependencies : realtime_libs) + lib_rt = cc.find_library('rt', required : false) + if lib_rt.found() + realtime_libs += lib_rt + have = cc.has_function('clock_gettime', + dependencies : realtime_libs) + endif endif conf.set('HAVE_CLOCK_GETTIME', have ? 1 : false) @@ -742,9 +745,12 @@ thread_libs = dependency('threads') have = cc.has_function('timer_create') if not have - realtime_libs = [cc.find_library('rt', required : true)] - have = cc.has_function('timer_create', - dependencies : realtime_libs) + lib_rt = cc.find_library('rt', required : false) + if lib_rt.found() + realtime_libs = [lib_rt] + have = cc.has_function('timer_create', + dependencies : realtime_libs) + endif if not have realtime_libs += thread_libs have = cc.has_function('timer_create', @@ -2708,16 +2714,20 @@ endif mq_libs = [] mq_libs += cc.find_library('rt', required : true) +lib_rt = cc.find_library('rt', required : get_option('build-lsfd')) + +opt = not get_option('build-lsfd').disabled() exe = executable( 'lsfd', lsfd_sources, include_directories : includes, link_with : [lib_common, lib_smartcols], - dependencies : mq_libs, + dependencies : [lib_rt], install_dir : usrbin_exec_dir, - install : true) -if not is_disabler(exe) + install : opt, + build_by_default : opt) +if opt and not is_disabler(exe) exes += exe manadocs += ['misc-utils/lsfd.1.adoc'] endif @@ -3493,14 +3503,14 @@ exe = executable( build_by_default: program_tests) exes += exe -if LINUX +if LINUX and lib_rt.found() exe = executable( 'test_mkfds', 'tests/helpers/test_mkfds.c', 'tests/helpers/test_mkfds.h', 'tests/helpers/test_mkfds_ppoll.c', include_directories : includes, - dependencies : mq_libs, + dependencies : [lib_rt], build_by_default: program_tests) exes += exe endif diff --git a/meson_options.txt b/meson_options.txt index 7acf9d4fcad..5cc8b4f6133 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -101,6 +101,8 @@ option('build-cal', type : 'feature', description : 'build cal') option('build-logger', type : 'feature', description : 'build logger') +option('build-lsfd', type : 'feature', + description : 'build lsfd') option('build-switch_root', type : 'feature', description : 'switch_root') option('build-pivot_root', type : 'feature', From 712e9271d199aacc0694c73b5c908203713bb16a Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Mon, 1 Apr 2024 12:18:52 -0500 Subject: [PATCH 2/2] meson: Only pick up the rt library once Require the rt library for the build-lsfd feature. Signed-off-by: Jordan Williams (cherry picked from commit 243950279f413e3844d13a2d87b3853c1242f437) --- meson.build | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index d2a1654762c..bd8d0e394b4 100644 --- a/meson.build +++ b/meson.build @@ -729,10 +729,10 @@ if not cc.has_function('socket') endif endif +lib_rt = cc.find_library('rt', required : false) realtime_libs = [] have = cc.has_function('clock_gettime') if not have - lib_rt = cc.find_library('rt', required : false) if lib_rt.found() realtime_libs += lib_rt have = cc.has_function('clock_gettime', @@ -745,7 +745,6 @@ thread_libs = dependency('threads') have = cc.has_function('timer_create') if not have - lib_rt = cc.find_library('rt', required : false) if lib_rt.found() realtime_libs = [lib_rt] have = cc.has_function('timer_create', @@ -2714,9 +2713,7 @@ endif mq_libs = [] mq_libs += cc.find_library('rt', required : true) -lib_rt = cc.find_library('rt', required : get_option('build-lsfd')) - -opt = not get_option('build-lsfd').disabled() +opt = not get_option('build-lsfd').require(lib_rt.found()).disabled() exe = executable( 'lsfd', lsfd_sources,