diff --git a/.gitignore b/.gitignore index 99b84a13..bd2ff201 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ packages/ Debug/ Release/ out/ -build.debug/ -build.release/ -.vs/ +build*/ +.vs*/ *.vcxproj.user \ No newline at end of file diff --git a/build.cmd b/build.cmd new file mode 100644 index 00000000..fd2f434f --- /dev/null +++ b/build.cmd @@ -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% + + + diff --git a/include/signalrclient/connection.h b/include/signalrclient/connection.h index 9768a345..d9602017 100644 --- a/include/signalrclient/connection.h +++ b/include/signalrclient/connection.h @@ -38,6 +38,9 @@ namespace signalr SIGNALRCLIENT_API void __cdecl set_disconnected(const std::function& 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 callback, std::exception_ptr exception) noexcept; diff --git a/include/signalrclient/signalr_client_config.h b/include/signalrclient/signalr_client_config.h index f045000b..f5f553dc 100644 --- a/include/signalrclient/signalr_client_config.h +++ b/include/signalrclient/signalr_client_config.h @@ -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 #include #pragma warning (pop) @@ -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. @@ -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& __cdecl get_http_headers() const noexcept; @@ -47,10 +58,6 @@ namespace signalr SIGNALRCLIENT_API const std::shared_ptr& __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 m_http_headers; std::shared_ptr m_scheduler; }; diff --git a/setup.cmd b/setup.cmd new file mode 100644 index 00000000..8af4045f --- /dev/null +++ b/setup.cmd @@ -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 \ No newline at end of file diff --git a/src/signalrclient/CMakeLists.txt b/src/signalrclient/CMakeLists.txt index e073753a..b8aa9cd7 100644 --- a/src/signalrclient/CMakeLists.txt +++ b/src/signalrclient/CMakeLists.txt @@ -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 @@ -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) diff --git a/src/signalrclient/completion_event.h b/src/signalrclient/completion_event.h index a7099637..3e741e73 100644 --- a/src/signalrclient/completion_event.h +++ b/src/signalrclient/completion_event.h @@ -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 #pragma warning (pop) diff --git a/src/signalrclient/connection.cpp b/src/signalrclient/connection.cpp index 2fcdbdaa..35df81bf 100644 --- a/src/signalrclient/connection.cpp +++ b/src/signalrclient/connection.cpp @@ -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 callback, std::exception_ptr exception) noexcept { m_pImpl->stop(callback, exception); diff --git a/src/signalrclient/connection_impl.cpp b/src/signalrclient/connection_impl.cpp index db3f8c8c..e444aace 100644 --- a/src/signalrclient/connection_impl.cpp +++ b/src/signalrclient/connection_impl.cpp @@ -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(); @@ -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& disconnected) { ensure_disconnected("cannot set the disconnected callback when the connection is not in the disconnected state. "); diff --git a/src/signalrclient/connection_impl.h b/src/signalrclient/connection_impl.h index 6e5cb923..5a7bf98e 100644 --- a/src/signalrclient/connection_impl.h +++ b/src/signalrclient/connection_impl.h @@ -48,6 +48,9 @@ namespace signalr void set_message_received(const std::function& message_received); void set_disconnected(const std::function& 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 m_scheduler; @@ -62,6 +65,9 @@ namespace signalr std::function m_message_received; std::function m_disconnected; signalr_client_config m_signalr_client_config; +#ifdef USE_CPPRESTSDK + cpprest_client_config m_cpprest_client_config; +#endif std::shared_ptr m_disconnect_cts; std::mutex m_stop_lock; diff --git a/src/signalrclient/default_http_client.cpp b/src/signalrclient/default_http_client.cpp index dcb3a9f9..2db27ef2 100644 --- a/src/signalrclient/default_http_client.cpp +++ b/src/signalrclient/default_http_client.cpp @@ -8,7 +8,10 @@ #include "default_http_client.h" #include #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 #pragma warning (pop) diff --git a/src/signalrclient/default_websocket_client.cpp b/src/signalrclient/default_websocket_client.cpp index 9c24a87e..482da000 100644 --- a/src/signalrclient/default_websocket_client.cpp +++ b/src/signalrclient/default_websocket_client.cpp @@ -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()) { @@ -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 callback) diff --git a/src/signalrclient/default_websocket_client.h b/src/signalrclient/default_websocket_client.h index 9172832a..4b779a63 100644 --- a/src/signalrclient/default_websocket_client.h +++ b/src/signalrclient/default_websocket_client.h @@ -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 #pragma warning (pop) #include "signalrclient/signalr_client_config.h" @@ -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 callback); void stop(std::function callback); diff --git a/src/signalrclient/negotiate.cpp b/src/signalrclient/negotiate.cpp index 6e869980..0185e336 100644 --- a/src/signalrclient/negotiate.cpp +++ b/src/signalrclient/negotiate.cpp @@ -15,7 +15,10 @@ namespace signalr const int negotiate_version = 1; void negotiate(std::shared_ptr 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 callback) noexcept { std::string negotiate_url; @@ -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) diff --git a/src/signalrclient/negotiate.h b/src/signalrclient/negotiate.h index 15e25ec8..c231bd76 100644 --- a/src/signalrclient/negotiate.h +++ b/src/signalrclient/negotiate.h @@ -13,7 +13,10 @@ namespace signalr namespace negotiate { void negotiate(std::shared_ptr 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 callback) noexcept; } } diff --git a/src/signalrclient/signalr_client_config.cpp b/src/signalrclient/signalr_client_config.cpp index f48a68cb..d5d769bb 100644 --- a/src/signalrclient/signalr_client_config.cpp +++ b/src/signalrclient/signalr_client_config.cpp @@ -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; } diff --git a/src/signalrclient/stdafx.h b/src/signalrclient/stdafx.h index 431e5c83..6864788b 100644 --- a/src/signalrclient/stdafx.h +++ b/src/signalrclient/stdafx.h @@ -16,5 +16,9 @@ #endif +#if _MSC_FULL_VER <= 191627045 +#pragma warning (disable: 4625 4626 5026 5027) +#endif + #include #include \ No newline at end of file diff --git a/src/signalrclient/websocket_transport.cpp b/src/signalrclient/websocket_transport.cpp index 2514723d..6e7986aa 100644 --- a/src/signalrclient/websocket_transport.cpp +++ b/src/signalrclient/websocket_transport.cpp @@ -9,7 +9,10 @@ #include "base_uri.h" #pragma warning (push) -#pragma warning (disable : 5204 4355) +#if _MSC_FULL_VER > 191627045 +#pragma warning (disable : 5204) +#endif +#pragma warning (disable : 4355) #include #pragma warning (pop) diff --git a/vcpkg-triplets/x64-windows-static-md-141.cmake b/vcpkg-triplets/x64-windows-static-md-141.cmake new file mode 100644 index 00000000..79adad59 --- /dev/null +++ b/vcpkg-triplets/x64-windows-static-md-141.cmake @@ -0,0 +1,5 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_PLATFORM_TOOLSET "v141") +set(VCPKG_DEP_INFO_OVERRIDE_VARS "v141") \ No newline at end of file diff --git a/vcpkg-triplets/x64-windows-static-md.cmake b/vcpkg-triplets/x64-windows-static-md.cmake new file mode 100644 index 00000000..eaa8c3b8 --- /dev/null +++ b/vcpkg-triplets/x64-windows-static-md.cmake @@ -0,0 +1,3 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) \ No newline at end of file