From 06e23a7d34ead324d45b00d60bdfa9d0acb9bc2c Mon Sep 17 00:00:00 2001 From: anonimal Date: Sun, 8 Jan 2017 04:22:24 +0000 Subject: [PATCH] Build: allow options to use Boost + OpenSSL static libs cherry-pick'd from 0.13-release --- CMakeLists.txt | 11 +++++++++-- libs/network/src/CMakeLists.txt | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6972594ae..461eead34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,8 @@ option( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF option( CPP-NETLIB_BUILD_TESTS "Build the cpp-netlib project tests." ON) option( CPP-NETLIB_BUILD_EXAMPLES "Build the cpp-netlib project examples." ON) option( CPP-NETLIB_ENABLE_HTTPS "Build cpp-netlib with support for https if OpenSSL is found." ON) +option( CPP-NETLIB_STATIC_OPENSSL "Build cpp-netlib using static OpenSSL" OFF) +option( CPP-NETLIB_STATIC_BOOST "Build cpp-netlib using static Boost" OFF) include(GNUInstallDirs) @@ -36,8 +38,10 @@ else() set(BUILD_SHARED_LIBS OFF) endif() -# Always use Boost's shared libraries. -set(Boost_USE_STATIC_LIBS OFF) +# Use Boost's static libraries +if (CPP-NETLIB_STATIC_BOOST) + set(Boost_USE_STATIC_LIBS ON) +endif() # We need this for all tests to use the dynamic version. add_definitions(-DBOOST_TEST_DYN_LINK) @@ -64,6 +68,9 @@ if (CPP-NETLIB_ENABLE_HTTPS) endif() endif() endif() + if (CPP-NETLIB_STATIC_OPENSSL) + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) + endif() find_package(OpenSSL) endif() diff --git a/libs/network/src/CMakeLists.txt b/libs/network/src/CMakeLists.txt index 0ad880075..44617f827 100644 --- a/libs/network/src/CMakeLists.txt +++ b/libs/network/src/CMakeLists.txt @@ -32,6 +32,11 @@ set_target_properties(cppnetlib-client-connections target_link_libraries(cppnetlib-client-connections ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) if (OPENSSL_FOUND) target_link_libraries(cppnetlib-client-connections ${OPENSSL_LIBRARIES}) + if (CPP-NETLIB_STATIC_OPENSSL) + if (NOT MSVC AND NOT MINGW AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") # dynlinker functions are built into libc on FreeBSD + target_link_libraries(cppnetlib-client-connections "-ldl") + endif() + endif() endif () install(TARGETS cppnetlib-client-connections EXPORT cppnetlibTargets