Skip to content

Commit aa2d08f

Browse files
committed
Merge branch 'master' into HEAD
2 parents cccb245 + 8b33dcc commit aa2d08f

24 files changed

+314
-260
lines changed

Release/CMakeLists.txt

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
2-
cmake_minimum_required(VERSION 2.8.12)
2+
cmake_minimum_required(VERSION 3.0)
33
if(POLICY CMP0042)
44
cmake_policy(SET CMP0042 NEW) # use MACOSX_RPATH
55
endif()
6-
project(cpprest)
6+
if(UNIX)
7+
project(cpprest C CXX)
8+
else()
9+
project(cpprest CXX)
10+
endif()
711

812
enable_testing()
913

1014
set(WERROR ON CACHE BOOL "Treat Warnings as Errors.")
1115
set(CPPREST_EXCLUDE_WEBSOCKETS OFF CACHE BOOL "Exclude websockets functionality.")
1216
set(CPPREST_EXCLUDE_COMPRESSION OFF CACHE BOOL "Exclude compression functionality.")
13-
set(CPPREST_EXPORT_DIR lib/cpprest CACHE STRING "Directory to install CMake config files.")
14-
set(CPPREST_EXPORT_NAME cpprest-config CACHE STRING "Name for CMake config file.")
17+
set(CPPREST_EXPORT_DIR lib/cpprestsdk CACHE STRING "Directory to install CMake config files.")
1518
set(CPPREST_INSTALL_HEADERS ON CACHE BOOL "Install header files.")
19+
set(CPPREST_INSTALL ON CACHE BOOL "Add install commands.")
1620

1721
if(IOS OR ANDROID)
1822
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
@@ -172,35 +176,35 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
172176

173177
# These settings can be used by the test targets
174178
set(Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
175-
set(Casablanca_SYSTEM_INCLUDE_DIRS)
176179
set(Casablanca_LIBRARY cpprest)
177180
set(Casablanca_LIBRARIES cpprest)
178181
get_directory_property(PARENT_DIR PARENT_DIRECTORY)
179182
if(NOT PARENT_DIR STREQUAL "")
180183
set(Casablanca_LIBRARIES ${Casablanca_LIBRARIES} PARENT_SCOPE)
181184
endif()
182185

183-
# Everything in the project needs access to the casablanca include directories
184-
include_directories( ${Casablanca_INCLUDE_DIRS})
185-
include_directories(SYSTEM ${Casablanca_SYSTEM_INCLUDE_DIRS})
186-
187186
# Finally, the tests all use the same style declaration to build themselves, so we use a function
188187
function(add_casablanca_test NAME SOURCES_VAR)
189188
add_library(${NAME} ${TEST_LIBRARY_TARGET_TYPE} ${${SOURCES_VAR}})
190189
message("-- Added test library ${NAME}")
191-
if (NOT TEST_LIBRARY_TARGET_TYPE STREQUAL "OBJECT")
190+
if(TEST_LIBRARY_TARGET_TYPE STREQUAL "OBJECT")
191+
foreach(_dep httptest_utilities common_utilities unittestpp cpprest)
192+
target_include_directories(${NAME} PRIVATE $<TARGET_PROPERTY:${_dep},INTERFACE_INCLUDE_DIRECTORIES>)
193+
target_compile_definitions(${NAME} PRIVATE $<TARGET_PROPERTY:${_dep},INTERFACE_COMPILE_DEFINITIONS>)
194+
endforeach()
195+
else()
192196
target_link_libraries(${NAME}
193197
httptest_utilities
194198
common_utilities
195199
unittestpp
196200
cpprest
197201
${ANDROID_STL_FLAGS}
198-
)
202+
)
199203
if (BUILD_SHARED_LIBS)
200204
add_test(NAME ${NAME}
201205
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
202206
COMMAND test_runner $<TARGET_FILE_NAME:${NAME}>
203-
)
207+
)
204208
endif()
205209
endif()
206210
endfunction()
+40-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
function(cpprest_find_boost)
2-
if(Boost_FOUND)
2+
if(TARGET cpprestsdk_boost_internal)
33
return()
44
endif()
55

