From 35a64f5facfbb1c244d4bffd8c2d3519562cc7a6 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Thu, 1 Oct 2015 22:54:08 -0700 Subject: [PATCH 1/4] Added CMake macro to disable websockets functionality on Windows --- Release/CMakeLists.txt | 15 ++++++++++++--- Release/src/CMakeLists.txt | 5 ++++- Release/tests/common/TestRunner/CMakeLists.txt | 5 ++--- .../tests/functional/http/client/CMakeLists.txt | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Release/CMakeLists.txt b/Release/CMakeLists.txt index 2938285f0e..d46a5f8a4c 100644 --- a/Release/CMakeLists.txt +++ b/Release/CMakeLists.txt @@ -101,6 +101,7 @@ elseif(WIN32) option(BUILD_SHARED_LIBS "Build shared Libraries." ON) option(BUILD_TESTS "Build tests." ON) option(BUILD_SAMPLES "Build samples." ON) + option(CPPREST_EXCLUDE_WEBSOCKETS "Exclude websockets functionality." OFF) option(Boost_USE_STATIC_LIBS ON) add_definitions(-DUNICODE -D_UNICODE) @@ -114,8 +115,12 @@ elseif(WIN32) endif() add_definitions(${Casablanca_DEFINITIONS} -D_WINSOCK_DEPRECATED_NO_WARNINGS -DWIN32) - find_package(Boost 1.55 REQUIRED COMPONENTS random system thread filesystem chrono atomic) - find_package(OpenSSL 1.0 REQUIRED) + if (CPPREST_EXCLUDE_WEBSOCKETS) + add_definitions(-DCPPREST_EXCLUDE_WEBSOCKETS=1) + else() + find_package(Boost 1.55 REQUIRED COMPONENTS random system thread filesystem chrono atomic) + find_package(OpenSSL 1.0 REQUIRED) + endif() else() message(FATAL_ERROR "-- Unsupported Build Platform.") endif() @@ -165,7 +170,11 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries) # These settings can be used by the test targets set(Casablanca_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) -set(Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include ${Boost_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libs/websocketpp) +if (NOT CPPREST_EXCLUDE_WEBSOCKETS) + set(Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include ${Boost_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libs/websocketpp) +else() + set(Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include) +endif() set(Casablanca_LIBRARY ${LIB}cpprest) set(Casablanca_LIBRARIES ${Casablanca_LIBRARY} ${Boost_LIBRARIES} ${Boost_FRAMEWORK}) diff --git a/Release/src/CMakeLists.txt b/Release/src/CMakeLists.txt index 766e4964bd..f6a000478d 100644 --- a/Release/src/CMakeLists.txt +++ b/Release/src/CMakeLists.txt @@ -1,4 +1,7 @@ -include_directories(../include pch ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}) +include_directories(../include pch) +if (NOT CPPREST_EXCLUDE_WEBSOCKETS) + include_directories(${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}) +endif() set(SOURCES_COMMON http/client/http_client_msg.cpp diff --git a/Release/tests/common/TestRunner/CMakeLists.txt b/Release/tests/common/TestRunner/CMakeLists.txt index 2a00f35431..57e63348b9 100644 --- a/Release/tests/common/TestRunner/CMakeLists.txt +++ b/Release/tests/common/TestRunner/CMakeLists.txt @@ -1,6 +1,5 @@ -include_directories(${Casablanca_INCLUDE_DIR} +include_directories(${Casablanca_INCLUDE_DIRS} ../UnitTestpp - ${Boost_INCLUDE_DIR} ) set(TR_SOURCES @@ -100,4 +99,4 @@ if(NOT IOS AND NOT ANDROID) ) endif() endif() -endif() +endif() diff --git a/Release/tests/functional/http/client/CMakeLists.txt b/Release/tests/functional/http/client/CMakeLists.txt index 97083a20a7..dd9a2b89d0 100644 --- a/Release/tests/functional/http/client/CMakeLists.txt +++ b/Release/tests/functional/http/client/CMakeLists.txt @@ -1,7 +1,7 @@ include_directories( ../utilities/include ../utilities/testlistener/include - ${OPENSSL_INCLUDE_DIR} + ${Casablanca_INCLUDE_DIRS} ) set(SOURCES From 6e07ff3db7533a6ef813a9c2c5bc54c06d8c7d8f Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Thu, 1 Oct 2015 22:54:24 -0700 Subject: [PATCH 2/4] Only use PCH when using MSBuild --- Release/src/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Release/src/CMakeLists.txt b/Release/src/CMakeLists.txt index f6a000478d..bf652bc227 100644 --- a/Release/src/CMakeLists.txt +++ b/Release/src/CMakeLists.txt @@ -70,8 +70,12 @@ elseif(WIN32) httpapi.lib Winhttp.lib ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS} /Yustdafx.h /Zm200") - set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS}") + if (${CMAKE_GENERATOR} MATCHES "Visual Studio .*") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Yustdafx.h /Zm200") + set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h") + endif() + if (BUILD_SHARED_LIBS) add_definitions(-D_ASYNCRT_EXPORT -D_PPLX_EXPORT -D_USRDLL) endif() From 61d14bf7c5b84364d98e427262b75e3a51de0bb0 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Wed, 9 Dec 2015 09:41:23 -0800 Subject: [PATCH 3/4] Remove use of boost in tests if on windows and excluding websockets --- Release/tests/functional/streams/stdstream_tests.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Release/tests/functional/streams/stdstream_tests.cpp b/Release/tests/functional/streams/stdstream_tests.cpp index 8904f3ee08..a100492fd0 100644 --- a/Release/tests/functional/streams/stdstream_tests.cpp +++ b/Release/tests/functional/streams/stdstream_tests.cpp @@ -26,7 +26,9 @@ #include "cpprest/filestream.h" #include "cpprest/producerconsumerstream.h" +#if !defined(_WIN32) || !defined(CPPREST_EXCLUDE_WEBSOCKETS) #include +#endif #if defined(__cplusplus_winrt) using namespace Windows::Storage; @@ -787,6 +789,7 @@ TEST(sync_on_async_close_with_exception) } } +#if !defined(_WIN32) || !defined(CPPREST_EXCLUDE_WEBSOCKETS) TEST(ostream_full_throw_exception) { char tgt_buffer[5]; @@ -806,6 +809,7 @@ TEST(ostream_full_throw_exception) VERIFY_THROWS(astream.read_to_end(os_streambuf).get(), std::exception); } +#endif } }}} From fa9f01538e98ab611f12192fac7fb013a35eef53 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Wed, 9 Dec 2015 09:41:39 -0800 Subject: [PATCH 4/4] Do not build websocket tests if excluding websockets --- .../websockets/client/CMakeLists.txt | 26 +++++++------- .../websockets/utilities/CMakeLists.txt | 34 +++++++++++-------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Release/tests/functional/websockets/client/CMakeLists.txt b/Release/tests/functional/websockets/client/CMakeLists.txt index 53df487947..e4bd7a3625 100644 --- a/Release/tests/functional/websockets/client/CMakeLists.txt +++ b/Release/tests/functional/websockets/client/CMakeLists.txt @@ -1,13 +1,15 @@ -include_directories(../utilities) +if (NOT CPPREST_EXCLUDE_WEBSOCKETS) + include_directories(../utilities) + + set(SOURCES + authentication_tests.cpp + client_construction.cpp + close_tests.cpp + error_tests.cpp + receive_msg_tests.cpp + send_msg_tests.cpp + ) -set(SOURCES - authentication_tests.cpp - client_construction.cpp - close_tests.cpp - error_tests.cpp - receive_msg_tests.cpp - send_msg_tests.cpp -) - -add_casablanca_test(${LIB}websocketclient_test SOURCES) -target_link_libraries(${LIB}websocketclient_test ${LIB}websockettest_utilities) \ No newline at end of file + add_casablanca_test(${LIB}websocketclient_test SOURCES) + target_link_libraries(${LIB}websocketclient_test ${LIB}websockettest_utilities) +endif() \ No newline at end of file diff --git a/Release/tests/functional/websockets/utilities/CMakeLists.txt b/Release/tests/functional/websockets/utilities/CMakeLists.txt index 31f51c37b9..e1c5b1edba 100644 --- a/Release/tests/functional/websockets/utilities/CMakeLists.txt +++ b/Release/tests/functional/websockets/utilities/CMakeLists.txt @@ -1,17 +1,21 @@ -include_directories(include) +if (NOT CPPREST_EXCLUDE_WEBSOCKETS) -if(WIN32) - add_definitions(-DWEBSOCKETTESTUTILITY_EXPORTS) -endif() + include_directories(include) + + if(WIN32) + add_definitions(-DWEBSOCKETTESTUTILITY_EXPORTS) + endif() + + set(SOURCES + test_websocket_server.cpp + ) + + add_library(${LIB}websockettest_utilities ${SOURCES}) + target_link_libraries(${LIB}websockettest_utilities + ${LIB}unittestpp + ${LIB}common_utilities + ${BOOST_LIBRARIES} + ${Casablanca_LIBRARIES} + ) -set(SOURCES - test_websocket_server.cpp -) - -add_library(${LIB}websockettest_utilities ${SOURCES}) -target_link_libraries(${LIB}websockettest_utilities - ${LIB}unittestpp - ${LIB}common_utilities - ${BOOST_LIBRARIES} - ${Casablanca_LIBRARIES} -) +endif() \ No newline at end of file