diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-07-01 14:43:51 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-07-01 20:50:47 +0530 |
commit | 0143c32c7cd82872e42f57216bb94a26191f2824 (patch) | |
tree | 7b6030e63de5283548ce234dd4d96a36a7380f1b /mesonbuild/backend | |
parent | bc347aed0be4d8ea6210a546fb350f7bc1eee529 (diff) | |
download | meson-0143c32c7cd82872e42f57216bb94a26191f2824.zip meson-0143c32c7cd82872e42f57216bb94a26191f2824.tar.gz meson-0143c32c7cd82872e42f57216bb94a26191f2824.tar.bz2 |
Overhaul versioning and naming of libraries
This commit contains several changes to the naming and versioning of
shared and static libraries. The details are documented at:
https://github.com/mesonbuild/meson/pull/417
Here's a brief summary:
* The results of binary and compiler detection via environment functions
are now cached so that they can be called repeatedly without
performance penalty. This is necessary because every
build.SharedLibrary object has to know whether the compiler is MSVC or
not (output filenames depend on that), and so the compiler detection
has to be called for each object instantiation.
* Linux shared libraries don't always have a library version. Sometimes
only soversions are specified (and vice-versa), so support both.
* Don't use versioned filenames when generating DLLs, DLLs are never
versioned using the suffix in the way that .so libraries are. Hence,
they don't use "aliases". Only Linux shared libraries use those.
* OS X dylibs do not use filename aliases at all. They only use the
soversion in the dylib name (libfoo.X.dylib), and that's it. If
there's no soversion specified, the dylib is called libfoo.dylib.
Further versioning in dylibs is supposed to be done with the
-current_version argument to clang, but this is TBD.
https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html#//apple_ref/doc/uid/TP40002013-SW23
* Install DLLs into bindir and import libraries into libdir
* Static libraries are now always called libfoo.a, even with MSVC
* .lib import libraries are always generated when building with MSVC
* .dll.a import libraries are always generated when building with
MinGW/GCC or MinGW/clang
* TODO: Use dlltool if available to generate .dll.a when .lib is
generated and vice-versa.
* Library and executable suffix/prefixes are now always correctly
overriden by the values of the 'name_prefix' and 'name_suffix' keyword
arguments.
Diffstat (limited to 'mesonbuild/backend')
-rw-r--r-- | mesonbuild/backend/backends.py | 10 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 35 | ||||
-rw-r--r-- | mesonbuild/backend/vs2010backend.py | 4 | ||||
-rw-r--r-- | mesonbuild/backend/xcodebackend.py | 8 |
4 files changed, 40 insertions, 17 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index bc49966..37503ba 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -105,9 +105,13 @@ class Backend(): # On some platforms (msvc for instance), the file that is used for # dynamic linking is not the same as the dynamic library itself. This # file is called an import library, and we want to link against that. - # On platforms where this distinction is not important, the import - # library is the same as the dynamic library itself. - return os.path.join(self.get_target_dir(target), target.get_import_filename()) + # On all other platforms, we link to the library directly. + if isinstance(target, build.SharedLibrary): + link_lib = target.get_import_filename() or target.get_filename() + return os.path.join(self.get_target_dir(target), link_lib) + elif isinstance(target, build.StaticLibrary): + return os.path.join(self.get_target_dir(target), target.get_filename()) + raise AssertionError('BUG: Tried to link to something that\'s not a library') def get_target_dir(self, target): if self.environment.coredata.get_builtin_option('layout') == 'mirror': diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index b583e62..f6a3c75 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -492,18 +492,33 @@ int dummy; pickle.dump(d, ofile) def generate_target_install(self, d): - libdir = self.environment.get_libdir() - bindir = self.environment.get_bindir() - should_strip = self.environment.coredata.get_builtin_option('strip') for t in self.build.get_targets().values(): if t.should_install(): + # Find the installation directory outdir = t.get_custom_install_dir() - if outdir is None: - if isinstance(t, build.Executable): - outdir = bindir - else: - outdir = libdir + if outdir is not None: + pass + elif isinstance(t, build.SharedLibrary): + # For toolchains/platforms that need an import library for + # linking (separate from the shared library with all the + # code), we need to install the import library (dll.a/.lib) + if t.get_import_filename(): + # Install the import library. + i = [self.get_target_filename_for_linking(t), + self.environment.get_import_lib_dir(), + # It has no aliases, should not be stripped, and + # doesn't have an install_rpath + [], False, ''] + d.targets.append(i) + outdir = self.environment.get_shared_lib_dir() + elif isinstance(t, build.SharedLibrary): + outdir = self.environment.get_static_lib_dir() + elif isinstance(t, build.Executable): + outdir = self.environment.get_bindir() + else: + # XXX: Add BuildTarget-specific install dir cases here + outdir = self.environment.get_libdir() i = [self.get_target_filename(t), outdir, t.get_aliaslist(),\ should_strip, t.install_rpath] d.targets.append(i) @@ -1661,8 +1676,12 @@ rule FORTRAN_DEP_HACK else: soversion = None commands += linker.get_soname_args(target.name, abspath, soversion) + # 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)) + # This is only visited when building for Windows using either MinGW/GCC or Visual Studio + if target.import_filename: + commands += linker.gen_import_library_args(os.path.join(target.subdir, target.import_filename)) elif isinstance(target, build.StaticLibrary): commands += linker.get_std_link_args() else: diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index d262e6b..72923b1 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -585,7 +585,7 @@ class Vs2010Backend(backends.Backend): for t in target.get_dependencies(): lobj = self.build.targets[t.get_id()] rel_path = self.relpath(lobj.subdir, target.subdir) - linkname = os.path.join(rel_path, lobj.get_import_filename()) + linkname = os.path.join(rel_path, self.get_target_filename_for_linking(lobj)) additional_links.append(linkname) for lib in self.get_custom_target_provided_libraries(target): additional_links.append(self.relpath(lib, self.get_target_dir(target))) @@ -607,6 +607,8 @@ class Vs2010Backend(backends.Backend): gendeb = ET.SubElement(link, 'GenerateDebugInformation') gendeb.text = 'true' if isinstance(target, build.SharedLibrary): + # DLLs built with MSVC always have an import library except when + # they're data-only DLLs, but we don't support those yet. ET.SubElement(link, 'ImportLibrary').text = target.get_import_filename() pdb = ET.SubElement(link, 'ProgramDataBaseFileName') pdb.text = '$(OutDir}%s.pdb' % target_name diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py index 0ce90ce..e64866d 100644 --- a/mesonbuild/backend/xcodebackend.py +++ b/mesonbuild/backend/xcodebackend.py @@ -292,12 +292,10 @@ class XCodeBackend(backends.Backend): reftype = 0 if isinstance(t, build.Executable): typestr = 'compiled.mach-o.executable' - path = t.get_filename() + path = fname elif isinstance(t, build.SharedLibrary): - # OSX has a completely different shared library - # naming scheme so do this manually. typestr = self.get_xcodetype('dummy.dylib') - path = t.get_osx_filename() + path = fname else: typestr = self.get_xcodetype(fname) path = '"%s"' % t.get_filename() @@ -626,7 +624,7 @@ class XCodeBackend(backends.Backend): headerdirs.append(os.path.join(self.environment.get_build_dir(), cd)) for l in target.link_targets: abs_path = os.path.join(self.environment.get_build_dir(), - l.subdir, buildtype, l.get_osx_filename()) + l.subdir, buildtype, l.get_filename()) dep_libs.append("'%s'" % abs_path) if isinstance(l, build.SharedLibrary): links_dylib = True |