Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v141 toolchain support (VS2017) and examples of building a single dll #59

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ packages/
Debug/
Release/
out/
build.debug/
build.release/
.vs/
build*/
.vs*/
*.vcxproj.user
54 changes: 54 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@echo off

set root=%~dp0%
set build=%root%build
set output=%build%\output
set output_lib=%output%\lib
set output_dll=%output%\dll
set output_include=%output%\include

if exist %output_lib%\x64 rmdir /s/q %output_lib%\x64
if exist %output_dll%\x64 rmdir /s/q %output_dll%\x64

robocopy /s /njh /njs include %output_include%
if %errorlevel% geq 8 exit /b %errorlevel%

if exist %build%\CMakeCache.txt del /F %build%\CMakeCache.txt
if %errorlevel% neq 0 exit /b %errorlevel%

cmake %root% -G "Visual Studio 15 2017" -B %build% -A x64 -DCMAKE_TOOLCHAIN_FILE="%root%\submodules\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows-static-md-141 -DBUILD_TESTING=false -DUSE_CPPRESTSDK=true -DINCLUDE_JSONCPP=true
if %errorlevel% neq 0 exit /b %errorlevel%

call :build_all x64 Debug
if %errorlevel% neq 0 exit /b %errorlevel%
call :build_all x64 RelWithDebInfo Release
if %errorlevel% neq 0 exit /b %errorlevel%

exit /b 0

REM ===================================================================================================================

:build_all
echo Building %1\%2:

set build_cfg=%2
set target_cfg=%2
if [%3] NEQ [] set target_cfg=%3

call :build_project %build%\microsoft-signalr.sln microsoft-signalr %1 %build_cfg%
if %errorlevel% neq 0 exit /b %errorlevel%
robocopy /njh /njs %build%\bin\%build_cfg% %output_lib%\%1\%target_cfg% *.lib
if %errorlevel% geq 8 exit /b %errorlevel%
robocopy /njh /njs %build%\bin\%build_cfg% %output_dll%\%1\%target_cfg% *.dll *.pdb
if %errorlevel% geq 8 exit /b %errorlevel%

exit /b 0

REM ===================================================================================================================

:build_project
msbuild /nologo /verbosity:minimal /m /target:%2 /p:Configuration=%4 /p:Platform=%3 %1
exit /b %errorlevel%



3 changes: 3 additions & 0 deletions include/signalrclient/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace signalr
SIGNALRCLIENT_API void __cdecl set_disconnected(const std::function<void __cdecl(std::exception_ptr)>& disconnected_callback);

SIGNALRCLIENT_API void __cdecl set_client_config(const signalr_client_config& config);
#ifdef USE_CPPRESTSDK
SIGNALRCLIENT_API void __cdecl set_client_config(const cpprest_client_config& config);
#endif

SIGNALRCLIENT_API void __cdecl stop(std::function<void(std::exception_ptr)> callback, std::exception_ptr exception) noexcept;

Expand Down
21 changes: 14 additions & 7 deletions include/signalrclient/signalr_client_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

#ifdef USE_CPPRESTSDK
#pragma warning (push)
#pragma warning (disable : 5204 4355 4625 4626 4868)
#if _MSC_FULL_VER > 191627045
#pragma warning (disable : 5204)
#endif
#pragma warning (disable : 4355 4625 4626 4868)
#include <cpprest/http_client.h>
#include <cpprest/ws_client.h>
#pragma warning (pop)
Expand All @@ -20,10 +23,11 @@

