]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: Don't create static library target unless option is enabled 37395/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 10 May 2025 20:19:22 +0000 (22:19 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 12 May 2025 11:35:50 +0000 (13:35 +0200)
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.

meson.build
src/test/meson.build

index 65b77c52148eaf90d001c3badf8ffe9531edb098..48b8b05834922e4b742932c849342dfa20f99484 100644 (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)
index 8640932d67ce7766d46d0664be08f00bda1f42e6..24d0dca2eebe92548b63e3750c54d9ce32beab61 100644 (file)
@@ -461,14 +461,6 @@ executables += [
                 'link_with' : libsystemd,
                 'suite' : 'libsystemd',
         },
-        test_template + {
-                'name' : 'test-libsystemd-static-sym',
-                'sources' : test_libsystemd_sym_c,
-                'link_with' : install_libsystemd_static,
-                'build_by_default' : want_tests != 'false' and static_libsystemd != 'false',
-                'install' : install_tests and static_libsystemd != 'false',
-                'suite' : 'libsystemd',
-        },
         test_template + {
                 'name' : 'test-libudev-sym',
                 'sources' : test_libudev_sym_c,
@@ -477,16 +469,6 @@ executables += [
                 'link_with' : libudev,
                 'suite' : 'libudev',
         },
-        test_template + {
-                'name' : 'test-libudev-static-sym',
-                'sources' : test_libudev_sym_c,
-                'include_directories' : libudev_includes,
-                'c_args' : ['-Wno-deprecated-declarations'] + test_cflags,
-                'link_with' : install_libudev_static,
-                'build_by_default' : want_tests != 'false' and static_libudev != 'false',
-                'install' : install_tests and static_libudev != 'false',
-                'suite' : 'libudev',
-        },
 
         # Tests that link to libcore, i.e. tests for pid1 code.
         core_test_template + {
@@ -627,3 +609,31 @@ executables += [
                 ],
         },
 ]
+
+if static_libsystemd != 'false'
+        executables += [
+                test_template + {
+                        'name' : 'test-libsystemd-static-sym',
+                        'sources' : test_libsystemd_sym_c,
+                        'link_with' : install_libsystemd_static,
+                        'build_by_default' : want_tests != 'false',
+                        'install' : install_tests,
+                        'suite' : 'libsystemd',
+                },
+        ]
+endif
+
+if static_libudev != 'false'
+        executables += [
+                test_template + {
+                        'name' : 'test-libudev-static-sym',
+                        'sources' : test_libudev_sym_c,
+                        'include_directories' : libudev_includes,
+                        'c_args' : ['-Wno-deprecated-declarations'] + test_cflags,
+                        'link_with' : install_libudev_static,
+                        'build_by_default' : want_tests != 'false',
+                        'install' : install_tests,
+                        'suite' : 'libudev',
+                },
+        ]
+endif