From 19046fd8543c2c1c7b8cfc1aa6fef11741f3fc51 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 16 Mar 2016 21:55:03 +0200 Subject: Added new base options and some sample opts for gcc. --- mesonbuild/compilers.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'mesonbuild/compilers.py') diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index f3ddf8d..4dcc256 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -66,6 +66,7 @@ msvc_buildtype_args = {'plain' : [], gnulike_buildtype_linker_args = {} + if mesonlib.is_osx(): gnulike_buildtype_linker_args.update({'plain' : [], 'debug' : [], @@ -111,6 +112,81 @@ msvc_winlibs = ['kernel32.lib', 'user32.lib', 'gdi32.lib', 'winspool.lib', 'shell32.lib', 'ole32.lib', 'oleaut32.lib', 'uuid.lib', 'comdlg32.lib', 'advapi32.lib'] + +base_options = {'b_lto': coredata.UserBooleanOption('b_lto', 'Use link time optimization', False), + 'b_sanitize': coredata.UserComboOption('b_sanitize', + 'Code sanitizer to use', + ['none', 'address', 'thread', 'undefined', 'memory'], + 'none'), + 'b_lundef': coredata.UserBooleanOption('b_lundef', 'Use -Wl,--no-undefined when linking', True), + 'b_pgo': coredata.UserComboOption('b_pgo', 'Use profile guide optimization', + ['off', 'generate', 'use'], + 'off') + } + +def sanitizer_compile_args(value): + if value == 'none': + return [] + args = ['-fsanitize=' + value] + if value == 'address': + args.append('-fno-omit-frame-pointer') + return args + +def sanitizer_link_args(value): + if value == 'none': + return [] + args = ['-fsanitize=' + value] + return args + +def get_base_compile_args(options): + args = [] + # FIXME, gcc/clang specific. + try: + if options['b_lto'].value: + args.append('-flto') + except KeyError: + pass + try: + args += sanitizer_compile_args(options['b_sanitize'].value) + except KeyError: + pass + try: + pgo_val = options['b_pgo'].value + if pgo_val == 'generate': + args.append('-fprofile-generate') + elif pgo_val == 'use': + args.append('-fprofile-use') + except KeyError: + pass + return args + +def get_base_link_args(options): + args = [] + # FIXME, gcc/clang specific. + try: + if options['b_lto'].value: + args.append('-flto') + except KeyError: + pass + try: + args += sanitizer_link_args(options['b_sanitize'].value) + except KeyError: + pass + try: + pgo_val = options['b_pgo'].value + if pgo_val == 'generate': + args.append('-fprofile-generate') + elif pgo_val == 'use': + args.append('-fprofile-use') + except KeyError: + pass + try: + if options['b_lundef'].value: + args.append('-Wl,--no-undefined') + except KeyError: + pass + return args + def build_unix_rpath_args(build_dir, rpath_paths, install_rpath): if len(rpath_paths) == 0 and len(install_rpath) == 0: return [] @@ -147,6 +223,7 @@ class Compiler(): else: raise TypeError('Unknown argument to Compiler') self.version = version + self.base_options = [] def get_always_args(self): return [] @@ -1293,6 +1370,7 @@ class GnuCCompiler(CCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize', 'b_lundef'] def get_pic_args(self): if self.gcc_type == GCC_MINGW: @@ -1355,6 +1433,7 @@ class GnuObjCCompiler(ObjCCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize', 'b_lundef'] def get_buildtype_args(self, buildtype): return gnulike_buildtype_args[buildtype] @@ -1380,6 +1459,7 @@ class GnuObjCPPCompiler(ObjCPPCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize', 'b_lundef'] def get_buildtype_args(self, buildtype): return gnulike_buildtype_args[buildtype] @@ -1455,6 +1535,7 @@ class GnuCPPCompiler(CPPCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize', 'b_lundef'] def get_always_args(self): return ['-pipe'] -- cgit v1.1 From 90c799fc610f2955d08e84c053ab43dd09768e20 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Thu, 17 Mar 2016 22:52:55 +0200 Subject: Do not use lundef on OSX. --- mesonbuild/compilers.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'mesonbuild/compilers.py') diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 4dcc256..4bb0d83 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -1370,7 +1370,9 @@ class GnuCCompiler(CCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize', 'b_lundef'] + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + if self.gcc_type != GCC_OSX: + self.base_options.append('b_lundef') def get_pic_args(self): if self.gcc_type == GCC_MINGW: @@ -1433,7 +1435,9 @@ class GnuObjCCompiler(ObjCCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize', 'b_lundef'] + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + if self.gcc_type != GCC_OSX: + self.base_options.append('b_lundef') def get_buildtype_args(self, buildtype): return gnulike_buildtype_args[buildtype] @@ -1459,7 +1463,9 @@ class GnuObjCPPCompiler(ObjCPPCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize', 'b_lundef'] + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + if self.gcc_type != GCC_OSX: + self.base_options.append('b_lundef') def get_buildtype_args(self, buildtype): return gnulike_buildtype_args[buildtype] @@ -1535,7 +1541,9 @@ class GnuCPPCompiler(CPPCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize', 'b_lundef'] + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + if self.gcc_type != GCC_OSX: + self.base_options.append('b_lundef') def get_always_args(self): return ['-pipe'] -- cgit v1.1 From ae1f284ade322f28b2efdf7abaef2543949f31d3 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 18 Mar 2016 00:36:39 +0200 Subject: Added base options to Clang compilers. --- mesonbuild/compilers.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'mesonbuild/compilers.py') diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 4bb0d83..2c35c67 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -1348,6 +1348,11 @@ GCC_STANDARD = 0 GCC_OSX = 1 GCC_MINGW = 2 +CLANG_STANDARD = 0 +CLANG_OSX = 1 +CLANG_WIN = 2 +# Possibly clang-cl? + def get_gcc_soname_args(gcc_type, shlib_name, path, soversion): if soversion is None: sostr = '' @@ -1480,22 +1485,34 @@ class GnuObjCPPCompiler(ObjCPPCompiler): return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion) class ClangObjCCompiler(GnuObjCCompiler): - def __init__(self, exelist, version, is_cross, exe_wrapper=None): + def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): super().__init__(exelist, version, is_cross, exe_wrapper) self.id = 'clang' + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + self.clang_type = cltype + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') class ClangObjCPPCompiler(GnuObjCPPCompiler): - def __init__(self, exelist, version, is_cross, exe_wrapper=None): + def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): super().__init__(exelist, version, is_cross, exe_wrapper) self.id = 'clang' + self.clang_type = cltype + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') class ClangCCompiler(CCompiler): - def __init__(self, exelist, version, is_cross, exe_wrapper=None): + def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None): CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) self.id = 'clang' + self.clang_type = clang_type self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') def get_buildtype_args(self, buildtype): return gnulike_buildtype_args[buildtype] @@ -1584,12 +1601,16 @@ class GnuCPPCompiler(CPPCompiler): return [] class ClangCPPCompiler(CPPCompiler): - def __init__(self, exelist, version, is_cross, exe_wrapper=None): + def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) self.id = 'clang' self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} + self.clang_type = cltype + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') def get_buildtype_args(self, buildtype): return gnulike_buildtype_args[buildtype] -- cgit v1.1 From 0c9c29b6b64a05611dc66ec04747b3970e25ca5c Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 20 Mar 2016 19:00:57 +0200 Subject: Preserve b_ prefix for base option names. --- mesonbuild/compilers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mesonbuild/compilers.py') diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 2c35c67..2a9c3ab 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -121,7 +121,7 @@ base_options = {'b_lto': coredata.UserBooleanOption('b_lto', 'Use link time opti 'b_lundef': coredata.UserBooleanOption('b_lundef', 'Use -Wl,--no-undefined when linking', True), 'b_pgo': coredata.UserComboOption('b_pgo', 'Use profile guide optimization', ['off', 'generate', 'use'], - 'off') + 'off'), } def sanitizer_compile_args(value): -- cgit v1.1 From 0c63f75aafd664ad4d5a478cdbd9f3e8fd582736 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 20 Mar 2016 19:16:49 +0200 Subject: Converted coverage into a base option. --- mesonbuild/compilers.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'mesonbuild/compilers.py') diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 2a9c3ab..50403ef 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -122,6 +122,9 @@ base_options = {'b_lto': coredata.UserBooleanOption('b_lto', 'Use link time opti 'b_pgo': coredata.UserComboOption('b_pgo', 'Use profile guide optimization', ['off', 'generate', 'use'], 'off'), + 'b_coverage': coredata.UserBooleanOption('b_coverage', + 'Enable coverage tracking.', + True), } def sanitizer_compile_args(value): @@ -138,7 +141,7 @@ def sanitizer_link_args(value): args = ['-fsanitize=' + value] return args -def get_base_compile_args(options): +def get_base_compile_args(options, compiler): args = [] # FIXME, gcc/clang specific. try: @@ -158,9 +161,14 @@ def get_base_compile_args(options): args.append('-fprofile-use') except KeyError: pass + try: + if options['b_coverage'].value: + args += compiler.get_coverage_args() + except KeyError: + pass return args -def get_base_link_args(options): +def get_base_link_args(options, linker): args = [] # FIXME, gcc/clang specific. try: @@ -185,6 +193,11 @@ def get_base_link_args(options): args.append('-Wl,--no-undefined') except KeyError: pass + try: + if options['b_coverage'].value: + args += linker.get_coverage_link_args() + except KeyError: + pass return args def build_unix_rpath_args(build_dir, rpath_paths, install_rpath): -- cgit v1.1 From 79de463993fb8201edd389df1626fec841f403d6 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 20 Mar 2016 19:35:42 +0200 Subject: Converted precompiled headers into a base option. --- mesonbuild/compilers.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'mesonbuild/compilers.py') diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 50403ef..30f6e60 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -113,7 +113,9 @@ msvc_winlibs = ['kernel32.lib', 'user32.lib', 'gdi32.lib', 'uuid.lib', 'comdlg32.lib', 'advapi32.lib'] -base_options = {'b_lto': coredata.UserBooleanOption('b_lto', 'Use link time optimization', False), +base_options = { + 'b_pch': coredata.UserBooleanOption('b_lto', 'Use precompiled headers', False), + 'b_lto': coredata.UserBooleanOption('b_lto', 'Use link time optimization', False), 'b_sanitize': coredata.UserComboOption('b_sanitize', 'Code sanitizer to use', ['none', 'address', 'thread', 'undefined', 'memory'], @@ -1190,6 +1192,7 @@ class VisualStudioCCompiler(CCompiler): self.warn_args = {'1': ['/W2'], '2': ['/W3'], '3': ['/w4']} + self.base_options = ['b_pch'] # FIXME add lto, pgo and the like def get_always_args(self): return self.always_args @@ -1312,6 +1315,7 @@ class VisualStudioCPPCompiler(VisualStudioCCompiler): VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap) self.language = 'cpp' self.default_suffix = 'cpp' + self.base_options = ['b_pch'] # FIXME add lto, pgo and the like def can_compile(self, filename): suffix = filename.split('.')[-1] @@ -1388,7 +1392,7 @@ class GnuCCompiler(CCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize'] if self.gcc_type != GCC_OSX: self.base_options.append('b_lundef') @@ -1453,7 +1457,7 @@ class GnuObjCCompiler(ObjCCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize'] if self.gcc_type != GCC_OSX: self.base_options.append('b_lundef') @@ -1481,7 +1485,7 @@ class GnuObjCPPCompiler(ObjCPPCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize'] if self.gcc_type != GCC_OSX: self.base_options.append('b_lundef') @@ -1501,7 +1505,7 @@ class ClangObjCCompiler(GnuObjCCompiler): def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): super().__init__(exelist, version, is_cross, exe_wrapper) self.id = 'clang' - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize'] self.clang_type = cltype if self.clang_type != CLANG_OSX: self.base_options.append('b_lundef') @@ -1511,7 +1515,7 @@ class ClangObjCPPCompiler(GnuObjCPPCompiler): super().__init__(exelist, version, is_cross, exe_wrapper) self.id = 'clang' self.clang_type = cltype - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize'] if self.clang_type != CLANG_OSX: self.base_options.append('b_lundef') @@ -1523,7 +1527,7 @@ class ClangCCompiler(CCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize'] if self.clang_type != CLANG_OSX: self.base_options.append('b_lundef') @@ -1571,7 +1575,7 @@ class GnuCPPCompiler(CPPCompiler): self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize'] if self.gcc_type != GCC_OSX: self.base_options.append('b_lundef') @@ -1621,7 +1625,7 @@ class ClangCPPCompiler(CPPCompiler): '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} self.clang_type = cltype - self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize'] if self.clang_type != CLANG_OSX: self.base_options.append('b_lundef') -- cgit v1.1