Fix default library detection in Meson

Previously there was a check that made it possible for the users to
switch between building a static or shared library when using Pistache
as a Meson subproject. Now Meson checks for the desired library type
before defining any build targets, and if somebody wants to only use the
static library it doesn't have to also build the shared one.

Also, code is now way cleaner, since the two calls to static_library and
shared_library are now a single library() call
parent 4674fd85
......@@ -269,9 +269,10 @@ before_script:
-DPISTACHE_BUILD_EXAMPLES=true
-DPISTACHE_USE_SSL=false
# Meson release build
# Meson release build, both libs
- meson setup meson_build_release
--buildtype=release
--default-library=both
-DPISTACHE_USE_SSL=true
# CMake debug build
......
......@@ -139,7 +139,7 @@ executable(
If you're using a Meson version older than 0.55.0 you'll have to use the "older" syntax for `depependecy()`:
```meson
dependencies: dependency('pistache', fallback ['pistache', 'pistache_static_dep'])
dependencies: dependency('pistache', fallback ['pistache', 'pistache_dep'])
```
### CMake
......
......@@ -44,6 +44,7 @@ SOURCE_DIR = $(abspath $(PACKAGE_DIR)/../)
# Configure source...
override_dh_auto_configure:
dh_auto_configure -- \
--default-library=both \
-DPISTACHE_BUILD_EXAMPLES=true \
-DPISTACHE_BUILD_TESTS=true \
-DPISTACHE_ENABLE_NETWORK_TESTS=false \
......
......@@ -8,6 +8,8 @@ pistache_example_files = [
'rest_description'
]
threads_dep = dependency('threads')
foreach example_name : pistache_example_files
executable('run'+example_name, example_name+'.cc', dependencies: pistache_static_dep)
executable('run'+example_name, example_name+'.cc', dependencies: [pistache_dep, threads_dep])
endforeach
......@@ -31,29 +31,19 @@ if get_option('PISTACHE_USE_SSL')
add_project_arguments('-DPISTACHE_USE_SSL', language: 'cpp')
endif
libpistache_static = static_library(
'pistache', pistache_common_src+pistache_server_src+pistache_client_src,
libpistache = library(
'pistache',
sources: pistache_common_src + pistache_server_src + pistache_client_src,
include_directories: incl_pistache,
dependencies: deps_libpistache,
install: get_option('PISTACHE_INSTALL'),
pic: get_option('b_staticpic')
)
libpistache_shared = shared_library(
'pistache', pistache_common_src+pistache_server_src+pistache_client_src,
version: pistache_version_str,
soversion: pistache_soversion_str,
include_directories: incl_pistache,
dependencies: deps_libpistache,
install: get_option('PISTACHE_INSTALL')
pic: get_option('b_staticpic')
)
pistache_static_dep = declare_dependency(link_with: libpistache_static, include_directories: incl_pistache)
pistache_shared_dep = declare_dependency(link_with: libpistache_shared, include_directories: incl_pistache)
pistache_dep = declare_dependency(link_with: libpistache, include_directories: incl_pistache)
if meson.version().version_compare('>=0.54.0')
if get_option('default_library') == 'static'
meson.override_dependency('pistache', pistache_static_dep)
else
meson.override_dependency('pistache', pistache_shared_dep)
endif
meson.override_dependency('pistache', pistache_dep)
endif
......@@ -43,7 +43,7 @@ foreach test_name : pistache_test_files
'run_'+test_name,
test_name+'.cc',
dependencies: [
pistache_shared_dep,
pistache_dep,
gtest_main_dep,
curl_dep
]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment