From 80b46bd62dab4114636ad4f316b5fb404c72aef0 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 --- 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 07c1b9f4a..a2885d603 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ option( CPP-NETLIB_BUILD_TESTS "Build the cpp-netlib project tests." ON) # option( CPP-NETLIB_BUILD_EXPERIMENTS "Build the cpp-netlib project experiments." 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) @@ -37,8 +39,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) @@ -65,6 +69,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 6d5fbb0d6..cadf86883 100644 --- a/libs/network/src/CMakeLists.txt +++ b/libs/network/src/CMakeLists.txt @@ -45,6 +45,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 () if (MINGW) target_link_libraries(cppnetlib-client-connections ws2_32)