Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Release/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(CPPREST_EXPORT_DIR cpprestsdk CACHE STRING "Directory to install CMake confi
option(CPPREST_FORCE_NARROW_STRINGS "Keep strings narrow/UTF8 (even if WIN32)" OFF)
set(CPPREST_INSTALL_HEADERS ON CACHE BOOL "Install header files.")
set(CPPREST_INSTALL ON CACHE BOOL "Add install commands.")
option(CPPREST_ISOLATE_COMPONENTS "Build cpprest components as individual libraries" OFF)

if(IOS OR ANDROID)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
Expand Down Expand Up @@ -235,7 +236,8 @@ if(NOT PARENT_DIR STREQUAL "")
endif()

# Finally, the tests all use the same style declaration to build themselves, so we use a function
function(add_casablanca_test NAME SOURCES_VAR)
# Tests that don't specify IMPLEMENTATION_TARGETS are assumed to depend on whole of cpprest.
function(add_casablanca_test NAME SOURCES_VAR) # [optional] IMPLEMENTATION_TARGETS...
add_library(${NAME} ${TEST_LIBRARY_TARGET_TYPE} ${${SOURCES_VAR}})
message("-- Added test library ${NAME}")
if(TEST_LIBRARY_TARGET_TYPE STREQUAL "OBJECT")
Expand All @@ -244,8 +246,12 @@ function(add_casablanca_test NAME SOURCES_VAR)
target_compile_definitions(${NAME} PRIVATE $<TARGET_PROPERTY:${_dep},INTERFACE_COMPILE_DEFINITIONS>)
endforeach()
else()
set(IMPLEMENTATION_TARGETS cpprest)
if(CPPREST_ISOLATE_COMPONENTS AND ${ARGC} GREATER 2)
set(IMPLEMENTATION_TARGETS ${ARGN})
endif()
target_link_libraries(${NAME} PRIVATE
cpprest
${IMPLEMENTATION_TARGETS}
common_utilities
unittestpp
${ANDROID_LIBS}
Expand Down
1 change: 1 addition & 0 deletions Release/include/cpprest/details/web_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "cpprest/asyncrt_utils.h"
#include "cpprest/uri.h"
#include "pplx/pplxtasks.h"
#include <memory>

namespace web
Expand Down
4 changes: 4 additions & 0 deletions Release/include/pplx/pplxlinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#error This file must not be included for Visual Studio
#endif

#if !defined(_PPLX_H)
#error Include pplx.h instead of pplxlinux.h directly.
#endif

#ifndef _WIN32

#include "cpprest/details/cpprest_compat.h"
Expand Down
4 changes: 4 additions & 0 deletions Release/include/pplx/pplxwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

#pragma once

#if !defined(_PPLX_H)
#error Include pplx.h instead of pplxwin.h directly.
#endif

#if !defined(_WIN32) || _MSC_VER < 1800 || CPPREST_FORCE_PPLX

#include "cpprest/details/cpprest_compat.h"
Expand Down
206 changes: 176 additions & 30 deletions Release/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ set(SOURCES
${HEADERS_PPLX}
${HEADERS_DETAILS}
pch/stdafx.h
json/json.cpp
json/json_parsing.cpp
json/json_serialization.cpp
utilities/asyncrt_utils.cpp
utilities/base64.cpp
utilities/string_utils.cpp
utilities/web_utilities.cpp
)

if(NOT CPPREST_EXCLUDE_HTTP_NARROW_STRING_WIP)
Expand All @@ -45,15 +38,161 @@ LIST(APPEND SOURCES
)
endif()

# Targets for properties common to all cpprestsdk libraries
add_library(cpprest_interface_PUBLIC INTERFACE)
target_include_directories(cpprest_interface_PUBLIC
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)
add_library(cpprest_interface_PRIVATE INTERFACE)
target_include_directories(cpprest_interface_PRIVATE
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/internal>
)

add_library(cpprest ${SOURCES})
target_include_directories(cpprest
PUBLIC
$<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
pch
)
target_link_libraries(cpprest PUBLIC cpprest_interface_PUBLIC PRIVATE cpprest_interface_PRIVATE)
set(CPPREST_TARGETS cpprest cpprest_interface_PUBLIC)
if(NOT BUILD_SHARED_LIBS)
# for installed static libraries the private dependencies must also be
# "installed". As an interface it should not actually impact install.
list(APPEND CPPREST_TARGETS cpprest_interface_PRIVATE)
endif()


## Sub-components

# add_sub_component(name sources...)
# When CPPREST_ISOLATE_COMPONENTS is ON:
# Creates library ${name} using given sources. Then adds respective
# object files to cpprest.
# Otherwise sources are added to cpprest directly.
function(add_sub_component name) # sources...
set(COMPONENT_SOURCES ${ARGN})

# cpprest and this new library inherit these properties publicly.
add_library(${name}_properties_PUBLIC INTERFACE)
target_link_libraries(${name}_properties_PUBLIC INTERFACE cpprest_interface_PUBLIC)
# cpprest and this new library inherit these properties privately.
add_library(${name}_properties_PRIVATE INTERFACE)
target_link_libraries(${name}_properties_PRIVATE INTERFACE cpprest_interface_PRIVATE)

if(CPPREST_ISOLATE_COMPONENTS)
# isolated components are built as OBJECT_LIBRARY so that cpprest library
# may be self contained (apart from external dependencies) and sources are
# still only compiled once.
add_library(${name}_objects OBJECT ${COMPONENT_SOURCES})
# disable pch for isolated builds to ensure dependencies are explict and
# to avoid contamination across components by setting include path to
# reach primitive (ideally empty) stdafx.h.
target_include_directories(${name}_objects
PRIVATE
nopch
)
set_target_properties(${name}_objects PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(${name}_objects PRIVATE ${name}_properties_PUBLIC ${name}_properties_PRIVATE)

# create library of sub-component
add_library(${name} $<TARGET_OBJECTS:${name}_objects>)
target_link_libraries(${name} PUBLIC ${name}_properties_PUBLIC PRIVATE ${name}_properties_PRIVATE)

# connect sources to cpprest (main target)
target_sources(cpprest PRIVATE $<TARGET_OBJECTS:${name}_objects>)
else()
# no isolation, just build sources as part of cpprest
target_sources(cpprest PRIVATE ${COMPONENT_SOURCES})

# do create a dummy interface library for sub-components to specify other
# sub-components in sub_component_link_libraries
add_library(${name} INTERFACE)
# also add to target install list in case there is such use
list(APPEND CPPREST_TARGETS ${name})
endif()

target_link_libraries(cpprest PUBLIC ${name}_properties_PUBLIC PRIVATE ${name}_properties_PRIVATE)

# append public properties (interface) target to install list
# sub-component libraries (isolation build only) are not installed
list(APPEND CPPREST_TARGETS ${name}_properties_PUBLIC)
if(NOT BUILD_SHARED_LIBS)
# for installed static libraries the private dependencies must also be
# "installed". Should be interfaces and not actually impact install.
list(APPEND CPPREST_TARGETS ${name}_properties_PRIVATE)
endif()
set(CPPREST_TARGETS ${CPPREST_TARGETS} PARENT_SCOPE)
endfunction()

# sub_component_sources(name sources...)
# Adds given sources to sub-component library and/or cpprest.
function(sub_component_sources name) # additional sources...
if(CPPREST_ISOLATE_COMPONENTS)
target_sources(${name}_objects ${ARGN})
else()
# no actual sub-component targets built when not isolated; pass along
# sources to cpprest
target_sources(cpprest ${ARGN})
endif()
endfunction()

# sub_component_link_libraries(name link_dependencies...)
# Adds given link_dependencies to sub-component library and/or cpprest.
function(sub_component_link_libraries name) # link dependencies...
if(CPPREST_ISOLATE_COMPONENTS)
target_link_libraries(${name}_objects ${ARGN})
target_link_libraries(${name} ${ARGN})
# remove entries in list that are our own sub-components
# before passing up to cpprest
set(ALL_LINK_ARGS ${ARGN})
foreach(LINK_ARG ${ALL_LINK_ARGS})
if(TARGET ${LINK_ARG}_properties_PRIVATE)
list(REMOVE_ITEM ARGN ${LINK_ARG})
endif()
endforeach()
else()
# no actual sub-component targets built when not isolated
endif()
# pass along dependencies to cpprest in all cases
# (in isolated case only objects are referenced, so dependencies
# need to be passed up too)
target_link_libraries(cpprest ${ARGN})
endfunction()


# Utility components
add_sub_component(cpprest_utility_strings
utilities/string_utils.cpp
)

add_sub_component(cpprest_utility_asyncrt
utilities/asyncrt_utils.cpp
)
sub_component_link_libraries(cpprest_utility_asyncrt PUBLIC cpprest_utility_strings)

add_sub_component(cpprest_utilities
utilities/base64.cpp
utilities/web_utilities.cpp
)
sub_component_link_libraries(cpprest_utilities PUBLIC cpprest_utility_asyncrt cpprest_utility_strings)
if(WIN32 AND NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
sub_component_link_libraries(cpprest_utilities PRIVATE
crypt32.lib
)
endif()

# Json component
add_sub_component(cpprest_json
json/json.cpp
json/json_parsing.cpp
json/json_serialization.cpp
)
sub_component_link_libraries(cpprest_json PUBLIC cpprest_utility_strings)

# Websockets component
if(CPPREST_WEBSOCKETS_IMPL STREQUAL "none")
target_compile_definitions(cpprest PUBLIC -DCPPREST_EXCLUDE_WEBSOCKETS=1)
Expand Down Expand Up @@ -100,35 +239,43 @@ endif()
if(CPPREST_PPLX_IMPL STREQUAL "apple")
find_library(COREFOUNDATION CoreFoundation "/")
find_library(SECURITY Security "/")
target_link_libraries(cpprest PUBLIC ${COREFOUNDATION} ${SECURITY})
target_sources(cpprest PRIVATE pplx/pplxapple.cpp pplx/pplx.cpp pplx/threadpool.cpp ../include/pplx/threadpool.h)
add_sub_component(cpprest_pplx pplx/pplxapple.cpp pplx/pplx.cpp pplx/threadpool.cpp ../include/pplx/threadpool.h)
sub_component_link_libraries(cpprest_pplx PUBLIC ${COREFOUNDATION} ${SECURITY})
if(CPPREST_INSTALL_HEADERS)
install(FILES ../include/pplx/threadpool.h DESTINATION include/pplx)
endif()
elseif(CPPREST_PPLX_IMPL STREQUAL "linux")
target_sources(cpprest PRIVATE pplx/pplxlinux.cpp pplx/pplx.cpp pplx/threadpool.cpp ../include/pplx/threadpool.h)
add_sub_component(cpprest_pplx pplx/pplxlinux.cpp pplx/pplx.cpp pplx/threadpool.cpp ../include/pplx/threadpool.h)
if(CPPREST_INSTALL_HEADERS)
install(FILES ../include/pplx/threadpool.h DESTINATION include/pplx)
endif()
elseif(CPPREST_PPLX_IMPL STREQUAL "win")
target_sources(cpprest PRIVATE pplx/pplxwin.cpp)
add_sub_component(cpprest_pplx pplx/pplxwin.cpp)
if(CPPREST_WEBSOCKETS_IMPL STREQUAL "wspp")
target_sources(cpprest PRIVATE pplx/threadpool.cpp ../include/pplx/threadpool.h)
sub_component_sources(cpprest_pplx PRIVATE pplx/threadpool.cpp ../include/pplx/threadpool.h)
if(CPPREST_INSTALL_HEADERS)
install(FILES ../include/pplx/threadpool.h DESTINATION include/pplx)
endif()
endif()
elseif(CPPREST_PPLX_IMPL STREQUAL "winpplx")
target_compile_definitions(cpprest PUBLIC -DCPPREST_FORCE_PPLX=1)
target_sources(cpprest PRIVATE pplx/pplxwin.cpp pplx/pplx.cpp pplx/threadpool.cpp ../include/pplx/threadpool.h)
if(CPPREST_INSTALL_HEADERS)
install(FILES ../include/pplx/threadpool.h DESTINATION include/pplx)
add_sub_component(cpprest_pplx pplx/pplxwin.cpp pplx/pplx.cpp)
target_compile_definitions(cpprest_pplx_properties_PUBLIC INTERFACE -DCPPREST_FORCE_PPLX=1)
if(NOT CPPREST_WEBSOCKETS_IMPL STREQUAL "none")
sub_component_sources(cpprest_pplx PRIVATE pplx/threadpool.cpp ../include/pplx/threadpool.h)
if(CPPREST_INSTALL_HEADERS)
install(FILES ../include/pplx/threadpool.h DESTINATION include/pplx)
endif()
endif()
elseif(CPPREST_PPLX_IMPL STREQUAL "winrt")
target_sources(cpprest PRIVATE pplx/pplxwin.cpp)
add_sub_component(cpprest_pplx pplx/pplxwin.cpp)
else()
message(FATAL_ERROR "Invalid implementation")
endif()
if(NOT CPPREST_PPLX_IMPL STREQUAL "winrt")
cpprest_find_boost()
sub_component_link_libraries(cpprest_pplx PUBLIC cpprestsdk_boost_internal)
endif()
sub_component_link_libraries(cpprest_pplx PUBLIC cpprest_utility_asyncrt)

# Http client component
if(NOT CPPREST_EXCLUDE_HTTP_NARROW_STRING_WIP)
Expand Down Expand Up @@ -156,14 +303,15 @@ endif()

# fileio streams component
if(CPPREST_FILEIO_IMPL STREQUAL "win32")
target_sources(cpprest PRIVATE streams/fileio_win32.cpp)
add_sub_component(cpprest_streams streams/fileio_win32.cpp)
elseif(CPPREST_FILEIO_IMPL STREQUAL "winrt")
target_sources(cpprest PRIVATE streams/fileio_winrt.cpp)
add_sub_component(cpprest_streams streams/fileio_winrt.cpp)
elseif(CPPREST_FILEIO_IMPL STREQUAL "posix")
target_sources(cpprest PRIVATE streams/fileio_posix.cpp)
add_sub_component(cpprest_streams streams/fileio_posix.cpp)
else()
message(FATAL_ERROR "Invalid implementation")
endif()
sub_component_link_libraries(cpprest_streams PUBLIC cpprest_utility_asyncrt)

# http listener component
if(CPPREST_HTTP_LISTENER_IMPL STREQUAL "asio")
Expand Down Expand Up @@ -197,35 +345,34 @@ endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(WERROR)
target_compile_options(cpprest PRIVATE -Werror)
target_compile_options(cpprest_interface_PRIVATE INTERFACE -Werror)
endif()
target_compile_options(cpprest PRIVATE -pedantic ${WARNINGS})
target_compile_options(cpprest_interface_PRIVATE INTERFACE -pedantic ${WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(WERROR)
target_compile_options(cpprest PRIVATE /WX ${WARNINGS})
target_compile_options(cpprest_interface_PRIVATE INTERFACE /WX ${WARNINGS})
endif()
else()
message(FATAL_ERROR "Unknown compiler")
endif()

if(WIN32)
if (BUILD_SHARED_LIBS)
target_compile_definitions(cpprest PRIVATE -D_ASYNCRT_EXPORT -D_PPLX_EXPORT -D_USRDLL)
target_compile_definitions(cpprest_interface_PRIVATE INTERFACE -D_ASYNCRT_EXPORT -D_PPLX_EXPORT -D_USRDLL)
else()
target_compile_definitions(cpprest PUBLIC -D_NO_ASYNCRTIMP -D_NO_PPLXIMP)
target_compile_definitions(cpprest_interface_PUBLIC INTERFACE -D_NO_ASYNCRTIMP -D_NO_PPLXIMP)
endif()
elseif(ANDROID)
target_link_libraries(cpprest PRIVATE ${ANDROID_STL_FLAGS})
target_link_libraries(cpprest_interface_PRIVATE INTERFACE ${ANDROID_STL_FLAGS})
endif()

if (WIN32 AND NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
target_link_libraries(cpprest PRIVATE
bcrypt.lib
crypt32.lib
)
elseif(WINDOWS_STORE)
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio .*")
target_compile_definitions(cpprest PRIVATE -DWINAPI_FAMILY=WINAPI_FAMILY_PC_APP)
target_compile_definitions(cpprest_interface_PRIVATE INTERFACE -DWINAPI_FAMILY=WINAPI_FAMILY_PC_APP)
get_target_property(LINK_FLAGS cpprest LINK_FLAGS)
if(NOT LINK_FLAGS)
set(LINK_FLAGS "")
Expand Down Expand Up @@ -257,7 +404,6 @@ if(CPPREST_INSTALL)
set(CPPREST_USES_BROTLI OFF)
set(CPPREST_USES_OPENSSL OFF)

set(CPPREST_TARGETS cpprest)
if(TARGET cpprestsdk_boost_internal)
list(APPEND CPPREST_TARGETS cpprestsdk_boost_internal)
set(CPPREST_USES_BOOST ON)
Expand Down
Loading