chiark / gitweb /
meson: use get_supported_arguments()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 10 May 2018 06:30:42 +0000 (15:30 +0900)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
This bumps the required minimum version of meson to 0.43, as
`get_supported_arguments()` is supported since meson-0.43.

meson.build

index 0193f95f2e163e3dbbfb3b36b362d5ed2384457c..6b4dc6dfe861af9aa0168ef1dec61644bfe8cf34 100644 (file)
@@ -11,7 +11,7 @@ project('elogind', 'c',
                 'sysconfdir=/etc',
                 'localstatedir=/var',
         ],
-        meson_version : '>= 0.41',
+        meson_version : '>= 0.43',
        )
 
 #if 0 /// UNNEEDED by elogind - libudev is external
@@ -21,7 +21,7 @@ project('elogind', 'c',
 libelogind_version = '0.22.0'
 #endif // 0
 
-# We need the same data in three different formats, ugh!
+# We need the same data in two different formats, ugh!
 # Also, for hysterical reasons, we use different variable
 # names, sometimes. Not all variables are included in every
 # set. Ugh, ugh, ugh!
@@ -37,8 +37,6 @@ substs.set('PACKAGE_URL',          'https://github.com/elogind/elogind')
 #endif // 0
 substs.set('PACKAGE_VERSION',      meson.project_version())
 
-m4_defines = []
-
 #####################################################################
 #if 0 /// elogind does not need this
 # 
@@ -84,11 +82,9 @@ endif
 #if 0 /// UNNEEDED by elogind
 # sysvinit_path = get_option('sysvinit-path')
 # sysvrcnd_path = get_option('sysvrcnd-path')
-# have = sysvinit_path != '' and sysvrcnd_path != ''
-# conf.set10('HAVE_SYSV_COMPAT', have,
+# conf.set10('HAVE_SYSV_COMPAT', sysvinit_path != '' and sysvrcnd_path != '',
 #            description : 'SysV init scripts and rcN.d links are supported')
 #endif // 0
-m4_defines += have ? ['-DHAVE_SYSV_COMPAT'] : []
 
 # join_paths ignore the preceding arguments if an absolute component is
 # encountered, so this should canonicalize various paths when they are
@@ -361,59 +357,80 @@ endif
 # if want_ossfuzz
 #         fuzzing_engine = meson.get_compiler('cpp').find_library('FuzzingEngine')
 # endif
+# 
+# possible_cc_flags = [
+#         '-Wextra',
+#         '-Werror=undef',
+#         '-Wlogical-op',
+#         '-Wmissing-include-dirs',
+#         '-Wold-style-definition',
+#         '-Wpointer-arith',
+#         '-Winit-self',
+#         '-Wdeclaration-after-statement',
+#         '-Wfloat-equal',
+#         '-Wsuggest-attribute=noreturn',
+#         '-Werror=missing-prototypes',
+#         '-Werror=implicit-function-declaration',
+#         '-Werror=missing-declarations',
+#         '-Werror=return-type',
+#         '-Werror=incompatible-pointer-types',
+#         '-Werror=format=2',
+#         '-Wstrict-prototypes',
+#         '-Wredundant-decls',
+#         '-Wmissing-noreturn',
+#         '-Wimplicit-fallthrough=5',
+#         '-Wshadow',
+#         '-Wendif-labels',
+#         '-Wstrict-aliasing=2',
+#         '-Wwrite-strings',
+#         '-Werror=overflow',
+#         '-Wdate-time',
+#         '-Wnested-externs',
+#         '-ffast-math',
+#         '-fno-common',
+#         '-fdiagnostics-show-option',
+#         '-fno-strict-aliasing',
+#         '-fvisibility=hidden',
+#         '-fstack-protector',
+#         '-fstack-protector-strong',
+#         '--param=ssp-buffer-size=4',
+# ]
+# 
+# # --as-needed and --no-undefined are provided by meson by default,
+# # run mesonconf to see what is enabled
+# possible_link_flags = [
+#         '-Wl,-z,relro',
+#         '-Wl,-z,now',
+# ]
 #else
 fuzzer_build = false
 #endif // 0
 
-foreach arg : ['-Wextra',
-               '-Werror=undef',
-               '-Wlogical-op',
-               '-Wmissing-include-dirs',
-               '-Wold-style-definition',
-               '-Wpointer-arith',
-               '-Winit-self',
-               '-Wdeclaration-after-statement',
-               '-Wfloat-equal',
-               '-Wsuggest-attribute=noreturn',
-               '-Werror=missing-prototypes',
-               '-Werror=implicit-function-declaration',
-               '-Werror=missing-declarations',
-               '-Werror=return-type',
-               '-Werror=incompatible-pointer-types',
-               '-Werror=format=2',
-               '-Wstrict-prototypes',
-               '-Wredundant-decls',
-               '-Wmissing-noreturn',
-               '-Wimplicit-fallthrough=5',
-               '-Wshadow',
-               '-Wendif-labels',
-               '-Wstrict-aliasing=2',
-               '-Wwrite-strings',
-               '-Werror=overflow',
-               '-Wdate-time',
-               '-Wnested-externs',
-               '-ffast-math',
-               '-fno-common',
-               '-fdiagnostics-show-option',
-               '-fno-strict-aliasing',
-               '-fvisibility=hidden',
-               '-fstack-protector',
-               '-fstack-protector-strong',
-               '--param=ssp-buffer-size=4',
-              ]
-        if cc.has_argument(arg)
-                add_project_arguments(arg, language : 'c')
-        endif
-endforeach
-
 # the oss-fuzz fuzzers are not built with -fPIE, so don't
 # enable it when we are linking against them
 if not fuzzer_build
-        if cc.has_argument('-fPIE')
-              add_project_arguments('-fPIE', language : 'c')
-        endif
+        possible_cc_flags += '-fPIE'
+        possible_link_flags += '-pie'
+endif
+
+if cc.get_id() == 'clang'
+        possible_cc_flags += [
+                '-Wno-typedef-redefinition',
+                '-Wno-gnu-variable-sized-type-not-at-end',
+        ]
 endif
 
+if get_option('buildtype') != 'debug'
+        possible_cc_flags += [
+                '-ffunction-sections',
+                '-fdata-sections',
+        ]
+
+        possible_link_flags += '-Wl,--gc-sections'
+endif
+
+add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
+
 # "negative" arguments: gcc on purpose does not return an error for "-Wno-"
 # arguments, just emits a warnings. So test for the "positive" version instead.
 foreach arg : ['unused-parameter',
@@ -440,55 +457,18 @@ if cc.compiles('''
         add_project_arguments('-Werror=shadow', language : 'c')
 endif
 
-if cc.get_id() == 'clang'
-        foreach arg : ['-Wno-typedef-redefinition',
-                       '-Wno-gnu-variable-sized-type-not-at-end',
-                      ]
-                if cc.has_argument(arg,
-                                   name : '@0@ is supported'.format(arg))
-                        add_project_arguments(arg, language : 'c')
-                endif
-        endforeach
-endif
-
 link_test_c = files('tools/meson-link-test.c')
 
-# --as-needed and --no-undefined are provided by meson by default,
-# run mesonconf to see what is enabled
-foreach arg : ['-Wl,-z,relro',
-               '-Wl,-z,now',
-               '-pie',
-              ]
-
+foreach arg : possible_link_flags
         have = run_command(check_compilation_sh,
                            cc.cmd_array(), '-x', 'c', arg,
                            '-include', link_test_c).returncode() == 0
         message('Linking with @0@ supported: @1@'.format(arg, have ? 'yes' : 'no'))
-        if have and (arg != '-pie' or not fuzzer_build)
+        if have
                 add_project_link_arguments(arg, language : 'c')
         endif
 endforeach
 
-if get_option('buildtype') != 'debug'
-        foreach arg : ['-ffunction-sections',
-                       '-fdata-sections']
-                if cc.has_argument(arg,
-                                   name : '@0@ is supported'.format(arg))
-                        add_project_arguments(arg, language : 'c')
-                endif
-        endforeach
-
-        foreach arg : ['-Wl,--gc-sections']
-                have = run_command(check_compilation_sh,
-                                   cc.cmd_array(), '-x', 'c', arg,
-                                   '-include', link_test_c).returncode() == 0
-                message('Linking with @0@ supported: @1@'.format(arg, have ? 'yes' : 'no'))
-                if have
-                        add_project_link_arguments(arg, language : 'c')
-                endif
-        endforeach
-endif
-
 cpp = ' '.join(cc.cmd_array()) + ' -E'
 
 #####################################################################
@@ -872,13 +852,8 @@ substs.set('TTY_GID', tty_gid)
 # endif
 # substs.set('USERS_GID', users_gid)
 # 
-# if get_option('adm-group')
-#         m4_defines += ['-DENABLE_ADM_GROUP']
-# endif
-# 
-# if get_option('wheel-group')
-#         m4_defines += ['-DENABLE_WHEEL_GROUP']
-# endif
+# conf.set10('ENABLE_ADM_GROUP', get_option('adm-group'))
+# conf.set10('ENABLE_WHEEL_GROUP', get_option('wheel-group'))
 # 
 # substs.set('DEV_KVM_MODE', get_option('dev-kvm-mode'))
 # substs.set('GROUP_RENDER_MODE', get_option('group-render-mode'))
@@ -961,7 +936,6 @@ endif
 #         have = false
 #         libseccomp = []
 # endif
-# m4_defines += have ? ['-DHAVE_SECCOMP'] : []
 #else
 libseccomp = []
 #endif // 0
@@ -978,7 +952,6 @@ else
         libselinux = []
 endif
 conf.set10('HAVE_SELINUX', have)
-m4_defines += have ? ['-DHAVE_SELINUX'] : []
 
 #if 0 /// UNNEEDED by elogind
 # want_apparmor = get_option('apparmor')
@@ -990,7 +963,6 @@ m4_defines += have ? ['-DHAVE_SELINUX'] : []
 #         have = false
 #         libapparmor = []
 # endif
-# m4_defines += have ? ['-DHAVE_APPARMOR'] : []
 #else
 libapparmor = []
 #endif // 0
@@ -999,7 +971,6 @@ conf.set10('HAVE_APPARMOR', have)
 smack_run_label = get_option('smack-run-label')
 if smack_run_label != ''
         conf.set_quoted('SMACK_RUN_LABEL', smack_run_label)
-        m4_defines += ['-DHAVE_SMACK_RUN_LABEL']
 endif
 
 want_polkit = get_option('polkit')
@@ -1026,7 +997,6 @@ else
         libacl = []
 endif
 conf.set10('HAVE_ACL', have)
-m4_defines += have ? ['-DHAVE_ACL'] : []
 
 want_audit = get_option('audit')
 if want_audit != 'false' and not fuzzer_build
@@ -1076,7 +1046,6 @@ else
         libpam_misc = []
 endif
 conf.set10('HAVE_PAM', have)
-m4_defines += have ? ['-DHAVE_PAM'] : []
 
 #if 0 /// UNNEEDED by elogind
 # want_microhttpd = get_option('microhttpd')
@@ -1090,7 +1059,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         libmicrohttpd = []
 # endif
 # conf.set10('HAVE_MICROHTTPD', have)
-# m4_defines += have ? ['-DHAVE_MICROHTTPD'] : []
 # 
 # want_libcryptsetup = get_option('libcryptsetup')
 # if want_libcryptsetup != 'false' and not fuzzer_build
@@ -1115,7 +1083,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         libcurl = []
 # endif
 # conf.set10('HAVE_LIBCURL', have)
-# m4_defines += have ? ['-DHAVE_LIBCURL'] : []
 # 
 # want_libidn = get_option('libidn')
 # want_libidn2 = get_option('libidn2')
@@ -1132,7 +1099,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         libidn = []
 # endif
 # conf.set10('HAVE_LIBIDN', have)
-# m4_defines += have ? ['-DHAVE_LIBIDN'] : []
 # if not have and want_libidn2 != 'false' and not fuzzer_build
 #         # libidn is used for both libidn and libidn2 objects
 #         libidn = dependency('libidn2',
@@ -1142,7 +1108,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         have = false
 # endif
 # conf.set10('HAVE_LIBIDN2', have)
-# m4_defines += have ? ['-DHAVE_LIBIDN2'] : []
 # 
 # want_libiptc = get_option('libiptc')
 # if want_libiptc != 'false' and not fuzzer_build
@@ -1154,7 +1119,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         libiptc = []
 # endif
 # conf.set10('HAVE_LIBIPTC', have)
-# m4_defines += have ? ['-DHAVE_LIBIPTC'] : []
 # 
 # want_qrencode = get_option('qrencode')
 # if want_qrencode != 'false' and not fuzzer_build
@@ -1398,7 +1362,6 @@ foreach term : ['utmp',
 #                 'gshadow',
 #                 'idn',
 #                 'nss-systemd']
-#         m4_defines += have ? ['-D' + name] : []
 #else
                 'smack']
 #endif // 0
@@ -1407,6 +1370,8 @@ foreach term : ['utmp',
         conf.set10(name, have)
 endforeach
 
+conf.set10('ENABLE_TIMEDATECTL', get_option('timedated') or get_option('timesyncd'))
+
 want_tests = get_option('tests')
 install_tests = get_option('install-tests')
 slow_tests = get_option('slow-tests')
@@ -1454,6 +1419,8 @@ config_h = configure_file(
         output : 'config.h',
         configuration : conf)
 
+meson_apply_m4 = find_program('tools/meson-apply-m4.sh')
+
 includes = include_directories('src/basic',
                                'src/shared',
                                'src/systemd',
@@ -1943,6 +1910,13 @@ exe = executable('elogind-inhibit',
                         install : true,
                         install_dir : rootbindir)
 public_programs += [exe]
+executable('elogind-user-runtime-dir',
+           user_runtime_dir_sources,
+           include_directories : includes,
+           link_with : [libshared, liblogind_core],
+           install_rpath : rootlibexecdir,
+           install : true,
+           install_dir : rootlibexecdir)
 
 if conf.get('HAVE_PAM') == 1
         version_script_arg = join_paths(meson.current_source_dir(), pam_elogind_sym)
@@ -2151,12 +2125,15 @@ endif
 #                    install_rpath : rootlibexecdir,
 #                    install : true,
 #                    install_dir : rootlibexecdir)
+# endif
 # 
+# if conf.get('ENABLE_TIMEDATECTL') == 1
 #         exe = executable('timedatectl',
 #                          'src/timedate/timedatectl.c',
 #                          include_directories : includes,
 #                          install_rpath : rootlibexecdir,
 #                          link_with : [libshared],
+#                          dependencies : [libm],
 #                          install : true)
 #         public_programs += [exe]
 # endif