diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 6e2b1eefb..e5c430eb6 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1937,13 +1937,17 @@ rule FORTRAN_DEP_HACK if isinstance(target, build.Executable): commands += linker.get_std_exe_link_args() elif isinstance(target, build.SharedLibrary): - commands += linker.get_std_shared_lib_link_args() + if isinstance(target, build.SharedModule): + commands += linker.get_std_shared_module_link_args() + else: + commands += linker.get_std_shared_lib_link_args() commands += linker.get_pic_args() if hasattr(target, 'soversion'): soversion = target.soversion else: soversion = None - commands += linker.get_soname_args(target.prefix, target.name, target.suffix, abspath, soversion) + commands += linker.get_soname_args(target.prefix, target.name, target.suffix, + abspath, soversion, isinstance(target, build.SharedModule)) # This is only visited when using the Visual Studio toolchain if target.vs_module_defs and hasattr(linker, 'gen_vs_module_defs_args'): commands += linker.gen_vs_module_defs_args(target.vs_module_defs.rel_to_builddir(self.build_to_src)) diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index c603f370b..e012c556f 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -486,6 +486,12 @@ class Compiler(): def get_link_debugfile_args(self, rel_obj): return [] + def get_std_shared_lib_link_args(self): + return [] + + def get_std_shared_module_link_args(self): + return self.get_std_shared_lib_link_args() + class CCompiler(Compiler): def __init__(self, exelist, version, is_cross, exe_wrapper=None): # If a child ObjC or CPP class has already set it, don't set it ourselves @@ -1178,9 +1184,6 @@ class MonoCompiler(Compiler): def get_include_args(self, path): return [] - def get_std_shared_lib_link_args(self): - return [] - def get_pic_args(self): return [] @@ -1267,9 +1270,6 @@ class JavaCompiler(Compiler): def get_include_args(self, path): return [] - def get_std_shared_lib_link_args(self): - return [] - def get_pic_args(self): return [] @@ -1962,7 +1962,7 @@ CLANG_OSX = 1 CLANG_WIN = 2 # Possibly clang-cl? -def get_gcc_soname_args(gcc_type, prefix, shlib_name, suffix, path, soversion): +def get_gcc_soname_args(gcc_type, prefix, shlib_name, suffix, path, soversion, is_shared_module): if soversion is None: sostr = '' else: @@ -1972,6 +1972,8 @@ def get_gcc_soname_args(gcc_type, prefix, shlib_name, suffix, path, soversion): return ['-Wl,-soname,%s%s.%s%s' % (prefix, shlib_name, suffix, sostr)] return ['-Wl,-soname,%s%s' % (shlib_name, sostr)] elif gcc_type == GCC_OSX: + if is_shared_module: + return [] return ['-install_name', os.path.join(path, 'lib' + shlib_name + '.dylib')] else: raise RuntimeError('Not implemented yet.') @@ -2007,7 +2009,7 @@ class GnuCompiler: def get_define(self, define): if define in self.defines: - return defines[define] + return self.defines[define] def get_pic_args(self): if self.gcc_type in (GCC_MINGW, GCC_OSX): @@ -2029,8 +2031,13 @@ class GnuCompiler: def split_shlib_to_parts(self, fname): return (os.path.split(fname)[0], fname) - def get_soname_args(self, prefix, shlib_name, suffix, path, soversion): - return get_gcc_soname_args(self.gcc_type, prefix, shlib_name, suffix, path, soversion) + def get_soname_args(self, prefix, shlib_name, suffix, path, soversion, is_shared_module): + return get_gcc_soname_args(self.gcc_type, prefix, shlib_name, suffix, path, soversion, is_shared_module) + + def get_std_shared_lib_link_args(self): + if self.gcc_type == GCC_OSX: + return ['-bundle'] + return ['-shared'] class GnuCCompiler(GnuCompiler, CCompiler): def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None): @@ -2066,6 +2073,9 @@ class GnuCCompiler(GnuCompiler, CCompiler): return options['c_winlibs'].value[:] return [] + def get_std_shared_lib_link_args(self): + return ['-shared'] + class GnuCPPCompiler(GnuCompiler, CPPCompiler): def __init__(self, exelist, version, gcc_type, is_cross, exe_wrap, defines): @@ -2193,6 +2203,11 @@ class ClangCompiler(): extra_args.append('-Wl,-no_weak_imports') return super().has_function(funcname, prefix, env, extra_args, dependencies) + def get_std_shared_module_link_args(self): + if self.clang_type == CLANG_OSX: + return ['-bundle'] + return ['-shared'] + class ClangCCompiler(ClangCompiler, CCompiler): def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None): CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) @@ -2317,8 +2332,8 @@ end program prog def split_shlib_to_parts(self, fname): return (os.path.split(fname)[0], fname) - def get_soname_args(self, prefix, shlib_name, suffix, path, soversion): - return get_gcc_soname_args(self.gcc_type, prefix, shlib_name, suffix, path, soversion) + def get_soname_args(self, prefix, shlib_name, suffix, path, soversion, is_shared_module): + return get_gcc_soname_args(self.gcc_type, prefix, shlib_name, suffix, path, soversion, is_shared_module) def get_dependency_gen_args(self, outtarget, outfile): # Disabled until this is fixed: