From bd2e1c6087686b1fab147bbc60e46335c1ce641a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Guzm=C3=A1n?= Date: Thu, 8 Dec 2022 22:17:17 -0600 Subject: [PATCH] [Meson] build library as static on windows as dynamic linking is not supported on windows we can give a warning and compile the library as static itself --- meson.build | 55 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/meson.build b/meson.build index 9c3bab0..9b3ba42 100644 --- a/meson.build +++ b/meson.build @@ -93,6 +93,11 @@ if host_machine.system() == 'windows' sqlitecpp_opts += [ 'cpp_std=c++14', ] + # check that we are not trying to build as dynamic library + if get_option('default_library') != 'shared' + warming('SQLiteCpp does not support shared library on Windows, the library will be built as static') + endif + endif # Options relative to SQLite and SQLiteC++ functions @@ -139,29 +144,45 @@ if get_option('b_coverage') ] endif - -libsqlitecpp = library( - 'sqlitecpp', - sqlitecpp_srcs, - include_directories: sqlitecpp_incl, - cpp_args: sqlitecpp_args, - dependencies: sqlitecpp_deps, - # override the default options - override_options: sqlitecpp_opts, - # install: true, - # API version for SQLiteCpp shared library. - version: '0',) -if get_option('SQLITECPP_BUILD_TESTS') - # for the unit tests we need to link against a static version of SQLiteCpp - libsqlitecpp_static = static_library( - 'sqlitecpp_static', +## Workarround for windows: if building on windows we will build the library as static +if host_machine.system() == 'windows' + libsqlitecpp = static_library( + 'sqlitecpp', sqlitecpp_srcs, include_directories: sqlitecpp_incl, cpp_args: sqlitecpp_args, dependencies: sqlitecpp_deps, # override the default options override_options: sqlitecpp_opts,) - # static libraries do not have a version +else + libsqlitecpp = library( + 'sqlitecpp', + sqlitecpp_srcs, + include_directories: sqlitecpp_incl, + cpp_args: sqlitecpp_args, + dependencies: sqlitecpp_deps, + # override the default options + override_options: sqlitecpp_opts, + # install: true, + # API version for SQLiteCpp shared library. + version: '0',) +endif + +if get_option('SQLITECPP_BUILD_TESTS') + # for the unit tests we need to link against a static version of SQLiteCpp + if host_machine.system() == 'windows' or get_option('default_library') == 'static' + # we do not need to recomplile the library + libsqlitecpp_static = libsqlitecpp + else + libsqlitecpp_static = static_library( + 'sqlitecpp_static', + sqlitecpp_srcs, + include_directories: sqlitecpp_incl, + cpp_args: sqlitecpp_args, + dependencies: sqlitecpp_deps, + # override the default options + override_options: sqlitecpp_opts,) + endif endif install_subdir(