project( 'SQLiteCpp', 'cpp', # SQLiteCpp supports C++11 # however newer versions of gtest requires C++14 default_options: ['cpp_std=c++14', 'warning_level=3'], license: 'MIT', version: '3.3.3', ) cxx = meson.get_compiler('cpp') cpp_std = get_option('cpp_std') ## at best we might try to test if this code compiles ## testing for compilers or platforms is not reliable enough ## example: native clang on windows or mingw in windows unix_like_code = ''' #if defined(unix) || defined(__unix__) || defined(__unix) // do nothing #else # error "Non Unix-like OS" #endif ''' unix_like = cxx.compiles(unix_like_code, name : 'unix like environment') mingw_64_env_code = ''' #if defined(__MINGW64__) // do nothing #else # error "Non MinGW-W64 environment" #endif ''' mingw_64_env = cxx.compiles(mingw_64_env_code, name : 'MinGW-W64 environment') thread_dep = dependency('threads') # sqlite3 support sqlite3_dep = dependency( 'sqlite3', fallback: ['sqlite3', 'sqlite3_dep'] ) sqlitecpp_incl = [ include_directories('include') ] sqlitecpp_srcs = files( 'src/Backup.cpp', 'src/Column.cpp', 'src/Database.cpp', 'src/Exception.cpp', 'src/Savepoint.cpp', 'src/Statement.cpp', 'src/Transaction.cpp', ) sqlitecpp_args = cxx.get_supported_arguments( # included in meson by default # -Wall # included when warning_level=3 #'-Wextra', #'-Wpedantic', '-Wswitch-enum', '-Wshadow', '-Wno-long-long', '-Wno-attributes', ) sqlitecpp_link = [] sqlitecpp_deps = [ sqlite3_dep, thread_dep, ] ## used to override the default sqlitecpp options like cpp standard sqlitecpp_opts = [] ## used to set required macros when using sqlitecpp sqlitecpp_dep_args = [] ## tests sqlitecpp_test_srcs = files( 'tests/Column_test.cpp', 'tests/Database_test.cpp', 'tests/Savepoint_test.cpp', 'tests/Statement_test.cpp', 'tests/Backup_test.cpp', 'tests/Transaction_test.cpp', 'tests/VariadicBind_test.cpp', 'tests/Exception_test.cpp', 'tests/ExecuteMany_test.cpp', ) sqlitecpp_test_args = [] ## using MSVC headers requires c++14, if not will show an error on xstddef as: ## 'auto' return without trailing return type; deduced return types are a C++14 extension if host_machine.system() == 'windows' ## check if the std version is less than c++14 if cpp_std.version_compare(' int main() { sqlite3_enable_load_extension(0, 0); return 0; } ''', name: 'sqlite3_load_extension', dependencies: [sqlite3_dep]) if not sqlite3_load_extension_support message('warning: Detected bundled SQLite3 in OSX, but it does not support load extension') message('warning: SQLiteCpp will be built without load extension support') message('warning: You can disable this warning by setting SQLITE_OMIT_LOAD_EXTENSION to false') sqlitecpp_args += ['-DSQLITE_OMIT_LOAD_EXTENSION'] endif endif endif if unix_like sqlitecpp_args += [ # -fPIC is included by default in meson # 'fPIC', ] # add dl dependency libdl_dep = cxx.find_library('dl') sqlitecpp_deps += [ libdl_dep, ] endif if get_option('b_coverage') # Prevent the compiler from removing the unused inline functions so that they get tracked as "non-covered" sqlitecpp_args += [ '-fkeep-inline-functions', '-fkeep-static-functions', ] endif sqlitecpp_static_args = sqlitecpp_args sqlitecpp_static_dep_args = sqlitecpp_dep_args # if windows and shared library if host_machine.system() == 'windows' and get_option('default_library') == 'shared' # compile with SQLITECPP_COMPILE_DLL and SQLITECPP_DLL_EXPORT=1 sqlitecpp_args += [ '-DSQLITECPP_COMPILE_DLL', '-DSQLITECPP_DLL_EXPORT', ] sqlitecpp_dep_args += [ # we just need to define SQLITECPP_COMPILE_DLL '-DSQLITECPP_COMPILE_DLL', ] 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 if 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_static_args, dependencies: sqlitecpp_deps, # override the default options override_options: sqlitecpp_opts,) endif endif install_subdir( 'include/SQLiteCpp', install_dir: get_option('includedir')) sqlitecpp_dep = declare_dependency( include_directories: sqlitecpp_incl, link_with: libsqlitecpp, compile_args: sqlitecpp_dep_args, ) if get_option('SQLITECPP_BUILD_TESTS') ## 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( include_directories: sqlitecpp_incl, link_with: libsqlitecpp_static, compile_args: sqlitecpp_static_dep_args, ) endif if get_option('SQLITECPP_BUILD_TESTS') gtest_dep = dependency( 'gtest', main : true, fallback: ['gtest', 'gtest_main_dep']) # check for the current version of gtest as newer versions require newer C++ standards if gtest_dep.found() gtest_version = gtest_dep.version() minimum_standard = 'none' required_std_format = 'current Gtest version requires at least @0@, setting the minimum standard to @0@. You can disable this warning by setting cpp_std to @0@ or newer.' ## gtest 1.17.0 requires c++17 while gtest 1.14.0 requires c++14 if gtest_version.version_compare('>=1.17.0') and cpp_std.version_compare('=1.14.0') and cpp_std.version_compare('