]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Meson: LTO
authorFred Morcos <fred.morcos@open-xchange.com>
Tue, 8 Aug 2023 12:02:37 +0000 (14:02 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Wed, 20 Mar 2024 12:28:33 +0000 (13:28 +0100)
meson.build
meson/lto/meson.build [new file with mode: 0644]
meson_options.txt

index e5f51033036e16e0a12e2b99c949d407d03edf8d..e03adcbcdeb27e12f4f6a435572dce489768a1a7 100644 (file)
@@ -72,6 +72,8 @@ subdir('meson/auto-var-init')            # Automatic Variable Initialization
 # TODO Use meson's -Db_sanitize option?
 # subdir('meson/sanitizers')               # Sanitizers
 subdir('meson/malloc-trace')             # Malloc-trace
+# TODO Use meson's -Db_lto* options?
+subdir('meson/lto')                      # Link-time Optimization
 
 # Find or generate pdns/dnslabeltext.cc
 if not ragel.found() and not fs.exists('pdns/dnslabeltext.cc')
diff --git a/meson/lto/meson.build b/meson/lto/meson.build
new file mode 100644 (file)
index 0000000..eb9a0f1
--- /dev/null
@@ -0,0 +1,35 @@
+# Link-time Optimization
+
+opt_lto = get_option('lto')
+
+if opt_lto == 'thin'
+  compiler_opt = '-flto=thin'
+  if cxx.has_argument(compiler_opt)
+    add_global_arguments(compiler_opt, language: ['c', 'cpp'])
+    add_global_link_arguments(compiler_opt, language: ['c', 'cpp'])
+  else
+    opt_lto = 'auto'
+  endif
+endif
+
+if opt_lto == 'auto'
+  compiler_opt = '-flto=auto'
+  if cxx.has_argument(compiler_opt)
+    add_global_arguments(compiler_opt, language: ['c', 'cpp'])
+    add_global_link_arguments(compiler_opt, language: ['c', 'cpp'])
+  else
+    opt_lto = 'yes'
+  endif
+endif
+
+if opt_lto == 'yes'
+  compiler_opt = '-flto'
+  if cxx.has_argument(compiler_opt)
+    add_global_arguments(compiler_opt, language: ['c', 'cpp'])
+    add_global_link_arguments(compiler_opt, language: ['c', 'cpp'])
+  else
+    error('LTO was requested but is not supported')
+  endif
+endif
+
+summary('LTO', opt_lto, section: 'Configuration')
index e1cd4b10f8f5d12188c678b114379172f3b0c156..09e295c45d13c1a32759c2188f1ee4a06c5316b0 100644 (file)
@@ -56,3 +56,5 @@ option('auto-var-init', type: 'combo', value: 'disabled', choices: ['zero', 'pat
 # option('sanitizer-leak', type: 'boolean', value: false, description: 'Enable the Leak Sanitizer')
 # option('sanitizer-undefined', type: 'boolean', value: false, description: 'Enable the Undefined Behavior Sanitizer')
 option('malloc-trace', type: 'boolean', value: false, description: 'Enable malloc-trace')
+# TODO Use meson's -Db_lto* options?
+option('lto', type: 'combo', choices: ['yes', 'no', 'thin', 'auto'], value: 'no', description: 'Enable link-time optimization')