[pangomm/use-dllexport-2-42: 5/6] meson.build: Build pangomm as a shared lib if possible



commit 5a8dd471635a803f5790c78cc8c4ddac90ab0172
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Mar 11 18:01:42 2020 +0800

    meson.build: Build pangomm as a shared lib if possible
    
    Make the build files directly build pangomm as a shared library on:
    -All non-Visual Studio builds, as we did initially.
    -Visual Studio builds that have the headers generated from their .hg
     counterparts with gmmproc 2.64.3 or later.  gmmproc 2.64.3 has the
     updates that are necessary to have the generated headers contain build
     macros that could be used to export symbols using compiler directives.
     If it is found that an older gmmproc is being used, fall back to use
     gendef.exe, as we did before, by defining PANGOMM_USE_GENDEF.

 meson.build               | 47 ++++++++++++++++++++-------
 pango/pangomm/meson.build | 83 ++++++++++++++++++++++++++++-------------------
 2 files changed, 86 insertions(+), 44 deletions(-)
---
diff --git a/meson.build b/meson.build
index c2ff5d8..7776172 100644
--- a/meson.build
+++ b/meson.build
@@ -91,18 +91,27 @@ pangocairo_dep = dependency('pangocairo', version: pangocairo_req)
 glibmm_req_minor_ver = '4'
 cairomm_req_minor_ver = '0'
 
+glibmm_dep = dependency('glibmm-2.@0@'.format(glibmm_req_minor_ver), version: glibmm_req, required: not 
is_msvc)
+
+# Where to find gmmproc and generate_wrap_init.pl.
+if glibmm_dep.found() and glibmm_dep.type_name() == 'pkgconfig'
+  gmmproc_dir = glibmm_dep.get_pkgconfig_variable('gmmprocdir')
+endif
+
 if is_msvc
   # We must have Visual Studio 2013 or later...
   assert(cpp_compiler.version().split('.')[0].to_int() >= 18, 'Visual Studio 2013 or later is required')
 
   sigc_major_ver = '2'
 
-  glibmm_dep = dependency('glibmm-2.@0@'.format(glibmm_req_minor_ver), required: false, version: glibmm_req)
   if not glibmm_dep.found()
     assert(cpp_compiler.has_header('sigc++-@0@.0/sigc++/sigc++.h'.format(sigc_major_ver)) and 
cpp_compiler.has_header('sigc++-@0@.0/include/sigc++config.h'.format(sigc_major_ver)),
            'sigc++-@0@.x headers are required'.format(sigc_major_ver))
     assert(cpp_compiler.has_header('glibmm-2.@0@/glibmm.h'.format(glibmm_req_minor_ver)) and 
cpp_compiler.has_header('glibmm-2.@0@/include/glibmmconfig.h'.format(glibmm_req_minor_ver)),
            'glibmm-2.@0@ headers are required'.format(glibmm_req_minor_ver))
+
+    # We don't have a pkg-config file for glibmm, so use build options
+    gmmproc_dir = get_option('gmmproc-dir')
   else
     sigc_dep = dependency('', required: false) # glibmm covers for libsigc++ in its pkg-config file
   endif
@@ -138,6 +147,9 @@ if is_msvc
     cairomm_dep = cairomm_dep.found() ? cairomm_dep : 
cpp_compiler.find_library('cairomm-vc@0@0@1@-1_@2@'.format(v.to_string(), debugsuffix, 
cairomm_req_minor_ver), required: false)
   endforeach
 
+  # Check whether we compile pangomm without using gendef
+  build_shared_libs_directly = false
+
   if glibmm_dep.type_name() == 'library'
     warning('Note: Be sure to check that this finds the same libsigc++ .lib your glibmm is linked to')
     sigc_dep = cpp_compiler.find_library('sigc-@0@.0'.format(sigc_major_ver), required: false)
@@ -166,7 +178,6 @@ if is_msvc
   pangomm_build_dep = [glibmm_dep, cairomm_dep, sigc_dep, pangocairo_dep]
 else
   cairomm_req = '>= 1.2.2'
-  glibmm_dep = dependency('glibmm-2.@0@'.format(glibmm_req_minor_ver), version: glibmm_req)
   cairomm_dep = dependency('cairomm-1.@0@'.format(cairomm_req_minor_ver), version: cairomm_req)
   pangomm_build_dep = [glibmm_dep, cairomm_dep, pangocairo_dep]
   pangomm_requires = ' '.join([
@@ -174,6 +185,8 @@ else
     'cairomm-1.@0@'.format(cairomm_req_minor_ver), cairomm_req,
     'pangocairo', pangocairo_req,
   ])
+
+  build_shared_libs_directly = true
 endif
 
 # Some dependencies are required only in maintainer mode and/or if
@@ -185,20 +198,12 @@ doxygen = find_program('doxygen', required: build_documentation)
 dot = find_program('dot', required: build_documentation) # Used by Doxygen
 xsltproc = find_program('xsltproc', required: build_documentation)
 
-# Where to find gmmproc and generate_wrap_init.pl.
-if glibmm_dep.type_name() == 'pkgconfig'
-  gmmproc_dir = glibmm_dep.get_pkgconfig_variable('gmmprocdir')
-else
-  if is_msvc
-    gmmproc_dir = get_option('gmmproc-dir')
-  endif
-endif
-
 script_dir = project_source_root / 'untracked' / 'build_scripts'
 generate_binding = script_dir / 'generate-binding.py'
 doc_reference = script_dir / 'doc-reference.py'
 dist_changelog = script_dir / 'dist-changelog.py'
 dist_build_scripts = script_dir / 'dist-build-scripts.py'
