meson: Don't create static library target unless option is enabled

While we don't build these by default, all the source files still
get added to the compile_commands.json file by meson, which can confuse
tools as they might end up analyzing the source files twice or analyzing
the wrong one.

To avoid this issue, only define the static library target if the
corresponding option is enabled.
This commit is contained in:
Daan De Meyer
2025-05-10 22:19:22 +02:00
parent 30d20907bd
commit 1fbaabf9ec
2 changed files with 73 additions and 65 deletions

View File

@@ -2067,34 +2067,33 @@ libsystemd = shared_library(
install_tag: 'libsystemd',
install_dir : libdir)
install_libsystemd_static = static_library(
'systemd',
libsystemd_sources,
basic_sources,
fundamental_sources,
include_directories : libsystemd_includes,
implicit_include_directories : false,
build_by_default : static_libsystemd != 'false',
install : static_libsystemd != 'false',
install_tag: 'libsystemd',
install_dir : libdir,
pic : static_libsystemd_pic,
dependencies : [libblkid,
libcap,
libdl,
libgcrypt_cflags,
liblz4_cflags,
libm,
libmount,
libopenssl,
librt,
libxz_cflags,
libzstd_cflags,
threads,
userspace],
c_args : libsystemd_c_args + (static_libsystemd_pic ? [] : ['-fno-PIC']))
if static_libsystemd != 'false'
install_libsystemd_static = static_library(
'systemd',
libsystemd_sources,
basic_sources,
fundamental_sources,
include_directories : libsystemd_includes,
implicit_include_directories : false,
install : true,
install_tag: 'libsystemd',
install_dir : libdir,
pic : static_libsystemd_pic,
dependencies : [libblkid,
libcap,
libdl,
libgcrypt_cflags,
liblz4_cflags,
libm,
libmount,
libopenssl,
librt,
libxz_cflags,
libzstd_cflags,
threads,
userspace],
c_args : libsystemd_c_args + (static_libsystemd_pic ? [] : ['-fno-PIC']))
alias_target('libsystemd', libsystemd, install_libsystemd_static)
else
alias_target('libsystemd', libsystemd)
@@ -2116,27 +2115,26 @@ libudev = shared_library(
install_tag: 'libudev',
install_dir : libdir)
install_libudev_static = static_library(
'udev',
basic_sources,
fundamental_sources,
shared_sources,
libsystemd_sources,
libudev_sources,
include_directories : includes,
implicit_include_directories : false,
build_by_default : static_libudev != 'false',
install : static_libudev != 'false',
install_tag: 'libudev',
install_dir : libdir,
link_depends : libudev_sym,
dependencies : [libmount,
libshared_deps,
userspace],
c_args : static_libudev_pic ? [] : ['-fno-PIC'],
pic : static_libudev_pic)
if static_libudev != 'false'
install_libudev_static = static_library(
'udev',
basic_sources,
fundamental_sources,
shared_sources,
libsystemd_sources,
libudev_sources,
include_directories : includes,
implicit_include_directories : false,
install : true,
install_tag: 'libudev',
install_dir : libdir,
link_depends : libudev_sym,
dependencies : [libmount,
libshared_deps,
userspace],
c_args : static_libudev_pic ? [] : ['-fno-PIC'],
pic : static_libudev_pic)
alias_target('libudev', libudev, install_libudev_static)
else
alias_target('libudev', libudev)