66
if(IOS)
77
set(IOS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../Build_iOS")
8-
set(Boost_FOUND 1 CACHE INTERNAL "")
9-
set(Boost_FRAMEWORK "-F ${IOS_SOURCE_DIR} -framework boost" CACHE INTERNAL "")
10-
set(Boost_INCLUDE_DIR "$<BUILD_INTERFACE:${IOS_SOURCE_DIR}/boost.framework/Headers>" CACHE INTERNAL "")
8+
set(Boost_LIBRARIES "${IOS_SOURCE_DIR}/boost.framework/boost" CACHE INTERNAL "")
9+
set(Boost_INCLUDE_DIR "${IOS_SOURCE_DIR}/boost.framework/Headers" CACHE INTERNAL "")
1110
elseif(ANDROID)
1211
set(Boost_COMPILER "-clang")
1312
if(ARM)
@@ -24,17 +23,40 @@ function(cpprest_find_boost)
2423
find_package(Boost REQUIRED COMPONENTS system date_time regex)
2524
endif()
2625

27-
set(Boost_FOUND 1 CACHE INTERNAL "")
28-
set(Boost_INCLUDE_DIR ${Boost_INCLUDE_DIR} CACHE INTERNAL "")
29-
set(Boost_LIBRARIES
30-
${Boost_SYSTEM_LIBRARY}
31-
${Boost_THREAD_LIBRARY}
32-
${Boost_ATOMIC_LIBRARY}
33-
${Boost_CHRONO_LIBRARY}
34-
${Boost_RANDOM_LIBRARY}
35-
${Boost_REGEX_LIBRARY}
36-
${Boost_DATE_TIME_LIBRARY}
37-
${Boost_FILESYSTEM_LIBRARY}
38-
${BOOST_FRAMEWORK}
39-
CACHE INTERNAL "")
40-
endfunction()
26+
add_library(cpprestsdk_boost_internal INTERFACE)
27+
if(NOT TARGET Boost::boost)
28+
target_include_directories(cpprestsdk_boost_internal INTERFACE "$<BUILD_INTERFACE:${Boost_INCLUDE_DIR}>")
29+
target_link_libraries(cpprestsdk_boost_internal INTERFACE "$<BUILD_INTERFACE:${Boost_LIBRARIES}>")
30+
else()
31+
if(ANDROID)
32+
target_link_libraries(cpprestsdk_boost_internal INTERFACE
33+
Boost::boost
34+
Boost::random
35+
Boost::system
36+
Boost::thread
37+
Boost::filesystem
38+
Boost::chrono
39+
Boost::atomic
40+
)
41+
elseif(UNIX)
42+
target_link_libraries(cpprestsdk_boost_internal INTERFACE
43+
Boost::boost
44+
Boost::random
45+
Boost::system
46+
Boost::thread
47+
Boost::filesystem
48+
Boost::chrono
49+
Boost::atomic
50+
Boost::date_time
51+
Boost::regex
52+
)
53+
else()
54+
target_link_libraries(cpprestsdk_boost_internal INTERFACE
55+
Boost::boost
56+
Boost::system
57+
Boost::date_time
58+
Boost::regex
59+
)
60+
endif()
61+
endif()
62+
endfunction()
+38-30
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,70 @@
11
function(cpprest_find_openssl)
2-
if(OPENSSL_FOUND)
2+
if(TARGET cpprestsdk_openssl_internal)
33
return()
44
endif()
55

66
if(IOS)
77
set(IOS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../Build_iOS")
8-
set(OPENSSL_FOUND 1 CACHE INTERNAL "")
9-
set(OPENSSL_INCLUDE_DIR "$<BUILD_INTERFACE:${IOS_SOURCE_DIR}/openssl/include>" CACHE INTERNAL "")
8+
9+
set(OPENSSL_INCLUDE_DIR "${IOS_SOURCE_DIR}/openssl/include" CACHE INTERNAL "")
1010
set(OPENSSL_LIBRARIES
1111
"${IOS_SOURCE_DIR}/openssl/lib/libcrypto.a"
1212
"${IOS_SOURCE_DIR}/openssl/lib/libssl.a"
1313
CACHE INTERNAL ""
1414
)
1515
set(_SSL_LEAK_SUPPRESS_AVAILABLE ON CACHE INTERNAL "")
16-
return()
1716
elseif(ANDROID)
18-
set(OPENSSL_FOUND 1 CACHE INTERNAL "")
1917
if(ARM)
20-
set(OPENSSL_INCLUDE_DIR "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/../openssl/armeabi-v7a/include>" CACHE INTERNAL "")
18+
set(OPENSSL_INCLUDE_DIR "${CMAKE_BINARY_DIR}/../openssl/armeabi-v7a/include" CACHE INTERNAL "")
2119
set(OPENSSL_LIBRARIES
2220
"${CMAKE_BINARY_DIR}/../openssl/armeabi-v7a/lib/libssl.a"
2321
"${CMAKE_BINARY_DIR}/../openssl/armeabi-v7a/lib/libcrypto.a"
2422
CACHE INTERNAL ""
2523
)
2624
else()
27-
set(OPENSSL_INCLUDE_DIR "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/../openssl/x86/include>" CACHE INTERNAL "")
25+
set(OPENSSL_INCLUDE_DIR "${CMAKE_BINARY_DIR}/../openssl/x86/include" CACHE INTERNAL "")
2826
set(OPENSSL_LIBRARIES
2927
"${CMAKE_BINARY_DIR}/../openssl/x86/lib/libssl.a"
3028
"${CMAKE_BINARY_DIR}/../openssl/x86/lib/libcrypto.a"
3129
CACHE INTERNAL ""
3230
)
3331
endif()
34-
elseif(APPLE)
35-
if(NOT DEFINED OPENSSL_ROOT_DIR)
36-
# Prefer a homebrew version of OpenSSL over the one in /usr/lib
37-
file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
38-
# Prefer the latest (make the latest one first)
39-
list(REVERSE OPENSSL_ROOT_DIR)
40-
endif()
41-
# This should prevent linking against the system provided 0.9.8y
42-
set(_OPENSSL_VERSION "")
43-
find_package(OpenSSL 1.0.0 REQUIRED)
32+
set(_SSL_LEAK_SUPPRESS_AVAILABLE ON CACHE INTERNAL "")
4433
else()
34+
if(APPLE)
35+
if(NOT DEFINED OPENSSL_ROOT_DIR)
36+
# Prefer a homebrew version of OpenSSL over the one in /usr/lib
37+
file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
38+
# Prefer the latest (make the latest one first)
39+
list(REVERSE OPENSSL_ROOT_DIR)
40+
endif()
41+
# This should prevent linking against the system provided 0.9.8y
42+
set(_OPENSSL_VERSION "")
43+
endif()
4544
find_package(OpenSSL 1.0.0 REQUIRED)
45+
46+
INCLUDE(CheckCXXSourceCompiles)
47+
set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
48+
set(CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}")
49+
CHECK_CXX_SOURCE_COMPILES("
50+
#include <openssl/ssl.h>
51+
int main()
52+
{
53+
::SSL_COMP_free_compression_methods();
54+
}
55+
" _SSL_LEAK_SUPPRESS_AVAILABLE)
4656
endif()
4757

48-
set(OPENSSL_FOUND 1 CACHE INTERNAL "")
49-
set(OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR} CACHE INTERNAL "")
50-
set(OPENSSL_LIBRARIES ${OPENSSL_LIBRARIES} CACHE INTERNAL "")
58+
add_library(cpprestsdk_openssl_internal INTERFACE)
59+
if(TARGET OpenSSL::SSL)
60+
target_link_libraries(cpprestsdk_openssl_internal INTERFACE OpenSSL::SSL)
61+
else()
62+
target_link_libraries(cpprestsdk_openssl_internal INTERFACE "$<BUILD_INTERFACE:${OPENSSL_LIBRARIES}>")
63+
target_include_directories(cpprestsdk_openssl_internal INTERFACE "$<BUILD_INTERFACE:${OPENSSL_INCLUDE_DIR}>")
64+
endif()
5165

52-
INCLUDE(CheckCXXSourceCompiles)
53-
set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
54-
set(CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}")
55-
CHECK_CXX_SOURCE_COMPILES("
56-
#include <openssl/ssl.h>
57-
int main()
58-
{
59-
::SSL_COMP_free_compression_methods();
60-
}
61-
" _SSL_LEAK_SUPPRESS_AVAILABLE)
66+
if (NOT _SSL_LEAK_SUPPRESS_AVAILABLE)
67+
# libressl doesn't ship with the cleanup method being used in ws_client_wspp
68+
target_compile_definitions(cpprestsdk_openssl_internal INTERFACE -DCPPREST_NO_SSL_LEAK_SUPPRESS)
69+
endif()
6270
endfunction()
+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function(cpprest_find_websocketpp)
2-
if(WEBSOCKETPP_FOUND)
2+
if(TARGET cpprestsdk_websocketpp_internal)
33
return()
44
endif()
55

@@ -9,7 +9,17 @@ function(cpprest_find_websocketpp)
99
set(WEBSOCKETPP_INCLUDE_DIR ${WEBSOCKETPP_INCLUDE_DIR} CACHE INTERNAL "")
1010
else()
1111
message("-- websocketpp not found, using the embedded version")
12-
set(WEBSOCKETPP_FOUND 1 CACHE INTERNAL "" FORCE)
1312
set(WEBSOCKETPP_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/libs/websocketpp CACHE INTERNAL "")
1413
endif()
14+
15+
cpprest_find_boost()
16+
cpprest_find_openssl()
17+
18+
add_library(cpprestsdk_websocketpp_internal INTERFACE)
19+
target_include_directories(cpprestsdk_websocketpp_internal INTERFACE "$<BUILD_INTERFACE:${WEBSOCKETPP_INCLUDE_DIR}>")
20+
target_link_libraries(cpprestsdk_websocketpp_internal
21+
INTERFACE
22+
cpprestsdk_boost_internal
23+
cpprestsdk_openssl_internal
24+
)
1525
endfunction()

Release/cmake/cpprest_find_zlib.cmake

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
function(cpprest_find_zlib)
2-
if(ZLIB_FOUND)
2+
if(TARGET cpprestsdk_zlib_internal)
33
return()
44
endif()
55

66
if(APPLE AND NOT IOS)
77
# Prefer the homebrew version of zlib
8-
find_library(ZLIB_LIBRARIES NAMES libz.a PATHS /usr/local/Cellar/zlib/1.2.8/lib NO_DEFAULT_PATH)
8+
find_library(ZLIB_LIBRARY NAMES libz.a PATHS /usr/local/Cellar/zlib/1.2.8/lib NO_DEFAULT_PATH)
99
find_path(ZLIB_INCLUDE_DIRS NAMES zlib.h PATHS /usr/local/Cellar/zlib/1.2.8/include NO_DEFAULT_PATH)
1010

11-
if(NOT ZLIB_LIBRARIES OR NOT ZLIB_INCLUDE_DIRS)
11+
if(NOT ZLIB_LIBRARY OR NOT ZLIB_INCLUDE_DIRS)
1212
find_package(ZLIB REQUIRED)
1313
endif()
1414
else()
1515
find_package(ZLIB REQUIRED)
1616
endif()
1717

18-
set(ZLIB_FOUND 1 CACHE INTERNAL "")
19-
set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS} CACHE INTERNAL "")
20-
set(ZLIB_LIBRARIES ${ZLIB_LIBRARIES} CACHE INTERNAL "")
18+
add_library(cpprestsdk_zlib_internal INTERFACE)
19+
if(TARGET ZLIB::ZLIB)
20+
target_link_libraries(cpprestsdk_zlib_internal INTERFACE ZLIB::ZLIB)
21+
else()
22+
target_link_libraries(cpprestsdk_zlib_internal INTERFACE "$<BUILD_INTERFACE:${ZLIB_LIBRARY}")
23+
target_include_directories(cpprestsdk_zlib_internal INTERFACE "$<BUILD_INTERFACE:${ZLIB_INCLUDE_DIRS}")
24+
endif()
2125
endfunction()
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
include(CMakeFindDependencyMacro)
2+
if(@CPPREST_USES_ZLIB@)
3+
find_dependency(ZLIB)
4+
endif()
5+
6+
if(@CPPREST_USES_OPENSSL@)
7+
find_dependency(OpenSSL)
8+
endif()
9+
10+
if(@CPPREST_USES_BOOST@)
11+
if(UNIX)
12+
find_dependency(Boost COMPONENTS random system thread filesystem chrono atomic date_time regex)
13+
else()
14+
find_dependency(Boost COMPONENTS system date_time regex)
15+
endif()
16+
endif()
17+
include("${CMAKE_CURRENT_LIST_DIR}/cpprestsdk-targets.cmake")

Release/include/cpprest/http_client.h

+27-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class http_client_config
8787
#if !defined(__cplusplus_winrt)
8888
, m_validate_certificates(true)
8989
#endif
90-
, m_set_user_nativehandle_options([](native_handle)->void{})
9190
#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO)
9291
, m_tlsext_sni_enabled(true)
9392
#endif
@@ -312,6 +311,30 @@ class http_client_config
312311
}
313312
#endif
314313