namespace signalr
{
class signalr_client_config

#ifdef USE_CPPRESTSDK
class cpprest_client_config
{
public:
#ifdef USE_CPPRESTSDK
SIGNALRCLIENT_API void __cdecl set_proxy(const web::web_proxy &proxy);
// Please note that setting credentials does not work in all cases.
// For example, Basic Authentication fails under Win32.
Expand All @@ -36,8 +40,15 @@ namespace signalr

SIGNALRCLIENT_API web::websockets::client::websocket_client_config __cdecl get_websocket_client_config() const noexcept;
SIGNALRCLIENT_API void __cdecl set_websocket_client_config(const web::websockets::client::websocket_client_config& websocket_client_config);
private:
web::http::client::http_client_config m_http_client_config;
web::websockets::client::websocket_client_config m_websocket_client_config;
};
#endif

class signalr_client_config
{
public:
SIGNALRCLIENT_API __cdecl signalr_client_config();

SIGNALRCLIENT_API const std::map<std::string, std::string>& __cdecl get_http_headers() const noexcept;
Expand All @@ -47,10 +58,6 @@ namespace signalr
SIGNALRCLIENT_API const std::shared_ptr<scheduler>& __cdecl get_scheduler() const noexcept;

private:
#ifdef USE_CPPRESTSDK
web::http::client::http_client_config m_http_client_config;
web::websockets::client::websocket_client_config m_websocket_client_config;
#endif
std::map<std::string, std::string> m_http_headers;
std::shared_ptr<scheduler> m_scheduler;
};
Expand Down
6 changes: 6 additions & 0 deletions setup.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off

set root=%~dp0%

if not exist %root%\submodules\vcpkg\vcpkg.exe call %root%\submodules\vcpkg\bootstrap-vcpkg.bat
%root%\submodules\vcpkg\vcpkg.exe install cpprestsdk:x64-windows-static-md-141 --overlay-triplets=%root%\vcpkg-triplets
21 changes: 20 additions & 1 deletion src/signalrclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ set (SOURCES
../../third_party_code/cpprestsdk/uri_builder.cpp
)

file( GLOB PUBLICHEADERS LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
"../../include/signalrclient/*.h"
)

file( GLOB PRIVATEHEADERS LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
"*.h"
)

source_group( "Headers"
FILES
${PUBLICHEADERS}
)

source_group( "Source"
FILES
${PRIVATEHEADERS}
${SOURCES}
)

if(USE_MSGPACK)
list (APPEND SOURCES
binary_message_formatter.cpp
Expand All @@ -37,7 +56,7 @@ include_directories(
../../third_party_code/cpprestsdk
)

add_library (microsoft-signalr ${SOURCES})
add_library (microsoft-signalr ${SOURCES} ${PUBLICHEADERS} ${PRIVATEHEADERS})

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(WERROR)
Expand Down
5 changes: 4 additions & 1 deletion src/signalrclient/completion_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#pragma once

#pragma warning (push)
#pragma warning (disable : 5204 4355)
#if _MSC_FULL_VER > 191627045
#pragma warning (disable : 5204)
#endif
#pragma warning (disable : 4355)
#include <future>
#pragma warning (pop)

Expand Down
7 changes: 7 additions & 0 deletions src/signalrclient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ namespace signalr
m_pImpl->set_client_config(config);
}

#ifdef USE_CPPRESTSDK
void connection::set_client_config(const cpprest_client_config& config)
{
m_pImpl->set_client_config(config);
}
#endif

void connection::stop(std::function<void(std::exception_ptr)> callback, std::exception_ptr exception) noexcept
{
m_pImpl->stop(callback, exception);
Expand Down
16 changes: 15 additions & 1 deletion src/signalrclient/connection_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ namespace signalr
}

auto http_client = m_http_client_factory(m_signalr_client_config);
negotiate::negotiate(http_client, url, m_signalr_client_config,
negotiate::negotiate(
http_client,
url,
m_signalr_client_config,
#ifdef USE_CPPRESTSDK
m_cpprest_client_config,
#endif
[callback, weak_connection, redirect_count, token, url, transport_started](negotiation_response&& response, std::exception_ptr exception)
{
auto connection = weak_connection.lock();
Expand Down Expand Up @@ -735,6 +741,14 @@ namespace signalr
m_signalr_client_config = config;
}

#ifdef USE_CPPRESTSDK
void connection_impl::set_client_config(const cpprest_client_config& config)
{
ensure_disconnected("cannot set client config when the connection is not in the disconnected state. ");
m_cpprest_client_config = config;
}
#endif

void connection_impl::set_disconnected(const std::function<void(std::exception_ptr)>& disconnected)
{
ensure_disconnected("cannot set the disconnected callback when the connection is not in the disconnected state. ");
Expand Down
6 changes: 6 additions & 0 deletions src/signalrclient/connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ namespace signalr
void set_message_received(const std::function<void(std::string&&)>& message_received);
void set_disconnected(const std::function<void(std::exception_ptr)>& disconnected);
void set_client_config(const signalr_client_config& config);
#ifdef USE_CPPRESTSDK
void set_client_config(const cpprest_client_config& config);
#endif

private:
std::shared_ptr<scheduler> m_scheduler;
Expand All @@ -62,6 +65,9 @@ namespace signalr
std::function<void(std::string&&)> m_message_received;
std::function<void(std::exception_ptr)> m_disconnected;
signalr_client_config m_signalr_client_config;
#ifdef USE_CPPRESTSDK
cpprest_client_config m_cpprest_client_config;
#endif

std::shared_ptr<cancellation_token> m_disconnect_cts;
std::mutex m_stop_lock;
Expand Down
5 changes: 4 additions & 1 deletion src/signalrclient/default_http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#include "default_http_client.h"
#include <thread>
#pragma warning (push)
#pragma warning (disable : 5204 4355 4625 4626 4868)
#if _MSC_FULL_VER > 191627045
#pragma warning (disable : 5204)
#endif
#pragma warning (disable : 4355 4625 4626 4868)
#include <cpprest/http_client.h>
#pragma warning (pop)

Expand Down
8 changes: 4 additions & 4 deletions src/signalrclient/default_websocket_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace signalr
{
namespace
{
static web::websockets::client::websocket_client_config create_client_config(const signalr_client_config& signalr_client_config) noexcept
static web::websockets::client::websocket_client_config create_client_config(const signalr_client_config& signalr_client_config, const cpprest_client_config& cpprest_client_config) noexcept
{
auto websocket_client_config = signalr_client_config.get_websocket_client_config();
auto websocket_client_config = cpprest_client_config.get_websocket_client_config();
auto& websocket_headers = websocket_client_config.headers();
for (auto& header : signalr_client_config.get_http_headers())
{
Expand All @@ -25,8 +25,8 @@ namespace signalr
}
}

default_websocket_client::default_websocket_client(const signalr_client_config& signalr_client_config) noexcept
: m_underlying_client(create_client_config(signalr_client_config))
default_websocket_client::default_websocket_client(const signalr_client_config& signalr_client_config, const cpprest_client_config& cpprest_client_config) noexcept
: m_underlying_client(create_client_config(signalr_client_config, cpprest_client_config))
{ }

void default_websocket_client::start(const std::string& url, std::function<void(std::exception_ptr)> callback)
Expand Down
7 changes: 5 additions & 2 deletions src/signalrclient/default_websocket_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#ifdef USE_CPPRESTSDK

#pragma warning (push)
#pragma warning (disable : 5204 4355 4625 4626 4868)
#if _MSC_FULL_VER > 191627045
#pragma warning (disable : 5204)
#endif
#pragma warning (disable : 4355 4625 4626 4868)
#include <cpprest/ws_client.h>
#pragma warning (pop)
#include "signalrclient/signalr_client_config.h"
Expand All @@ -18,7 +21,7 @@ namespace signalr
class default_websocket_client : public websocket_client
{
public:
explicit default_websocket_client(const signalr_client_config& signalr_client_config = {}) noexcept;
explicit default_websocket_client(const signalr_client_config& signalr_client_config = {}, const cpprest_client_config& cpprest_client_config = {}) noexcept;

void start(const std::string& url, std::function<void(std::exception_ptr)> callback);
void stop(std::function<void(std::exception_ptr)> callback);
Expand Down
9 changes: 6 additions & 3 deletions src/signalrclient/negotiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ namespace signalr
const int negotiate_version = 1;

void negotiate(std::shared_ptr<http_client> client, const std::string& base_url,
const signalr_client_config& config,
const signalr_client_config& signalr_client_config,
#ifdef USE_CPPRESTSDK
const cpprest_client_config& cpprest_client_config,
#endif
std::function<void(negotiation_response&&, std::exception_ptr)> callback) noexcept
{
std::string negotiate_url;
Expand All @@ -33,9 +36,9 @@ namespace signalr
// TODO: signalr_client_config
http_request request;
request.method = http_method::POST;
request.headers = config.get_http_headers();
request.headers = signalr_client_config.get_http_headers();
#ifdef USE_CPPRESTSDK
request.timeout = config.get_http_client_config().timeout();
request.timeout = cpprest_client_config.get_http_client_config().timeout();
#endif

client->send(negotiate_url, request, [callback](const http_response& http_response, std::exception_ptr exception)
Expand Down
5 changes: 4 additions & 1 deletion src/signalrclient/negotiate.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ namespace signalr
namespace negotiate
{
void negotiate(std::shared_ptr<http_client> client, const std::string& base_url,
const signalr_client_config& signalr_client_config,
const signalr_client_config& signalr_client_config,
#ifdef USE_CPPRESTSDK
const cpprest_client_config& cpprest_client_config,
#endif
std::function<void(negotiation_response&&, std::exception_ptr)> callback) noexcept;
}
}
12 changes: 6 additions & 6 deletions src/signalrclient/signalr_client_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@
namespace signalr
{
#ifdef USE_CPPRESTSDK
void signalr_client_config::set_proxy(const web::web_proxy &proxy)
void cpprest_client_config::set_proxy(const web::web_proxy &proxy)
{
m_http_client_config.set_proxy(proxy);
m_websocket_client_config.set_proxy(proxy);
}

void signalr_client_config::set_credentials(const web::credentials &credentials)
void cpprest_client_config::set_credentials(const web::credentials &credentials)
{
m_http_client_config.set_credentials(credentials);
m_websocket_client_config.set_credentials(credentials);
}

web::http::client::http_client_config signalr_client_config::get_http_client_config() const
web::http::client::http_client_config cpprest_client_config::get_http_client_config() const
{
return m_http_client_config;
}

void signalr_client_config::set_http_client_config(const web::http::client::http_client_config& http_client_config)
void cpprest_client_config::set_http_client_config(const web::http::client::http_client_config& http_client_config)
{
m_http_client_config = http_client_config;
}

web::websockets::client::websocket_client_config signalr_client_config::get_websocket_client_config() const noexcept
web::websockets::client::websocket_client_config cpprest_client_config::get_websocket_client_config() const noexcept
{
return m_websocket_client_config;
}

void signalr_client_config::set_websocket_client_config(const web::websockets::client::websocket_client_config& websocket_client_config)
void cpprest_client_config::set_websocket_client_config(const web::websockets::client::websocket_client_config& websocket_client_config)
{
m_websocket_client_config = websocket_client_config;
}
Expand Down
4 changes: 4 additions & 0 deletions src/signalrclient/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@

#endif

#if _MSC_FULL_VER <= 191627045
#pragma warning (disable: 4625 4626 5026 5027)
#endif

#include <functional>
#include <unordered_map>
Loading