|
| 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 | +) |
0 commit comments