[dbi]: allow to build without mongodb

The tests won't be build as they depend on mongodb.
To build without mongodb do

meson configure -Dmongodb=false
This commit is contained in:
Alexander Couzens 2022-09-11 20:43:57 +02:00
parent 0accea361c
commit d973dc1eea
4 changed files with 69 additions and 7 deletions

View File

@ -16,6 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
libdbi_conf = configuration_data()
libdbi_deps = [libcrypt_dep]
dbi_sources = files('''
ogs-dbi.h
@ -31,6 +32,11 @@ mongo_sources = files('''
mongo/ims.c
'''.split())
without_mongo_sources = files('''
mongo/dummy.c
mongo/ogs-mongoc.h
'''.split())
json_sources = files('''
json/json.c
external/cjson/cJSON.c
@ -38,10 +44,16 @@ json_sources = files('''
libdbi_sources += [json_sources]
cjson_inc = include_directories('./external/')
libmongoc_dep = dependency('libmongoc-1.0', required: true)
if libmongoc_dep.found()
libdbi_conf.set('WITH_MONGOC', 1)
libdbi_sources += [mongo_sources]
mongodb_optval = get_option('mongodb')
if mongodb_optval
libmongoc_dep = dependency('libmongoc-1.0', required: true)
if libmongoc_dep.found()
libdbi_conf.set('WITH_MONGOC', 1)
libdbi_sources += [mongo_sources]
libdbi_deps += [libmongoc_dep]
endif
else
libdbi_sources += [without_mongo_sources]
endif
configure_file(output : 'dbi-config-private.h', configuration : libdbi_conf)
@ -60,10 +72,10 @@ libdbi = library('ogsdbi',
version : libogslib_version,
c_args : dbi_cc_flags,
include_directories : [libdbi_inc, libinc, cjson_inc],
dependencies : [libcrypt_dep, libmongoc_dep],
dependencies : libdbi_deps,
install : true)
libdbi_dep = declare_dependency(
link_with : libdbi,
include_directories : [libdbi_inc, libinc],
dependencies : [libcrypt_dep, libmongoc_dep])
dependencies : libdbi_deps)

48
lib/dbi/mongo/dummy.c Normal file
View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* Author: Alexander Couzens <lynxis@fe80.eu>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* This file will be used when build without mongodb support to support the old api */
#include "ogs-dbi.h"
int ogs_dbi_init(const char *db_uri)
{
return -ENODEV;
}
int ogs_dbi_mongo_init(const char *db_uri)
{
return -ENODEV;
}
int ogs_mongoc_init(const char *db_uri)
{
return -ENODEV;
}
void ogs_mongoc_final(void)
{
}
ogs_mongoc_t *ogs_mongoc(void)
{
return NULL;
}

View File

@ -120,7 +120,8 @@ subdir('lib')
subdir('src')
subdir('misc')
# Don't build the tests unless we can run them (either natively or in an exe wrapper)
build_tests = not meson.is_cross_build() or (meson.is_cross_build() and meson.has_exe_wrapper())
# tests also depend on mongodb
build_tests = get_option('mongodb') and (not meson.is_cross_build() or (meson.is_cross_build() and meson.has_exe_wrapper()))
if build_tests
subdir('tests')
endif

View File

@ -1 +1,2 @@
option('metrics_impl', type : 'combo', choices : ['void', 'prometheus'], value : 'void', description : 'libogsmetrics implementation')
option('mongodb', type : 'boolean', value : 'true', description : 'build with mongodb support')