Skip to content

Commit cb7ca74

Browse files
authored
libcpprestsdk: fix building as a static library (microsoft#1344)
On Unix, try to use pkg-config to find OpenSSL. This will automatically find any dependent libraries and put them in the correct order for linking. If pkg-config is not available or system is not UNIX, fallback on current mechanism Signed-off-by: Adam Duskett <[email protected]> [Retrieved (and slightly updated) from: https://git.buildroot.net/buildroot/tree/package/libcpprestsdk/0001-libcpprestsdk-fix-building-as-a-static-library.patch] Signed-off-by: Fabrice Fontaine <[email protected]>
1 parent b94bc32 commit cb7ca74

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Release/cmake/cpprest_find_openssl.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ function(cpprest_find_openssl)
4141
# This should prevent linking against the system provided 0.9.8y
4242
set(_OPENSSL_VERSION "")
4343
endif()
44-
find_package(OpenSSL 1.0.0 REQUIRED)
44+
if(UNIX)
45+
find_package(PkgConfig)
46+
pkg_search_module(OPENSSL openssl)
47+
endif()
48+
if(OPENSSL_FOUND)
49+
target_link_libraries(cpprest PRIVATE ${OPENSSL_LDFLAGS})
50+
else()
51+
find_package(OpenSSL 1.0.0 REQUIRED)
52+
endif()
4553

4654
INCLUDE(CheckCXXSourceCompiles)
4755
set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
@@ -67,4 +75,4 @@ function(cpprest_find_openssl)
6775
# libressl doesn't ship with the cleanup method being used in ws_client_wspp
6876
target_compile_definitions(cpprestsdk_openssl_internal INTERFACE -DCPPREST_NO_SSL_LEAK_SUPPRESS)
6977
endif()
70-
endfunction()
78+
endfunction()

0 commit comments

Comments
 (0)