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
51 changes: 48 additions & 3 deletions Release/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,37 @@ set(CPPREST_VERSION_MAJOR 2)
set(CPPREST_VERSION_MINOR 10)
set(CPPREST_VERSION_REVISION 14)

# Note: when bumping CMake version to 3.3 or higher if(... IN_LIST ...) may be used
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_17 COMPILER_HAS_CXX_STD_17)
set(CPPREST_USE_STRING_VIEWS_DEFAULT_PER_CXX_STANDARD OFF)
if(COMPILER_HAS_CXX_STD_17 EQUAL "-1")
if(CPPREST_USE_STRING_VIEWS)
if(CMAKE_VERSION VERSION_LESS 3.8)
message(FATAL_ERROR "CPPREST_USE_STRING_VIEWS cannot be enabled. CMake 3.8 or higher required to support C++17.")
else()
message(FATAL_ERROR "CPPREST_USE_STRING_VIEWS cannot be enabled. Compiler (${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}) does not support C++17.")
endif()
endif()
elseif(CMAKE_CXX_STANDARD LESS 17)
if(CPPREST_USE_STRING_VIEWS)
message(FATAL_ERROR "CPPREST_USE_STRING_VIEWS cannot be enabled when C++ standard is less than 17")
endif()
elseif((NOT CMAKE_CXX_STANDARD GREATER 16.99) AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"))
if(CPPREST_USE_STRING_VIEWS)
message(FATAL_ERROR "CPPREST_USE_STRING_VIEWS cannot be enabled without setting C++ standard to 17 or greater for current configuration") # see compiler specific settings below
endif()
else()
set(CPPREST_USE_STRING_VIEWS_DEFAULT_PER_CXX_STANDARD ON)
endif()

enable_testing()

set(WERROR ON CACHE BOOL "Treat Warnings as Errors.")
set(CPPREST_EXCLUDE_WEBSOCKETS OFF CACHE BOOL "Exclude websockets functionality.")
set(CPPREST_EXCLUDE_COMPRESSION OFF CACHE BOOL "Exclude compression functionality.")
set(CPPREST_EXCLUDE_BROTLI ON CACHE BOOL "Exclude Brotli compression functionality.")
set(CPPREST_EXPORT_DIR cpprestsdk CACHE STRING "Directory to install CMake config files.")
option(CPPREST_USE_STRING_VIEWS "Use string_view types" ${CPPREST_USE_STRING_VIEWS_DEFAULT_PER_CXX_STANDARD})
set(CPPREST_INSTALL_HEADERS ON CACHE BOOL "Install header files.")
set(CPPREST_INSTALL ON CACHE BOOL "Add install commands.")

Expand Down Expand Up @@ -116,6 +140,11 @@ endif()
set(WARNINGS)
set(ANDROID_LIBS)

# Generic build settings
if(CPPREST_USE_STRING_VIEWS)
add_definitions(-DCPPREST_USE_STRING_VIEWS)
endif()

# Platform (not compiler) specific settings
if(ANDROID)
# These are used in the shared library case
Expand All @@ -140,6 +169,15 @@ else()
endif()

# Compiler (not platform) specific settings
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(NOT CMAKE_CXX_STANDARD GREATER 0)
if(CPPREST_USE_STRING_VIEWS)
message(FATAL_ERROR "internal cpprestsdk cmake error: CPPREST_USE_STRING_VIEWS ON while C++ standard not set")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS)
message("-- Setting clang options")

Expand All @@ -157,18 +195,18 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wno-return-type-c-linkage -Wno-unneeded-internal-declaration")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++${CMAKE_CXX_STANDARD}")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")

elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message("-- Setting gcc options")

set(WARNINGS -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code)
set(LD_FLAGS "${LD_FLAGS} -Wl,-z,defs")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -D_GLIBCXX_USE_SCHED_YIELD -D_GLIBCXX_USE_NANOSLEEP")
endif()
Expand All @@ -193,6 +231,13 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/permissive-)
endif()
endif()

