From 34959f44f3ace985f61a9483a4181955150511aa Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 7 Apr 2021 01:58:58 +0200 Subject: [PATCH] support -Ddefault_library=both for windows --- src/meson.build | 50 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/meson.build b/src/meson.build index c9eba7d..b9b70a8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,23 +28,45 @@ libcubescript_src = [ 'lib_str.cc' ] -lib_cxxflags = [ '-DLIBCUBESCRIPT_BUILD' ] -host_system = host_machine.system() +lib_cxxflags = extra_cxxflags + [ '-DLIBCUBESCRIPT_BUILD' ] +dyn_cxxflags = lib_cxxflags -if host_system == 'windows' or host_system == 'cygwin' - if get_option('default_library') != 'static' - lib_cxxflags += '-DLIBCUBESCRIPT_DLL' - endif +lib_incdirs = libcubescript_includes + [include_directories('.')] + +host_system = host_machine.system() +os_uses_dlls = (host_system == 'windows' or host_system == 'cygwin') + +if os_uses_dlls + dyn_cxxflags += '-DLIBCUBESCRIPT_DLL' endif -libcubescript_target = library('cubescript', - libcubescript_src, - include_directories: libcubescript_includes + [include_directories('.')], - cpp_args: extra_cxxflags + lib_cxxflags, - install: true, - pic: true, - version: meson.project_version() -) +if os_uses_dlls and get_option('default_library') == 'both' + # we need a bunch of this nonsense on windows as both_libraries() + # does not work reliably there; since DLLs work like they do, we + # need to compile one set of object files with dllexport and the + # other set without that, and there is no way to tell meson to + # do that other than making two different targets... + libcubescript_static = static_library('cubescript', + libcubescript_src, include_directories: lib_incdirs, + cpp_args: lib_cxxflags, + install: true + ) + libcubescript_dynamic = shared_library('cubescript', + libcubescript_src, include_directories: lib_incdirs, + cpp_args: dyn_cxxflags, + install: true, + version: meson.project_version() + ) + libcubescript_target = libcubescript_dynamic +else + libcubescript_target = library('cubescript', + libcubescript_src, include_directories: lib_incdirs, + cpp_args: dyn_cxxflags, + install: true, + pic: true, + version: meson.project_version() + ) +endif libcubescript = declare_dependency( include_directories: libcubescript_includes,