[gtksourceview/meson.msvc: 1/5] meson: Fix Visual Studio DLL builds



commit 39ef0bf74c8222e4ff5ee6fbc72460c86c33e073
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Apr 24 16:20:14 2019 +0800

    meson: Fix Visual Studio DLL builds
    
    Unfortunately, Visual Studio builds do not really like the concept of
    linking 2 static libraries and not using any sources for building a
    given DLL (it will not include those items when linking the final DLL as
    it will optimize most of the items out as the linker does not believe
    those items are being really used in the final DLL), so we need to do
    the following for the Visual Studio builds:
    
    -Define a separate GtkSourceView shared library target that contain the
     core sources *and* the word completion provider sources, along with the
     generated glib-mkenums and GResource sources.  This is actually how the
     Visual Studio projects build the sources for the GtkSourceView DLL, due
     to the same reasoning.
    
    -Declare the various internal dependencies accordingly; note that we
     still need the static core library for building the test programs.
     This means that on Visual Studio builds we need to build the core
     sources 2 times, it seems that this is unavoidable at this point.
     The build files for the tests in tests/ and testsuite/ has been updated
     accordingly so that things will build and link.  Note that for the
     test-stylescheme test, we need to ensure that we only link to the
     static core library, otherwise it will fail to link.
    
    -Update the enumeration source generating process, so that we include
     config.h during the build and so ensure that the symbols in the
     enumeration sources are properly exported.  This is necessary
     especially for the introspection builds on Visual Studio, as well as
     for the test programs.
    
    -For builds prior to Visual Studio 2013, we must include our math.h so
     that we can have a fallback implementation for round(), which is only
     provided in Visual Studio 2013 and later.

 .../completion-providers/words/meson.build         | 37 ++++++-----
 gtksourceview/meson.build                          | 73 ++++++++++++++++------
 tests/meson.build                                  |  5 +-
 testsuite/meson.build                              |  4 +-
 4 files changed, 81 insertions(+), 38 deletions(-)
---
diff --git a/gtksourceview/completion-providers/words/meson.build 
b/gtksourceview/completion-providers/words/meson.build
index 7e351c3a..75d942b8 100644
--- a/gtksourceview/completion-providers/words/meson.build
+++ b/gtksourceview/completion-providers/words/meson.build
@@ -26,26 +26,29 @@ install_headers(
   )
 )
 
-completionwords_lib = static_library(
-  package_string + 'completionwords',
-  completionwords_public_c,
-  include_directories: rootdir,
-  dependencies: core_dep,
-  c_args: completionwords_c_args,
-  install: false,
-)
+if cc.get_id() != 'msvc'
+  completionwords_lib = static_library(
+    package_string + 'completionwords',
+    completionwords_public_c,
+    include_directories: rootdir,
+    dependencies: core_dep,
+    c_args: completionwords_c_args,
+    install: false,
+  )
 
-gtksource_libs += [
-  completionwords_lib,
-]
+  gtksource_libs += [
+    completionwords_lib,
+  ]
 
-completionwords_dep = declare_dependency(
-  link_with: completionwords_lib,
-  include_directories: rootdir,
-  dependencies: core_dep,
-)
+  completionwords_dep = declare_dependency(
+    link_with: completionwords_lib,
+    include_directories: rootdir,
+    dependencies: core_dep,
+  )
+
+  gtksource_deps += completionwords_dep
 
-gtksource_deps += completionwords_dep
+endif
 
 extra_public_sources += files([
   'gtksourcecompletionwords.c',
diff --git a/gtksourceview/meson.build b/gtksourceview/meson.build
index be74f737..c11433d4 100644
--- a/gtksourceview/meson.build
+++ b/gtksourceview/meson.build
@@ -120,16 +120,24 @@ if config_h.has('OS_OSX')
   ]
 endif
 
-extra_include_dirs = []
 if cc.get_id() == 'msvc'
   # include our math.h to implement round() for pre-2013 Visual Studio
   msvc_maj_ver = cc.version().split('.')[0].to_int()
   if msvc_maj_ver < 18
-    extra_include_dirs = include_directories('../win32')
+    gtksourceview_include_dirs = [rootdir, include_directories('../win32')]
+  else
+    gtksourceview_include_dirs = rootdir
   endif
+else
+  gtksourceview_include_dirs = rootdir
 endif
 
 core_enums_header = '''
+
+#if defined (GTK_SOURCE_COMPILATION) && defined (HAVE_CONFIG_H)
+# include <config.h>
+#endif
+
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 # error "Only <gtksourceview/gtksource.h> can be included directly."
 #endif
@@ -171,19 +179,20 @@ install_headers(
   install_dir: join_paths(pkgincludedir, 'gtksourceview'),
 )
 
+core_enums_h = core_enums.get(1)
+
+# Unfortunately, Visual Studio builds must build the core
+# sources twice, once for the GtkSourceView DLL, and once for
+# the tests (static core lib), so that we can ensure that
+# all the items from the core sources are properly linked into
+# the final GtkSourceView DLL and exported from it.
 core_lib = static_library(package_string + 'core', core_sources,
-  include_directories: [rootdir, extra_include_dirs],
+  include_directories: gtksourceview_include_dirs,
          dependencies: core_deps,
                c_args: core_c_args,
               install: false
 )
 
-gtksource_libs = [
-  core_lib,
-]
-
-core_enums_h = core_enums.get(1)
-
 core_dep = declare_dependency(
             link_with: core_lib,
   include_directories: rootdir,
@@ -195,6 +204,12 @@ gtksource_deps = [
   core_dep,
 ]
 
+# We can't use the static libs on Visual Studio builds
+# to form our DLL here, so we must build all the core
+# and word completion provider sources into the main DLL
+# instead
+gtksource_libs = cc.get_id() == 'msvc' ? [] : [core_lib]
+
 extra_public_sources = []
 
 subdir('completion-providers')
@@ -204,15 +219,34 @@ gtksource_res = gnome.compile_resources(
   'gtksourceview.gresource.xml'
 )
 
-gtksource_lib = shared_library(package_string, gtksource_res,
-                version: lib_version,
-    include_directories: rootdir,
-           dependencies: gtksource_deps,
-             link_whole: gtksource_libs,
-                 c_args: core_c_args,
-                install: true,
-  gnu_symbol_visibility: 'hidden',
-)
+# We can't use the static libs on Visual Studio builds
+# to form our DLL here, so we must build all the core
+# and word completion provider sources into the main DLL
+# instead
+if cc.get_id() == 'msvc'
+  gtksource_word_provider_sources = []
+  foreach s: completionwords_public_c
+    gtksource_word_provider_sources += files(['completion-providers/words/@0@'.format(s)])
+  endforeach
+  gtksource_lib = shared_library(package_string,
+                  [core_sources, gtksource_word_provider_sources, gtksource_res],
+                  version: lib_version,
+      include_directories: gtksourceview_include_dirs,
+             dependencies: core_deps,
+                   c_args: core_c_args,
+                  install: true,
+  )
+else
+  gtksource_lib = shared_library(package_string, gtksource_res,
+                  version: lib_version,
+      include_directories: gtksourceview_include_dirs,
+             dependencies: gtksource_deps,
+               link_whole: gtksource_libs,
+                   c_args: core_c_args,
+                  install: true,
+    gnu_symbol_visibility: 'hidden',
+  )
+endif
 
 gtksource_dep_sources = [
   core_enums_h,
@@ -269,10 +303,11 @@ if generate_gir
   endif
 endif
 
+# MSVC builds: Only link to the dependent packages/.lib's
 gtksource_dep = declare_dependency(
             link_with: gtksource_lib,
   include_directories: rootdir,
-         dependencies: gtksource_deps,
+         dependencies: cc.get_id() == 'msvc' ? core_deps : gtksource_deps,
               sources: gtksource_dep_sources,
 )
 
diff --git a/tests/meson.build b/tests/meson.build
index e1430fbc..eb078ee8 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -27,7 +27,10 @@ foreach test_name, test_sources: tests_sources
     )
   endif
 
+  # MSVC builds: We need items from the main GtkSourceView .lib as
+  # well as the static core lib
   executable('test-@0@'.format(test_name), test_sources,
           c_args: tests_c_args,
-    dependencies: [gtksource_dep])
+    dependencies: cc.get_id() == 'msvc' ? [gtksource_dep, core_dep] : [gtksource_dep],
+  )
 endforeach
diff --git a/testsuite/meson.build b/testsuite/meson.build
index e820a606..5405d9b7 100644
--- a/testsuite/meson.build
+++ b/testsuite/meson.build
@@ -42,9 +42,11 @@ foreach test: testsuite_sources
     '@0@.c'.format(test_name),
   ]
 
+  # MSVC builds: We need to link to the main GtkSourceView .lib except
+  # for test-stylescheme.c, where we must link only to the static core lib
   test_exe = executable(test_name, test_sources,
           c_args: testsuite_c_args,
-    dependencies: [gtksource_dep],
+    dependencies: cc.get_id() == 'msvc' and test_name == 'test-stylescheme' ? [core_dep] : [gtksource_dep],
          install: get_option('install_tests'),
      install_dir: testexecdir
   )


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