Skip to content

Commit 3db5d86

Browse files
committed
add basic meson support
1 parent ce6dd9b commit 3db5d86

File tree

5 files changed

+230
-0
lines changed

5 files changed

+230
-0
lines changed

meson.build

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
project(
2+
'SQLiteCpp', 'cpp',
3+
# SQLiteCpp requires C++11 support
4+
default_options: ['cpp_std=c++11'],
5+
license: 'MIT',
6+
version: '3.1.1',
7+
)
8+
9+
cxx = meson.get_compiler('cpp')
10+
11+
## at best we might try to test if this code compiles
12+
## testing for compilers or platforms is not reliable enough
13+
## example: native clang on windows or mingw in windows
14+
unix_like_code = '''
15+
#if defined(unix) || defined(__unix__) || defined(__unix)
16+
// do nothing
17+
#else
18+
# error "Non Unix-like OS"
19+
#endif
20+
'''
21+
unix_like = cxx.compiles(unix_like_code, name : 'unix like environment')
22+
23+
thread_dep = dependency('threads')
24+
# sqlite3 support
25+
sqlite3_dep = dependency(
26+
'sqlite3',
27+
fallback: ['sqlite3', 'sqlite3_dep']
28+
)
29+
30+
sqlitecpp_incl = [
31+
include_directories('include')
32+
]
33+
sqlitecpp_srcs = [
34+
'src/Backup.cpp',
35+
'src/Column.cpp',
36+
'src/Database.cpp',
37+
'src/Exception.cpp',
38+
'src/Statement.cpp',
39+
'src/Transaction.cpp',
40+
]
41+
sqlitecpp_args = [
42+
'-Wall',
43+
]
44+
sqlitecpp_link = []
45+
sqlitecpp_deps = [
46+
sqlite3_dep,
47+
thread_dep,
48+
]
49+
50+
## tests
51+
52+
sqlitecpp_test_srcs = [
53+
'tests/Column_test.cpp',
54+
'tests/Database_test.cpp',
55+
'tests/Statement_test.cpp',
56+
'tests/Backup_test.cpp',
57+
'tests/Transaction_test.cpp',
58+
'tests/VariadicBind_test.cpp',
59+
'tests/Exception_test.cpp',
60+
'tests/ExecuteMany_test.cpp',
61+
]
62+
63+
## samples
64+
65+
sqlitecpp_sample_srcs = [
66+
'examples/example1/main.cpp',
67+
]
68+
69+
# if not using MSVC we need to add this compiler arguments
70+
# for a list of MSVC supported arguments please check:
71+
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically?view=msvc-170
72+
if not (host_machine.system() == 'windows' and cxx.get_id() == 'msvc')
73+
sqlitecpp_args += [
74+
'-Wextra',
75+
'-Wpedantic',
76+
'-Wswitch-enum',
77+
'-Wshadow',
78+
'-Wno-long-long',
79+
]
80+
endif
81+
82+
# Options relative to SQLite and SQLiteC++ functions
83+
84+
if get_option('SQLITE_ENABLE_COLUMN_METADATA')
85+
sqlitecpp_args += [
86+
'-DSQLITE_ENABLE_COLUMN_METADATA',
87+
]
88+
endif
89+
90+
if get_option('SQLITE_ENABLE_ASSERT_HANDLER')
91+
sqlitecpp_args += [
92+
'-DSQLITE_ENABLE_ASSERT_HANDLER',
93+
]
94+
endif
95+
96+
if get_option('SQLITE_HAS_CODEC')
97+
sqlitecpp_args += [
98+
'SQLITE_HAS_CODEC',
99+
]
100+
endif
101+
102+
if get_option('SQLITE_USE_LEGACY_STRUCT')
103+
sqlitecpp_args += [
104+
'-DSQLITE_USE_LEGACY_STRUCT',
105+
]
106+
endif
107+
108+
if unix_like
109+
sqlitecpp_args += [
110+
'-DfPIC',
111+
]
112+
# add dl dependency
113+
libdl_dep = cxx.find_library('dl')
114+
sqlitecpp_deps += [
115+
libdl_dep,
116+
]
117+
endif
118+
119+
if get_option('b_coverage')
120+
# Prevent the compiler from removing the unused inline functions so that they get tracked as "non-covered"
121+
sqlitecpp_args += [
122+
'-fkeep-inline-functions',
123+
'-fkeep-static-functions',
124+
]
125+
endif
126+
127+
128+
libsqlitecpp = library(
129+
'sqlitecpp',
130+
sqlitecpp_srcs,
131+
include_directories: sqlitecpp_incl,
132+
cpp_args: sqlitecpp_args,
133+
dependencies: sqlitecpp_deps,
134+
# install: true,
135+
# API version for SQLiteCpp shared library.
136+
version: '0',
137+
)
138+
139+
install_headers(
140+
'include/SQLiteCpp/SQLiteCpp.h',
141+
'include/SQLiteCpp/Assertion.h',
142+
'include/SQLiteCpp/Backup.h',
143+
'include/SQLiteCpp/Column.h',
144+
'include/SQLiteCpp/Database.h',
145+
'include/SQLiteCpp/Exception.h',
146+
'include/SQLiteCpp/Statement.h',
147+
'include/SQLiteCpp/Transaction.h',
148+
'include/SQLiteCpp/VariadicBind.h',
149+
'include/SQLiteCpp/ExecuteMany.h',
150+
)
151+
152+
sqlitecpp_dep = declare_dependency(
153+
include_directories: sqlitecpp_incl,
154+
link_with: libsqlitecpp,
155+
)
156+
157+
if get_option('SQLITECPP_BUILD_TESTS')
158+
gtest_dep = dependency(
159+
'gtest',
160+
main : true,
161+
fallback: ['gtest', 'gtest_dep'])
162+
sqlitecpp_test_dependencies = [
163+
gtest_dep,
164+
sqlitecpp_dep,
165+
sqlite3_dep,
166+
]
167+
sqlitecpp_test_args = []
168+
169+
testexe = executable('testexe', sqlitecpp_test_srcs,
170+
dependencies: sqlitecpp_test_dependencies)
171+
172+
test_args = []
173+
174+
test('sqlitecpp unit tests', testexe, args: test_args)
175+
endif
176+
if get_option('SQLITECPP_BUILD_EXAMPLES')
177+
## demo executable
178+
sqlitecpp_demo_exe = executable('SQLITECPP_sample_demo',
179+
sqlitecpp_sample_srcs,
180+
dependencies: sqlitecpp_dep)
181+
endif
182+
183+
pkgconfig = import('pkgconfig')
184+
pkgconfig.generate(
185+
libsqlitecpp,
186+
description: 'a smart and easy to use C++ SQLite3 wrapper.',
187+
version: meson.project_version(),
188+
)

