Unverified Commit ba743da7 authored by Kip's avatar Kip Committed by GitHub

Merge pull request #890 from Tachi107/meson-improvements-library-pkgconf

Meson improvements
parents 4674fd85 1b04c2dc
......@@ -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
......
# Source: https://github.com/llvm-mirror/llvm/blob/master/cmake/modules/CheckAtomic.cmake
# atomic builtins are required for threading support.
INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckLibraryExists)
# Sometimes linking against libatomic is required for atomic ops, if
# the platform doesn't support lock-free atomics.
function(check_working_cxx_atomics varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<int> x;
int main() {
return x;
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics)
function(check_working_cxx_atomics64 varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x (0);
int main() {
uint64_t i = x.load(std::memory_order_relaxed);
return 0;
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics64)
# This isn't necessary on MSVC, so avoid command-line switch annoyance
# by only running on GCC-like hosts.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
# First check if atomics work without the library.
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
# If not, check if the library exists, and atomics work with it.
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
if( HAVE_LIBATOMIC )
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)
if (NOT HAVE_CXX_ATOMICS_WITH_LIB)
message(FATAL_ERROR "Host compiler must support std::atomic!")
endif()
else()
message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
endif()
endif()
endif()
# Check for 64 bit atomic operations.
if(MSVC)
set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
else()
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
endif()
# If not, check if the library exists, and atomics work with it.
if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
if(HAVE_CXX_LIBATOMICS64)
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!")
endif()
else()
message(FATAL_ERROR "Host compiler appears to require libatomic for 64-bit operations, but cannot find it.")
endif()
endif()
......@@ -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
......
......@@ -28,7 +28,8 @@ Depends:
${misc:Depends},
pkg-config (>= 0.28),
libpistache0 (= ${binary:Version}),
libssl-dev
libssl-dev,
rapidjson-dev (>= 1.1.0)
Description: elegant C++ REST framework
Pistache is a C++ REST framework originally written by Mathieu Stefani at
Datacratic, since maintained by other volunteers. It is written in pure C++14
......
......@@ -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
prefix = get_option('prefix')
configure_file(input: 'version.h.in', output: 'version.h', configuration: version_data_conf, install: get_option('PISTACHE_INSTALL'), install_dir: prefix/get_option('includedir')/'pistache')
install_headers([
......
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libpistache
URL: http://pistache.io/
Description: An elegant C++ REST framework.
Version: @version@
Libs: -L'${libdir}/' @libs@
Libs.private: @libs_private@
Cflags: -I'${includedir}/'
......@@ -15,9 +15,6 @@ project(
compiler = meson.get_compiler('cpp')
compiler_id = compiler.get_id()
prefix = get_option('prefix')
pc_lib = '-lpistache'
pc_libs_private = ['-pthread']
# Wrapping arguments inside a call to get_supported_arguments so that only supported arguments get applied
# No need for -Wall -Wextra -Wpedantic, since warning_level is 3
......@@ -28,49 +25,10 @@ if get_option('b_coverage')
add_project_arguments(compiler.get_supported_arguments(['-fstack-protector-all', '--param=ssp-buffer-size=4']), language: 'cpp')
endif
##### BEGIN CheckAtomic.cmake
is_libatomic_needed = false
cxx_atomics_check_code = '''
#include <atomic>
std::atomic<int> x;
int main(){return x;}
'''
has_working_cxx_atomics = compiler.compiles(cxx_atomics_check_code, name: 'std::atomic')
if (compiler_id.contains('clang') or compiler_id.contains('gcc')) and not has_working_cxx_atomics
assert(compiler.has_function('__atomic_fetch_add_4', args: '-latomic'), 'Host compiler appears to require libatomic, but cannot find it.')
has_working_cxx_atomics = compiler.compiles(cxx_atomics_check_code, args: '-latomic', name: 'std::atomic with libatomic')
assert(has_working_cxx_atomics, 'Host compiler must support std::atomic!')
is_libatomic_needed = true
endif
cxx_atomics64_check_code = '''
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x(0);
int main() {
uint64_t i = x.load(std::memory_order_relaxed);
return 0;
}
'''
has_working_cxx_atomics64 = compiler.compiles(cxx_atomics64_check_code, name: 'std::atomic<uint64_t>')
if not has_working_cxx_atomics64
assert(compiler.has_function('__atomic_load_8', args: '-latomic'), 'Host compiler appears to require libatomic for 64-bit operations, but cannot find it.')
has_working_cxx_atomics = compiler.compiles(cxx_atomics_check_code, args: '-latomic', name: 'std::atomic<uint64_t> with libatomic')
assert(has_working_cxx_atomics, 'Host compiler must support 64-bit std::atomic')
is_libatomic_needed = true
endif
##### END CheckAtomic.cmake
if is_libatomic_needed
pc_libs_private += '-latomic'
endif
deps_libpistache = [dependency('threads'), dependency('RapidJSON', fallback: ['rapidjson', 'rapidjson_dep'])]
if get_option('PISTACHE_USE_SSL')
deps_libpistache += dependency('openssl')
pc_libs_private += ['-lssl', '-lcrypto']
endif
version_data_raw = ''
......@@ -94,16 +52,6 @@ endforeach
pistache_version_str = '.'.join([version_data_conf.get_unquoted('VERSION_MAJOR'), version_data_conf.get_unquoted('VERSION_MINOR'), version_data_conf.get_unquoted('VERSION_PATCH')])
pistache_soversion_str = '.'.join([version_data_conf.get_unquoted('SONAME_VERSION_MAJOR'), version_data_conf.get_unquoted('SONAME_VERSION_MINOR')])
configure_file(input: 'libpistache.pc.in', output: 'libpistache.pc', install: get_option('PISTACHE_INSTALL'), install_dir: get_option('libdir')/'pkgconfig', configuration: {
'prefix': prefix,
'exec_prefix': prefix/get_option('bindir'),
'libdir': prefix/get_option('libdir'),
'libs': pc_lib,
'libs_private': ' '.join(pc_libs_private),
'includedir': prefix/get_option('includedir'),
'version': pistache_version_str+'-git'+version_data_conf.get_unquoted('VERSION_GIT_DATE')
})
incl_pistache = include_directories('include')
subdir('include')
......
......@@ -31,29 +31,29 @@ 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
pkg = import('pkgconfig')
pkg.generate(
libpistache,
name: 'Pistache',
description: 'An elegant C++ REST framework.',
url: 'http://pistache.io',
version: pistache_version_str+'-git'+version_data_conf.get_unquoted('VERSION_GIT_DATE'),
filebase: 'libpistache'
)
......@@ -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