# Suppress C++17 deprecation warning in aiso per https://github.com/chriskohlhoff/asio/issues/290#issuecomment-371867040
# MSVC has addressed issue in 16.0 per https://devblogs.microsoft.com/cppblog/cpp17-20-features-and-fixes-in-vs-2019/
if(MSVC_VERSION GREATER 1912 AND MSVC_VERSION LESS 1920)
add_definitions(-D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING)
endif()

else()
message("-- Unknown compiler, success is doubtful.")
message("CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")
Expand Down
2 changes: 1 addition & 1 deletion Release/include/cpprest/base64_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _ASYNCRTIMP utility::string_t __cdecl to_base64(uint64_t data);
/// <summary>
/// Decode the given base64 string to a byte array
/// </summary>
_ASYNCRTIMP std::vector<unsigned char> __cdecl from_base64(const utility::string_t& str);
_ASYNCRTIMP std::vector<unsigned char> __cdecl from_base64(utility::string_view_t str);

} // namespace conversions

Expand Down
22 changes: 22 additions & 0 deletions Release/include/cpprest/details/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <iostream>
#include <sstream>
#include <string>
#if defined(CPPREST_USE_STRING_VIEWS)
#include <string_view>
#endif

#ifndef _WIN32
#ifndef __STDC_LIMIT_MACROS
Expand All @@ -44,11 +47,22 @@ typedef uint64_t size64_t;
typedef uint32_t HRESULT; // Needed for PPLX
#endif

#if defined(CPPREST_USE_STRING_VIEWS)
typedef std::string_view nstring_view_t;
typedef std::wstring_view wstring_view_t;
template<typename CharType> using string_view = std::basic_string_view<CharType>;
#else
typedef const std::string & nstring_view_t;
typedef const std::wstring & wstring_view_t;
template<typename CharType> using string_view = const std::basic_string<CharType> &;
#endif

#ifdef _UTF16_STRINGS
//
// On Windows, all strings are wide
//
typedef wchar_t char_t;
typedef wstring_view_t string_view_t;
typedef std::wstring string_t;
#define _XPLATSTR(x) L##x
typedef std::wostringstream ostringstream_t;
Expand All @@ -66,6 +80,7 @@ typedef std::wstringstream stringstream_t;
// On POSIX platforms, all strings are narrow
//
typedef char char_t;
typedef nstring_view_t string_view_t;
typedef std::string string_t;
#define _XPLATSTR(x) x
typedef std::ostringstream ostringstream_t;
Expand All @@ -90,6 +105,7 @@ typedef std::stringstream stringstream_t;
} // namespace utility

typedef char utf8char;
typedef utility::nstring_view_t utf8string_view;
typedef std::string utf8string;
typedef std::stringstream utf8stringstream;
typedef std::ostringstream utf8ostringstream;
Expand All @@ -99,6 +115,7 @@ typedef std::istringstream utf8istringstream;

