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



commit e3a70bd8600ff4b269887a1f84e1950234d5ea89
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/filelist.am        |  1 +
 MSVC_NMake/gendef/meson.build |  9 +++++++++
 meson.build                   |  1 +
 pango/pangomm/meson.build     | 32 ++++++++++++++++++++++++++++++--
 4 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/MSVC_NMake/filelist.am b/MSVC_NMake/filelist.am
index 258fede..50aa019 100644
--- a/MSVC_NMake/filelist.am
+++ b/MSVC_NMake/filelist.am
@@ -7,6 +7,7 @@ msvc_nmake_data =               \
        create-lists.bat        \
        detectenv-msvc.mak      \
        gendef/gendef.cc        \
+       gendef/meson.build      \
        generate-msvc.mak       \
        info-msvc.mak           \
        install.mak             \
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 7be9654..295beea 100644
--- a/meson.build
+++ b/meson.build
@@ -202,6 +202,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..4750354 100644
--- a/pango/pangomm/meson.build
+++ b/pango/pangomm/meson.build
@@ -159,11 +159,39 @@ 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,
     dependencies: pangomm_build_dep,
+    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,
+    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]