Fixed meson build thanks to @ninjaoflight

This commit is contained in:
Pierre Proske 2023-02-14 10:34:48 +11:00
parent 6110463dfe
commit 1eca00cb01

View File

@ -65,6 +65,8 @@ sqlitecpp_deps = [
] ]
## used to override the default sqlitecpp options like cpp standard ## used to override the default sqlitecpp options like cpp standard
sqlitecpp_opts = [] sqlitecpp_opts = []
## used to set required macros when using sqlitecpp
sqlitecpp_dep_args = []
## tests ## tests
@ -97,11 +99,6 @@ if host_machine.system() == 'windows'
sqlitecpp_opts += [ sqlitecpp_opts += [
'cpp_std=c++14', 'cpp_std=c++14',
] ]
# check that we are not trying to build as dynamic library
if get_option('default_library') != 'shared'
message('warning: SQLiteCpp does not support shared library on Windows, the library will be built as static')
endif
endif endif
# Options relative to SQLite and SQLiteC++ functions # Options relative to SQLite and SQLiteC++ functions
@ -199,33 +196,36 @@ if get_option('b_coverage')
] ]
endif endif
## Workarround for windows: if building on windows we will build the library as static sqlitecpp_static_args = sqlitecpp_args
if host_machine.system() == 'windows' sqlitecpp_static_dep_args = sqlitecpp_dep_args
libsqlitecpp = static_library( # if windows and shared library
'sqlitecpp', if host_machine.system() == 'windows' and get_option('default_library') == 'shared'
sqlitecpp_srcs, # compile with SQLITECPP_COMPILE_DLL and SQLITECPP_DLL_EXPORT=1
include_directories: sqlitecpp_incl, sqlitecpp_args += [
cpp_args: sqlitecpp_args, '-DSQLITECPP_COMPILE_DLL',
dependencies: sqlitecpp_deps, '-DSQLITECPP_DLL_EXPORT',
# override the default options ]
override_options: sqlitecpp_opts,) sqlitecpp_dep_args += [
else # we just need to define SQLITECPP_COMPILE_DLL
libsqlitecpp = library( '-DSQLITECPP_COMPILE_DLL',
'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 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') if get_option('SQLITECPP_BUILD_TESTS')
# for the unit tests we need to link against a static version of SQLiteCpp # 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' if get_option('default_library') == 'static'
# we do not need to recomplile the library # we do not need to recomplile the library
libsqlitecpp_static = libsqlitecpp libsqlitecpp_static = libsqlitecpp
else else
@ -233,7 +233,7 @@ if get_option('SQLITECPP_BUILD_TESTS')
'sqlitecpp_static', 'sqlitecpp_static',
sqlitecpp_srcs, sqlitecpp_srcs,
include_directories: sqlitecpp_incl, include_directories: sqlitecpp_incl,
cpp_args: sqlitecpp_args, cpp_args: sqlitecpp_static_args,
dependencies: sqlitecpp_deps, dependencies: sqlitecpp_deps,
# override the default options # override the default options
override_options: sqlitecpp_opts,) override_options: sqlitecpp_opts,)
@ -247,13 +247,14 @@ install_subdir(
sqlitecpp_dep = declare_dependency( sqlitecpp_dep = declare_dependency(
include_directories: sqlitecpp_incl, include_directories: sqlitecpp_incl,
link_with: libsqlitecpp, link_with: libsqlitecpp,
compile_args: sqlitecpp_dep_args,
) )
if get_option('SQLITECPP_BUILD_TESTS') if get_option('SQLITECPP_BUILD_TESTS')
## make the dependency static so the unit tests can link against it ## make the dependency static so the unit tests can link against it
## (mainly for windows as the symbols are not exported by default)
sqlitecpp_static_dep = declare_dependency( sqlitecpp_static_dep = declare_dependency(
include_directories: sqlitecpp_incl, include_directories: sqlitecpp_incl,
link_with: libsqlitecpp_static, link_with: libsqlitecpp_static,
compile_args: sqlitecpp_static_dep_args,
) )
endif endif
@ -264,7 +265,7 @@ if get_option('SQLITECPP_BUILD_TESTS')
fallback: ['gtest', 'gtest_main_dep']) fallback: ['gtest', 'gtest_main_dep'])
sqlitecpp_test_dependencies = [ sqlitecpp_test_dependencies = [
gtest_dep, gtest_dep,
sqlitecpp_static_dep, sqlitecpp_dep,
sqlite3_dep, sqlite3_dep,
] ]