+check_dllexport_usage = script_dir / 'check-dllexport-usage.py'
 dist_cmd = project_source_root / 'tools' / 'dist-cmd.py' # Must be committed to git.
 
 if maintainer_mode and mm_common_get.found()
@@ -212,6 +217,26 @@ warning_flags = []
 
 if is_msvc
   add_project_arguments(cpp_compiler.get_supported_arguments([ '/utf-8', '/wd4828']), language: 'cpp')
+
+  # Check for the first line in a file generated with gmmproc,
+  # to see which gmmproc version was used
+  if maintainer_mode
+    check_gmmproc_ver_cmd = [
+      python3, check_dllexport_usage,
+      '--perl=@0@'.format(perl.path()),
+      '--gmmprocdir=@0@'.format(gmmproc_dir), 
'--file=@0@/pango/src/attributes.hg'.format('/'.join(project_source_root.split('\\')))
+    ]
+  else
+    check_gmmproc_ver_cmd = [
+      python3, check_dllexport_usage,
+      '--file=@0@/untracked/pango/pangomm/attributes.h'.format('/'.join(project_source_root.split('\\')))
+    ]
+  endif
+
+  # Enable __declspec(dllexport) if the pangomm headers generated from the .hg files
+  # were generated using a recent enough gmmproc
+  build_shared_libs_directly = run_command(check_gmmproc_ver_cmd).returncode() == 0
+  message('Using __declspec(dllexport) to build pangomm: @0@'.format(build_shared_libs_directly ? 'YES' : 
'NO'))
 endif
 
 if warning_level == 'min'
diff --git a/pango/pangomm/meson.build b/pango/pangomm/meson.build
index f5898dc..c375b00 100644
--- a/pango/pangomm/meson.build
+++ b/pango/pangomm/meson.build
@@ -65,6 +65,12 @@ install_headers(extra_h_files, subdir: pangomm_pcname / 'pangomm')
 untracked_pangomm = 'untracked' / 'pango' / 'pangomm'
 src_untracked_pangomm = project_source_root / untracked_pangomm
 
+pangomm_cpp_args = [ '-DPANGOMM_BUILD=1' ]
+
+if is_msvc and not build_shared_libs_directly
+  pangomm_cpp_args += '-DPANGOMM_USE_GENDEF'
+endif
+
 if maintainer_mode
 
   # Maintainer mode. Generate .h and .cc files from .hg and .ccg files in ../src.
@@ -122,14 +128,8 @@ if maintainer_mode
 
   extra_include_dirs = ['..']
 
-  # 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_file_targets, built_h_file_targets, extra_cc_files,
-    include_directories: extra_include_dirs,
-    dependencies: pangomm_build_dep,
-    install: false,
-  )
+  pango_gen_sources = built_cc_file_targets
+  pango_built_headers = built_h_file_targets
 
   built_h_cc_dir = meson.current_build_dir()
 
@@ -163,26 +163,50 @@ else # not maintainer_mode
     built_cc_files += src_untracked_pangomm / file + '.cc'
   endforeach
 
+  pango_gen_sources = built_cc_files
+  pango_built_headers = []
+
   extra_include_dirs = [ '..', '..' / '..' / 'untracked' / 'pango' ]
 
-  # We need this so that we can run gendef.exe to get the .def file
+
+  built_h_cc_dir = src_untracked_pangomm
+
+endif
+
+extra_pangomm_objects = []
+
+# Build the .rc file for Windows builds and link to it
+if host_machine.system() == 'windows'
+  windows = import('windows')
+  pangomm_res = windows.compile_resources(pangomm_rc)
+  extra_pangomm_objects += pangomm_res
+endif
+
+if build_shared_libs_directly
+  pangomm_library = library(pangomm_pcname, extra_pangomm_objects,
+    pango_gen_sources, pango_built_headers, extra_cc_files,
+    include_directories: extra_include_dirs,
+    cpp_args: pangomm_cpp_args,
+    version: pangomm_libversion,
+    dependencies: pangomm_build_dep,
+    install: true,
+  )
+else
+  # Building with headers generated from *.hg files with
+  # gmmproc < 2.64.0 on Visual Studio: 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,
+    pango_gen_sources, pango_built_headers, extra_cc_files,
     include_directories: extra_include_dirs,
+    cpp_args: pangomm_cpp_args,
     dependencies: pangomm_build_dep,
     install: false,
   )
 
-  built_h_cc_dir = src_untracked_pangomm
-
-endif
-
-pangomm_def = []
-pangomm_extra_link_args = []
-extra_pangomm_objects = []
+  pangomm_def = []
+  pangomm_extra_link_args = []
 
-if is_msvc
   pangomm_def = custom_target('pangomm.def',
     output: 'pangomm.def',
     depends: pango_int_lib,
@@ -195,24 +219,17 @@ if is_msvc
     install: false,
   )
   pangomm_extra_link_args = ['/def:@0@'.format(pangomm_def.full_path())]
-endif
 
-# Build the .rc file for Windows builds and link to it
-if host_machine.system() == 'windows'
-  windows = import('windows')
-  pangomm_res = windows.compile_resources(pangomm_rc)
-  extra_pangomm_objects += pangomm_res
+  pangomm_library = library(pangomm_pcname, extra_pangomm_objects,
+    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,
+  )
 endif
 
-pangomm_library = library(pangomm_pcname, extra_pangomm_objects,
-  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,
-)
-
 # Install built .h and _p.h files.
 meson.add_install_script(
   python3.path(), generate_binding, 'install_built_h_files',


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