Pass the base url as a build option

So with SoapUI I can pass -Dbase_url=http://localhost:8080
This commit is contained in:
King_DuckZ 2020-06-22 19:37:56 +02:00
parent b1376f7379
commit d6a27f814a
5 changed files with 24 additions and 2 deletions

1
meson_options.txt Normal file
View file

@ -0,0 +1 @@
option('base_url', type: 'string', value: 'https://api.originsro.org')

7
src/config.hpp.in Normal file
View file

@ -0,0 +1,7 @@
#pragma once
namespace duck {
constexpr const char g_base_url[] = "@BASE_URL@";
} //namespace duck

View file

@ -1,8 +1,9 @@
#include "oro/api.hpp"
#include "orotool_config.hpp"
#include <iostream>
int main() {
oro::Api oro_api("https://api.originsro.org", "RESTC_CPP", "Testing");
oro::Api oro_api(duck::g_base_url, "RESTC_CPP", "Testing");
auto ping = oro_api.ping();
std::cout << "date: " << ping.first.date << '\n';

View file

@ -5,11 +5,25 @@ restc_cpp_dep = dependency('restc-cpp', version: '>=0.1.1',
],
)
base_url = get_option('base_url').strip()
if not base_url.endswith('/')
base_url = base_url + '/'
endif
conf = configuration_data()
conf.set('BASE_URL', base_url)
project_config_file = configure_file(
input: 'config.hpp.in',
output: meson.project_name() + '_config.hpp',
configuration: conf,
)
executable(meson.project_name(),
'main.cpp',
'oro/datatypes.cpp',
'oro/api.cpp',
'oro/dateconv.cpp',
project_config_file,
install: true,
dependencies: [restc_cpp_dep],
include_directories: date_incdir,

View file

@ -1,5 +1,4 @@
conf = configuration_data()
cpp = meson.get_compiler('cpp')
conf.set('RESTC_CPP_WITH_UNIT_TESTS', get_option('restc_cpp_with_unit_tests') ? 1 : false)