Unverified Commit 77850dbc authored by Kip's avatar Kip Committed by GitHub

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

Reapply #890
parents 04818887 9cf78480
...@@ -269,9 +269,10 @@ before_script: ...@@ -269,9 +269,10 @@ before_script:
-DPISTACHE_BUILD_EXAMPLES=true -DPISTACHE_BUILD_EXAMPLES=true
-DPISTACHE_USE_SSL=false -DPISTACHE_USE_SSL=false
# Meson release build # Meson release build, both libs
- meson setup meson_build_release - meson setup meson_build_release
--buildtype=release --buildtype=release
--default-library=both
-DPISTACHE_USE_SSL=true -DPISTACHE_USE_SSL=true
# CMake debug build # CMake debug build
......
...@@ -14,9 +14,6 @@ project (pistache ...@@ -14,9 +14,6 @@ project (pistache
include(GNUInstallDirs) include(GNUInstallDirs)
add_compile_options(-Wall -Wconversion -pedantic -Wextra -Wno-missing-field-initializers) add_compile_options(-Wall -Wconversion -pedantic -Wextra -Wno-missing-field-initializers)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
include(CheckAtomic)
option(BUILD_SHARED_LIBS "build shared library" ON) option(BUILD_SHARED_LIBS "build shared library" ON)
option(PISTACHE_BUILD_TESTS "build tests alongside the project" OFF) option(PISTACHE_BUILD_TESTS "build tests alongside the project" OFF)
......
# 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( ...@@ -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()`: If you're using a Meson version older than 0.55.0 you'll have to use the "older" syntax for `depependecy()`:
```meson ```meson
dependencies: dependency('pistache', fallback ['pistache', 'pistache_static_dep']) dependencies: dependency('pistache', fallback ['pistache', 'pistache_dep'])
``` ```
### CMake ### CMake
......
...@@ -28,7 +28,8 @@ Depends: ...@@ -28,7 +28,8 @@ Depends:
${misc:Depends}, ${misc:Depends},
pkg-config (>= 0.28), pkg-config (>= 0.28),
libpistache0 (= ${binary:Version}), libpistache0 (= ${binary:Version}),
libssl-dev libssl-dev,
rapidjson-dev (>= 1.1.0)
Description: elegant C++ REST framework Description: elegant C++ REST framework
Pistache is a C++ REST framework originally written by Mathieu Stefani at 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 Datacratic, since maintained by other volunteers. It is written in pure C++14
......
...@@ -44,6 +44,7 @@ SOURCE_DIR = $(abspath $(PACKAGE_DIR)/../) ...@@ -44,6 +44,7 @@ SOURCE_DIR = $(abspath $(PACKAGE_DIR)/../)
# Configure source... # Configure source...
override_dh_auto_configure: override_dh_auto_configure:
dh_auto_configure -- \ dh_auto_configure -- \
--default-library=both \
-DPISTACHE_BUILD_EXAMPLES=true \ -DPISTACHE_BUILD_EXAMPLES=true \
-DPISTACHE_BUILD_TESTS=true \ -DPISTACHE_BUILD_TESTS=true \
-DPISTACHE_ENABLE_NETWORK_TESTS=false \ -DPISTACHE_ENABLE_NETWORK_TESTS=false \
......
...@@ -8,6 +8,8 @@ pistache_example_files = [ ...@@ -8,6 +8,8 @@ pistache_example_files = [
'rest_description' 'rest_description'
] ]
threads_dep = dependency('threads')
foreach example_name : pistache_example_files 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 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') 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([ 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}/'
...@@ -14,10 +14,6 @@ project( ...@@ -14,10 +14,6 @@ project(
) )
compiler = meson.get_compiler('cpp') 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 # 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 # No need for -Wall -Wextra -Wpedantic, since warning_level is 3
...@@ -28,49 +24,10 @@ if get_option('b_coverage') ...@@ -28,49 +24,10 @@ if get_option('b_coverage')
add_project_arguments(compiler.get_supported_arguments(['-fstack-protector-all', '--param=ssp-buffer-size=4']), language: 'cpp') add_project_arguments(compiler.get_supported_arguments(['-fstack-protector-all', '--param=ssp-buffer-size=4']), language: 'cpp')
endif 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'])] deps_libpistache = [dependency('threads'), dependency('RapidJSON', fallback: ['rapidjson', 'rapidjson_dep'])]
if get_option('PISTACHE_USE_SSL') if get_option('PISTACHE_USE_SSL')
deps_libpistache += dependency('openssl') deps_libpistache += dependency('openssl')
pc_libs_private += ['-lssl', '-lcrypto']
endif endif
version_data_raw = '' version_data_raw = ''
...@@ -94,16 +51,6 @@ endforeach ...@@ -94,16 +51,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_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')]) 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') incl_pistache = include_directories('include')
subdir('include') subdir('include')
......
...@@ -31,29 +31,29 @@ if get_option('PISTACHE_USE_SSL') ...@@ -31,29 +31,29 @@ if get_option('PISTACHE_USE_SSL')
add_project_arguments('-DPISTACHE_USE_SSL', language: 'cpp') add_project_arguments('-DPISTACHE_USE_SSL', language: 'cpp')
endif endif
libpistache_static = static_library( libpistache = library(
'pistache', pistache_common_src+pistache_server_src+pistache_client_src, 'pistache',
sources: pistache_common_src + pistache_server_src + pistache_client_src,
include_directories: incl_pistache, include_directories: incl_pistache,
dependencies: deps_libpistache, dependencies: deps_libpistache,
install: get_option('PISTACHE_INSTALL'), 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, version: pistache_version_str,
soversion: pistache_soversion_str, soversion: pistache_soversion_str,
include_directories: incl_pistache, pic: get_option('b_staticpic')
dependencies: deps_libpistache,
install: get_option('PISTACHE_INSTALL')
) )
pistache_static_dep = declare_dependency(link_with: libpistache_static, include_directories: incl_pistache) pistache_dep = declare_dependency(link_with: libpistache, include_directories: incl_pistache)
pistache_shared_dep = declare_dependency(link_with: libpistache_shared, include_directories: incl_pistache)
if meson.version().version_compare('>=0.54.0') if meson.version().version_compare('>=0.54.0')
if get_option('default_library') == 'static' meson.override_dependency('pistache', pistache_dep)
meson.override_dependency('pistache', pistache_static_dep)
else
meson.override_dependency('pistache', pistache_shared_dep)
endif
endif 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 ...@@ -43,7 +43,7 @@ foreach test_name : pistache_test_files
'run_'+test_name, 'run_'+test_name,
test_name+'.cc', test_name+'.cc',
dependencies: [ dependencies: [
pistache_shared_dep, pistache_dep,
gtest_main_dep, gtest_main_dep,
curl_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