[pangomm/meson.msvc: 4/4] meson: Build import .lib for MSVC builds



commit 8acf13dd663d9f8f03180b9316c3c48b5804057b
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Oct 17 13:03:23 2019 +0800

    meson: Build import .lib for MSVC builds
    
    This first builds gendef.cc in MSVC_NMake/gendef so that we can use it
    to generate the .def file that we need to build the import .lib file for
    the pangomm DLL.
    
    However, in order to do this in Meson, we need to build the sources into
    a temporary static .lib and run gendef.exe against it (which works with
    gendef.cc unchanged, thanks to dumpbin /symbols accepting static .lib's
    as well, so we won't have to figure out where the compiled object files
    are) in order to obtain the symbols that we need, since Meson does not
    support pre-link build steps.
    
    Note that all the source files are still compiled only once since we are
    using extract_all_objects(), so the only overhead is the temporary static
    .lib that we need to build to obtain the .def file.

 MSVC_NMake/gendef/meson.build |  9 +++++++++
 meson.build                   |  1 +
 pango/pangomm/meson.build     | 31 +++++++++++++++++++++++++++++--
 3 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/MSVC_NMake/gendef/meson.build b/MSVC_NMake/gendef/meson.build
new file mode 100644
index 0000000..11c1c2f
--- /dev/null
+++ b/MSVC_NMake/gendef/meson.build
@@ -0,0 +1,9 @@
+# MSVC_NMake/gendef
+
+# Input: -
+# Output: -
+
+# Used to generate the .def file required to obtain the import .lib file
+if is_msvc
+  gendef = executable('gendef', 'gendef.cc', install: false,)
+endif
diff --git a/meson.build b/meson.build
index ab9fe26..b0c9546 100644
--- a/meson.build
+++ b/meson.build
@@ -204,6 +204,7 @@ warning_flags = cpp_compiler.get_supported_arguments(warning_flags)
 add_project_arguments(warning_flags, language: 'cpp')
 
 subdir('tools/extra_defs_gen')
+subdir('MSVC_NMake/gendef')
 subdir('pango')
 subdir('docs/reference')
 subdir('MSVC_NMake/pangomm')
diff --git a/pango/pangomm/meson.build b/pango/pangomm/meson.build
index 16c4f92..7c70b60 100644
--- a/pango/pangomm/meson.build
+++ b/pango/pangomm/meson.build
@@ -159,11 +159,38 @@ else # not maintainer_mode
   endforeach
 
   extra_include_dirs = [ '..', '..' / '..' / 'untracked' / 'pango' ]
-  pangomm_library = library(pangomm_pcname,
+
+  # We need this so that we can run gendef.exe to get the .def file
+  # needed for obtaining the .lib file for the pangomm DLL
+  pango_int_lib = static_library('pangomm-int',
     built_cc_files, extra_cc_files,
-    version: pangomm_libversion,
     include_directories: extra_include_dirs,
+    install: false,)
+
+  pangomm_def = []
+  pangomm_extra_link_args = []
+
+  if is_msvc
+    pangomm_def = custom_target('pangomm.def',
+      output: 'pangomm.def',
+      depends: pango_int_lib,
+      command: [ gendef,
+        '@OUTPUT@',
+               '@0@-@1@.dll'.format(pangomm_pcname,
+                             libtool_soversion[0] - libtool_soversion[2]),
+        pango_int_lib.full_path(),
+      ],
+      install: false,
+    )
+    pangomm_extra_link_args = ['/def:@0@'.format(pangomm_def.full_path())]
+  endif
+
+  pangomm_library = library(pangomm_pcname, pangomm_def,
+    objects: pango_int_lib.extract_all_objects(),
+    version: pangomm_libversion,
     dependencies: pangomm_build_dep,
+    link_depends: pangomm_def,
+    link_args: pangomm_extra_link_args,
     install: true,
   )
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]