meson_options.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Options relative to SQLite and SQLiteC++ functions
2+
## Enable the use of SQLite column metadata and Column::getColumnOriginName() method,
3+
## Require that the sqlite3 library is also compiled with this flag (default under Debian/Ubuntu, but not on Mac OS X).
4+
option('SQLITE_ENABLE_COLUMN_METADATA', type: 'boolean', value: false, description: 'Enable Column::getColumnOriginName(). Require support from sqlite3 library.')
5+
## Enable the user definition of a assertion_failed() handler (default to false, easier to handler for beginners).
6+
option('SQLITE_ENABLE_ASSERT_HANDLER', type: 'boolean', value: false, description: 'Enable the user definition of a assertion_failed() handler.')
7+
## Enable database encryption API. Requires implementations of sqlite3_key & sqlite3_key_v2.
8+
## Eg. SQLCipher (libsqlcipher-dev) is an SQLite extension that provides 256 bit AES encryption of database files.
9+
option('SQLITE_HAS_CODEC', type: 'boolean', value: false, description: 'Enable database encryption API. Not available in the public release of SQLite.')
10+
## Force forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)
11+
option('SQLITE_USE_LEGACY_STRUCT', type: 'boolean', value: false, description: 'Fallback to forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)')
12+
option('SQLITECPP_BUILD_TESTS', type: 'boolean', value: false, description: 'Build SQLiteC++ unit tests.')
13+
option('SQLITECPP_BUILD_EXAMPLES', type: 'boolean', value: false, description: 'Build SQLiteC++ examples.')

subprojects/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ignore everything here
2+
*
3+
# but not the wrap files and the .gitignore
4+
!*.wrap
5+
!*.gitignore

subprojects/gtest.wrap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[wrap-file]
2+
directory = googletest-release-1.11.0
3+
source_url = https://github.com/google/googletest/archive/release-1.11.0.tar.gz
4+
source_filename = gtest-1.11.0.tar.gz
5+
source_hash = b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5
6+
patch_directory = gtest
7+
8+
[provide]
9+
gtest = gtest_dep
10+
gtest_main = gtest_main_dep
11+
gmock = gmock_dep
12+
gmock_main = gmock_main_dep

subprojects/sqlite3.wrap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[wrap-file]
2+
directory = sqlite-amalgamation-3380000
3+
source_url = https://sqlite.org/2022/sqlite-amalgamation-3380000.zip
4+
source_filename = sqlite-amalgamation-3380000.zip
5+
source_hash = e055f6054e97747a135c89e36520c0a423249e8a91c5fc445163f4a6adb20df6
6+
patch_filename = sqlite3_3.38.0-1_patch.zip
7+
patch_url = https://wrapdb.mesonbuild.com/v2/sqlite3_3.38.0-1/get_patch
8+
patch_hash = 49e30bf010ff63ab772d5417885e6905379025ceac80382e292c6dbd3a9da744
9+
10+
[provide]
11+
sqlite3 = sqlite3_dep
12+

0 commit comments

Comments
 (0)