diff --git a/lib/dbi/meson.build b/lib/dbi/meson.build
index b4e16dd92..d41b8d761 100644
--- a/lib/dbi/meson.build
+++ b/lib/dbi/meson.build
@@ -16,6 +16,7 @@
# along with this program. If not, see .
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)
diff --git a/lib/dbi/mongo/dummy.c b/lib/dbi/mongo/dummy.c
new file mode 100644
index 000000000..9190c52b1
--- /dev/null
+++ b/lib/dbi/mongo/dummy.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2022 by sysmocom - s.f.m.c. GmbH
+ * Author: Alexander Couzens
+ *
+ * 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 .
+ */
+
+/* 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;
+}
+
+
diff --git a/meson.build b/meson.build
index 84670367e..6552d6dbc 100644
--- a/meson.build
+++ b/meson.build
@@ -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
diff --git a/meson_options.txt b/meson_options.txt
index 9350a6b8f..c81c38044 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -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')