314+
/// <summary>
315+
/// Sets a callback to enable custom setting of platform specific options.
316+
/// </summary>
317+
/// <remarks>
318+
/// The native_handle is the following type depending on the underlying platform:
319+
/// Windows Desktop, WinHTTP - HINTERNET (session)
320+
/// </remarks>
321+
/// <param name="callback">A user callback allowing for customization of the session</param>
322+
void set_nativesessionhandle_options(const std::function<void(native_handle)> &callback)
323+
{
324+
m_set_user_nativesessionhandle_options = callback;
325+
}
326+
327+
/// <summary>
328+
/// Invokes a user's callback to allow for customization of the session.
329+
/// </summary>
330+
/// <remarks>Internal Use Only</remarks>
331+
/// <param name="handle">A internal implementation handle.</param>
332+
void _invoke_nativesessionhandle_options(native_handle handle) const
333+
{
334+
if (m_set_user_nativesessionhandle_options)
335+
m_set_user_nativesessionhandle_options(handle);
336+
}
337+
315338
/// <summary>
316339
/// Sets a callback to enable custom setting of platform specific options.
317340
/// </summary>
@@ -335,7 +358,8 @@ class http_client_config
335358
/// <param name="handle">A internal implementation handle.</param>
336359
void invoke_nativehandle_options(native_handle handle) const
337360
{
338-
m_set_user_nativehandle_options(handle);
361+
if (m_set_user_nativehandle_options)
362+
m_set_user_nativehandle_options(handle);
339363
}
340364

341365
#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO)
@@ -397,6 +421,7 @@ class http_client_config
397421
#endif
398422

399423
std::function<void(native_handle)> m_set_user_nativehandle_options;
424+
std::function<void(native_handle)> m_set_user_nativesessionhandle_options;
400425

401426
#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO)
402427
std::function<void(boost::asio::ssl::context&)> m_ssl_context_callback;

0 commit comments

Comments
 (0)