#if defined(_UTF16_STRINGS) || defined(_WIN32)
typedef wchar_t utf16char;
typedef utility::wstring_view_t utf16string_view;
typedef std::wstring utf16string;
typedef std::wstringstream utf16stringstream;
typedef std::wostringstream utf16ostringstream;
Expand All @@ -107,6 +124,11 @@ typedef std::wistream utf16istream;
typedef std::wistringstream utf16istringstream;
#else
typedef char16_t utf16char;
#if defined(CPPREST_USE_STRING_VIEWS)
typedef std::u16string_view utf16string_view;
#else
typedef const std::u16string & utf16string_view;
#endif
typedef std::u16string utf16string;
typedef std::basic_stringstream<utf16char> utf16stringstream;
typedef std::basic_ostringstream<utf16char> utf16ostringstream;
Expand Down
6 changes: 3 additions & 3 deletions Release/include/cpprest/details/web_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class winrt_encryption
{
public:
winrt_encryption() = default;
_ASYNCRTIMP winrt_encryption(const ::utility::string_t& data);
_ASYNCRTIMP winrt_encryption(utility::string_view_t data);
_ASYNCRTIMP plaintext_string decrypt() const;

private:
Expand All @@ -43,7 +43,7 @@ class win32_encryption
{
public:
win32_encryption() = default;
_ASYNCRTIMP win32_encryption(const ::utility::string_t& data);
_ASYNCRTIMP win32_encryption(::utility::string_view_t data);
_ASYNCRTIMP ~win32_encryption();
_ASYNCRTIMP plaintext_string decrypt() const;

Expand Down Expand Up @@ -73,7 +73,7 @@ class credentials
/// </summary>
/// <param name="username">User name as a string.</param>
/// <param name="password">Password as a string.</param>
credentials(utility::string_t username, const utility::string_t& password)
credentials(utility::string_t username, utility::string_view_t password)
: m_username(std::move(username)), m_password(password)
{
}
Expand Down
10 changes: 5 additions & 5 deletions Release/include/cpprest/filestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ class basic_file_buffer : public details::streambuf_state_manager<_CharType>

#if !defined(__cplusplus_winrt)
static pplx::task<std::shared_ptr<basic_streambuf<_CharType>>> open(
const utility::string_t& _Filename,
utility::string_view_t _Filename,
std::ios_base::openmode _Mode = std::ios_base::out,
#ifdef _WIN32
int _Prot = (int)std::ios_base::_Openprot
Expand All @@ -724,7 +724,7 @@ class basic_file_buffer : public details::streambuf_state_manager<_CharType>
{
auto result_tce = pplx::task_completion_event<std::shared_ptr<basic_streambuf<_CharType>>>();
auto callback = new _filestream_callback_open(result_tce);
_open_fsb_str(callback, _Filename.c_str(), _Mode, _Prot);
_open_fsb_str(callback, _Filename.data(), _Mode, _Prot);
return pplx::create_task(result_tce);
}

Expand Down Expand Up @@ -955,7 +955,7 @@ class file_buffer
/// <param name="mode">The opening mode of the file</param>
/// <param name="prot">The file protection mode</param>
/// <returns>A <c>task</c> that returns an opened stream buffer on completion.</returns>
static pplx::task<streambuf<_CharType>> open(const utility::string_t& file_name,
static pplx::task<streambuf<_CharType>> open(utility::string_view_t file_name,
std::ios_base::openmode mode = std::ios_base::out,
#ifdef _WIN32
int prot = _SH_DENYRD
Expand Down Expand Up @@ -1010,7 +1010,7 @@ class file_stream
/// <param name="mode">The opening mode of the file</param>
/// <param name="prot">The file protection mode</param>
/// <returns>A <c>task</c> that returns an opened input stream on completion.</returns>
static pplx::task<streams::basic_istream<_CharType>> open_istream(const utility::string_t& file_name,
static pplx::task<streams::basic_istream<_CharType>> open_istream(utility::string_view_t file_name,
std::ios_base::openmode mode = std::ios_base::in,
#ifdef _WIN32
int prot = (int)std::ios_base::_Openprot
Expand All @@ -1035,7 +1035,7 @@ class file_stream
/// <param name="mode">The opening mode of the file</param>
/// <param name="prot">The file protection mode</param>
/// <returns>A <c>task</c> that returns an opened output stream on completion.</returns>
static pplx::task<streams::basic_ostream<_CharType>> open_ostream(const utility::string_t& file_name,
static pplx::task<streams::basic_ostream<_CharType>> open_ostream(utility::string_view_t file_name,
std::ios_base::openmode mode = std::ios_base::out,
#ifdef _WIN32
int prot = (int)std::ios_base::_Openprot
Expand Down
Loading