From 2cb82ec63fb6926fb8eba02a24fed34515b2ea3f Mon Sep 17 00:00:00 2001 From: Tengiz Sharafiev Date: Sat, 24 Mar 2018 11:45:57 +0700 Subject: [PATCH 1/4] Build: Clean up and modernize cmake scripts --- CMakeLists.txt | 206 +++++++++++++++----------- cppnetlibConfig.cmake.in | 58 +++++--- cppnetlibConfigVersion.cmake.in | 11 -- libs/network/example/CMakeLists.txt | 157 +++----------------- libs/network/src/CMakeLists.txt | 82 +++++----- libs/network/test/CMakeLists.txt | 48 +++--- libs/network/test/http/CMakeLists.txt | 153 +++++++------------ libs/network/test/uri/CMakeLists.txt | 43 ++---- 8 files changed, 298 insertions(+), 460 deletions(-) delete mode 100644 cppnetlibConfigVersion.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a8c30da83..c77e8c488 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,8 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -cmake_minimum_required(VERSION 2.8) -project(CPP-NETLIB) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +project(CPP-NETLIB CXX) option( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF ) option( CPP-NETLIB_BUILD_TESTS "Build the cpp-netlib project tests." ON) @@ -42,22 +42,25 @@ endif() # Use Boost's static libraries if (CPP-NETLIB_STATIC_BOOST) set(Boost_USE_STATIC_LIBS ON) +else() + # We need this for all tests to use the dynamic version. + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS BOOST_ALL_DYN_LINK) endif() -# We need this for all tests to use the dynamic version. -add_definitions(-DBOOST_TEST_DYN_LINK) +# The interface target for public usage requirements +add_library(cppnetlib INTERFACE) # Always use multi-threaded Boost libraries. -set(Boost_USE_MULTI_THREADED ON) +set(Boost_USE_MULTITHREADED ON) -find_package(Boost 1.58.0 REQUIRED COMPONENTS system thread) +find_package(Boost 1.58.0 REQUIRED COMPONENTS system thread regex) if (CPP-NETLIB_ENABLE_HTTPS) if (APPLE) # If we're on OS X check for Homebrew's copy of OpenSSL instead of Apple's if (NOT OpenSSL_DIR) find_program(HOMEBREW brew) - if (HOMEBREW STREQUAL "HOMEBREW-NOTFOUND") + if (NOT HOMEBREW) message(WARNING "Homebrew not found: not using Homebrew's OpenSSL") if (NOT OPENSSL_ROOT_DIR) message(WARNING "Use -DOPENSSL_ROOT_DIR for non-Apple OpenSSL") @@ -69,13 +72,19 @@ if (CPP-NETLIB_ENABLE_HTTPS) endif() endif() endif() + + if (CPP-NETLIB_STATIC_OPENSSL) + set(OPENSSL_USE_STATIC_LIBS TRUE) + endif() + + find_package(OpenSSL REQUIRED) + target_compile_definitions(cppnetlib INTERFACE BOOST_NETWORK_ENABLE_HTTPS) if (CPP-NETLIB_STATIC_OPENSSL) - set(CMAKE_FIND_LIBRARY_SUFFIXES .a) + target_link_libraries(cppnetlib INTERFACE ${CMAKE_DL_LIBS}) endif() - find_package(OpenSSL) endif() -find_package( Threads ) + set(CMAKE_VERBOSE_MAKEFILE true) set(CPPNETLIB_VERSION_MAJOR 0) # MUST bump this whenever we make ABI-incompatible changes @@ -83,95 +92,114 @@ set(CPPNETLIB_VERSION_MINOR 13) set(CPPNETLIB_VERSION_PATCH 0) set(CPPNETLIB_VERSION_STRING ${CPPNETLIB_VERSION_MAJOR}.${CPPNETLIB_VERSION_MINOR}.${CPPNETLIB_VERSION_PATCH}) -if (CMAKE_BUILD_TYPE MATCHES Debug) - add_definitions(-DBOOST_NETWORK_DEBUG) -endif() +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$:BOOST_NETWORK_DEBUG>) -if (OPENSSL_FOUND) - add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS) - include_directories(${OPENSSL_INCLUDE_DIR}) +# Use C++11 +if (CMAKE_VERSION VERSION_LESS 3.8) + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED ON) +else() + target_compile_features(cppnetlib INTERFACE cxx_std_11) endif() -if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) - # Use C++11 when using GNU compilers. - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") -elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang) - # We want to link in C++11 mode in Clang too, but also set a high enough - # template depth for the template metaprogramming. - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ftemplate-depth=256 -std=c++11") - if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + add_compile_options(-Wall) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # A high enough template depth for the template metaprogramming. + add_compile_options(-Wall -ftemplate-depth=256) + if (CMAKE_SYSTEM_NAME MATCHES "Darwin") # Use libc++ only in OS X. - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++") + add_compile_options(-stdlib=libc++) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++") endif() endif() -if (MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") - set(gtest_force_shared_crt true) +if (WIN32) + target_compile_definitions(cppnetlib INTERFACE _WIN32_WINNT=0x0501) + + if (MSVC) + target_compile_options(cppnetlib INTERFACE /bigobj) + target_compile_definitions(cppnetlib INTERFACE _SCL_SECURE_NO_WARNINGS) + endif() + + if (MINGW) + target_link_libraries(cppnetlib INTERFACE ws2_32 wsock32) + endif() endif() -if (Boost_FOUND) - if (MSVC) - add_definitions(-D_SCL_SECURE_NO_WARNINGS) - endif(MSVC) - if (WIN32) - add_definitions(-D_WIN32_WINNT=0x0501) - endif(WIN32) - include_directories(${Boost_INCLUDE_DIRS}) - link_directories(${Boost_LIBRARY_DIRS}) - - enable_testing() - add_subdirectory(libs/network/src) - if (CPP-NETLIB_BUILD_TESTS) - add_subdirectory(deps/googletest) - add_subdirectory(libs/network/test) - endif (CPP-NETLIB_BUILD_TESTS) - if (CPP-NETLIB_BUILD_EXAMPLES) - add_subdirectory(libs/network/example) - endif (CPP-NETLIB_BUILD_EXAMPLES) -endif(Boost_FOUND) - -enable_testing() - -set(CPP-NETLIB_LIBRARIES ${Boost_LIBRARIES} CACHE INTERNAL "Dependent libraries for header-only use") - -install(DIRECTORY boost DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - -### -## Export Targets -# (so cpp-netlib can be easily used by other CMake projects) -# [see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file] - -# Add all targets to the build-tree export set -export(TARGETS cppnetlib-client-connections cppnetlib-server-parsers cppnetlib-uri - FILE "${PROJECT_BINARY_DIR}/cppnetlibTargets.cmake") -# Export the package for use from the build-tree -# (this registers the build-tree with a global CMake-registry) -export(PACKAGE cppnetlib) -# Create the cppnetlibConfig.cmake and cppnetlibConfigVersion files -file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" - "${CMAKE_INSTALL_FULL_INCLUDEDIR}") -# ... for the build tree -set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" ${Boost_INCLUDE_DIRS}) -configure_file(cppnetlibConfig.cmake.in - "${PROJECT_BINARY_DIR}/cppnetlibConfig.cmake" @ONLY) -# ... for the install tree -set(CONF_INCLUDE_DIRS "\${CPPNETLIB_CMAKE_DIR}/${REL_INCLUDE_DIR}") -set(CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +target_include_directories(cppnetlib INTERFACE + $ + $) + +find_package(Threads REQUIRED) +target_link_libraries(cppnetlib INTERFACE Boost::thread Threads::Threads) + +install(TARGETS cppnetlib EXPORT cppnetlibTargets) + +add_subdirectory(libs/network/src) + +add_library(cppnetlib::cppnetlib ALIAS cppnetlib) +add_library(cppnetlib::uri ALIAS uri) +add_library(cppnetlib::server-parsers ALIAS server-parsers) +add_library(cppnetlib::client-connections ALIAS client-connections) + +if (CPP-NETLIB_BUILD_TESTS) + enable_testing() + + if (MSVC) + set(gtest_force_shared_crt ON CACHE BOOL "Use shared (DLL) run-time lib even when Google Test is built as static lib.") + endif() + + add_subdirectory(deps/googletest) + + if (MSVC) + target_compile_definitions(gtest PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) + target_compile_definitions(gtest_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) + target_compile_definitions(gmock PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) + target_compile_definitions(gmock_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) + endif() + + add_subdirectory(libs/network/test) +endif() + +if (CPP-NETLIB_BUILD_EXAMPLES) + add_library(cxxopts INTERFACE) + target_include_directories(cxxopts INTERFACE deps/cxxopts/src) + + add_subdirectory(libs/network/example) +endif () + +install(DIRECTORY boost DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT dev) + +### +## Export Targets +# (so cpp-netlib can be easily used by other CMake projects) +# [see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file] + +# Add all targets to the build-tree export set +export(EXPORT cppnetlibTargets + FILE "${CMAKE_CURRENT_BINARY_DIR}/cppnetlibTargets.cmake" + NAMESPACE cppnetlib::) configure_file(cppnetlibConfig.cmake.in - "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake" @ONLY) -# ... for both -configure_file(cppnetlibConfigVersion.cmake.in - "${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake" @ONLY) -# Install the cppnetlibConfig.cmake and cppnetlibConfigVersion.cmake + "${CMAKE_CURRENT_BINARY_DIR}/cppnetlibConfig.cmake" @ONLY) + +# Export the package for use from the build-tree +# (this registers the build-tree with a global CMake-registry) +export(PACKAGE cppnetlib) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file(cppnetlibConfigVersion.cmake VERSION ${CPPNETLIB_VERSION_STRING} COMPATIBILITY AnyNewerVersion) + +# Install the cppnetlibConfig.cmake and cppnetlibConfigVersion.cmake install(FILES - "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake" - "${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake" + "${PROJECT_BINARY_DIR}/cppnetlibConfig.cmake" + "${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake" DESTINATION "${INSTALL_CMAKE_DIR}" - COMPONENT dev) -# Install the export set for use with the install-tree -install(EXPORT cppnetlibTargets - DESTINATION "${INSTALL_CMAKE_DIR}" - COMPONENT dev) + COMPONENT dev) + +# Install the export set for use with the install-tree +install(EXPORT cppnetlibTargets + FILE cppnetlibTargets.cmake + NAMESPACE cppnetlib:: + DESTINATION "${INSTALL_CMAKE_DIR}") \ No newline at end of file diff --git a/cppnetlibConfig.cmake.in b/cppnetlibConfig.cmake.in index 952a5f63f..daf3b6e5e 100644 --- a/cppnetlibConfig.cmake.in +++ b/cppnetlibConfig.cmake.in @@ -1,24 +1,38 @@ -# - Config file for the cppnetlib package -# It defines the following variables -# CPPNETLIB_INCLUDE_DIRS - include directories for cppnetlib -# CPPNETLIB_LIBRARIES - libraries to link against -# CPPNETLIB_EXECUTABLE - the bar executable - -# Compute paths -get_filename_component(CPPNETLIB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -set(CPPNETLIB_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") - -# Our library dependencies (contains definitions for IMPORTED targets) -if( NOT TARGET cppnetlib-client-connections - AND NOT TARGET cppnetlib-server-parsers - AND NOT TARGET cppnetlib-uri - AND NOT CPPNETLIB_BINARY_DIR) - include("${CPPNETLIB_CMAKE_DIR}/cppnetlibTargets.cmake") +# - Config file for the cppnetlib package +# It defines the following variables targets +# cppnetlib::cppnetlib - include directories and usage requirements for cppnetlib +# Libraries and usage requirements^ +# cppnetlib::uri +# cppnetlib::server-parsers +# cppnetlib::client-connections +# Variables +# CPPNETLIB_INCLUDE_DIRS - include directories for cppnetlib (empty, usage requirements propageted through libraries) +# CPPNETLIB_LIBRARIES - libraries to link against + +set(CPP-NETLIB_STATIC_BOOST @CPP-NETLIB_STATIC_BOOST@) +set(CPP-NETLIB_ENABLE_HTTPS @CPP-NETLIB_ENABLE_HTTPS@) +set(CPP-NETLIB_STATIC_OPENSSL @CPP-NETLIB_STATIC_OPENSSL@) + +# Use Boost's static libraries +if (CPP-NETLIB_STATIC_BOOST) + set(Boost_USE_STATIC_LIBS ON) +endif() + +# Always use multi-threaded Boost libraries. +set(Boost_USE_MULTITHREADED ON) + +if (CPP-NETLIB_ENABLE_HTTPS) + if (CPP-NETLIB_STATIC_OPENSSL) + set(OPENSSL_USE_STATIC_LIBS TRUE) + endif() + + find_package(OpenSSL REQUIRED) endif() -# These are IMPORTED targets created by cppnetlibTargets.cmake -set(CPPNETLIB_LIBRARIES - cppnetlib-client-connections - cppnetlib-server-parsers - cppnetlib-uri) -#set(CPPNETLIB_EXECUTABLE ...) # maybe the examples? +find_package(Boost 1.58.0 REQUIRED COMPONENTS system thread regex) +find_package(Threads) + +include("${CMAKE_CURRENT_LIST_DIR}/cppnetlibTargets.cmake") + +set(CPPNETLIB_INCLUDE_DIRS) +set(CPPNETLIB_LIBRARIES cppnetlib::client-connections cppnetlib::server-parsers cppnetlib::uri) \ No newline at end of file diff --git a/cppnetlibConfigVersion.cmake.in b/cppnetlibConfigVersion.cmake.in deleted file mode 100644 index e459ca324..000000000 --- a/cppnetlibConfigVersion.cmake.in +++ /dev/null @@ -1,11 +0,0 @@ -set(PACKAGE_VERSION "@CPPNETLIB_VERSION_STRING@") - -# Check whether the requested PACKAGE_FIND_VERSION is compatible -if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() \ No newline at end of file diff --git a/libs/network/example/CMakeLists.txt b/libs/network/example/CMakeLists.txt index 12530fa82..98176b277 100644 --- a/libs/network/example/CMakeLists.txt +++ b/libs/network/example/CMakeLists.txt @@ -3,11 +3,8 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -include_directories(${CPP-NETLIB_SOURCE_DIR}) -include_directories(${CPP-NETLIB_SOURCE_DIR}/deps/cxxopts/src) -if (OPENSSL_FOUND) - include_directories(${OPENSSL_INCLUDE_DIR}) -endif (OPENSSL_FOUND) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +project(cpp-netlib-examples CXX) add_executable(http_client http_client.cpp) add_executable(simple_wget simple_wget.cpp) @@ -20,136 +17,32 @@ add_executable(trivial_google trivial_google.cpp) if (UNIX) add_executable(fileserver http/fileserver.cpp) + target_link_libraries(fileserver PRIVATE cppnetlib::server-parsers) + set_target_properties(fileserver PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) + add_executable(async_server_file_upload http/async_server_file_upload.cpp) - add_dependencies(async_server_file_upload cppnetlib-server-parsers) + target_link_libraries(async_server_file_upload PRIVATE cppnetlib::server-parsers) + set_target_properties(async_server_file_upload PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) endif (UNIX) -add_dependencies(http_client cppnetlib-uri cppnetlib-client-connections) -add_dependencies(simple_wget cppnetlib-uri cppnetlib-client-connections) -add_dependencies(atom_reader cppnetlib-uri cppnetlib-client-connections) -add_dependencies(rss_reader cppnetlib-uri cppnetlib-client-connections) -add_dependencies(trivial_google cppnetlib-uri cppnetlib-client-connections) - -target_link_libraries(http_client - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-uri - cppnetlib-client-connections) - -target_link_libraries(simple_wget - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-uri - cppnetlib-client-connections) - -target_link_libraries(atom_reader - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-uri - cppnetlib-client-connections) -target_link_libraries(rss_reader - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-uri - cppnetlib-client-connections) +find_package(Boost 1.58.0 REQUIRED COMPONENTS program_options) -target_link_libraries(trivial_google - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-uri - cppnetlib-client-connections) +target_link_libraries(http_client PRIVATE cppnetlib::uri cppnetlib::client-connections cxxopts Boost::program_options) +target_link_libraries(simple_wget PRIVATE cppnetlib::uri cppnetlib::client-connections) +target_link_libraries(atom_reader PRIVATE cppnetlib::uri cppnetlib::client-connections) +target_link_libraries(rss_reader PRIVATE cppnetlib::uri cppnetlib::client-connections) +target_link_libraries(trivial_google PRIVATE cppnetlib::uri cppnetlib::client-connections) -target_link_libraries(hello_world_server - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-server-parsers) +target_link_libraries(hello_world_server PRIVATE cppnetlib::server-parsers) +target_link_libraries(hello_world_client PRIVATE cppnetlib::uri cppnetlib::client-connections) +target_link_libraries(hello_world_async_server_with_work_queue PRIVATE cppnetlib::uri cppnetlib::client-connections cppnetlib::server-parsers) -target_link_libraries(hello_world_client - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-uri - cppnetlib-client-connections) - -target_link_libraries(hello_world_async_server_with_work_queue - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-uri - cppnetlib-client-connections - cppnetlib-server-parsers) - -if (OPENSSL_FOUND) - add_executable(ssl_server http/ssl/ssl_server.cpp) - add_dependencies(ssl_server cppnetlib-uri cppnetlib-client-connections) - target_link_libraries(ssl_server - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-server-parsers - cppnetlib-uri - cppnetlib-client-connections) -endif (OPENSSL_FOUND) - - -if (OPENSSL_FOUND) - target_link_libraries(http_client ${OPENSSL_LIBRARIES}) - target_link_libraries(simple_wget ${OPENSSL_LIBRARIES}) - target_link_libraries(atom_reader ${OPENSSL_LIBRARIES}) - target_link_libraries(rss_reader ${OPENSSL_LIBRARIES}) - target_link_libraries(hello_world_server ${OPENSSL_LIBRARIES}) - target_link_libraries(hello_world_client ${OPENSSL_LIBRARIES}) - target_link_libraries(hello_world_async_server_with_work_queue ${OPENSSL_LIBRARIES}) - target_link_libraries(ssl_server ${OPENSSL_LIBRARIES}) - target_link_libraries(trivial_google ${OPENSSL_LIBRARIES}) -endif (OPENSSL_FOUND) - -if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(http_client ws2_32) - target_link_libraries(simple_wget ws2_32) - target_link_libraries(atom_reader ws2_32) - target_link_libraries(rss_reader ws2_32) - target_link_libraries(hello_world_server ws2_32 wsock32) - target_link_libraries(hello_world_client ws2_32) - target_link_libraries(hello_world_async_server_with_work_queue ws2_32 wsock32) - target_link_libraries(ssl_server ws2_32 wsock32) - target_link_libraries(trivial_google ws2_32) -endif() - -if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - target_link_libraries(http_client rt) - target_link_libraries(simple_wget rt) - target_link_libraries(atom_reader rt) - target_link_libraries(rss_reader rt) - target_link_libraries(hello_world_server rt) - target_link_libraries(hello_world_client rt) - target_link_libraries(hello_world_async_server_with_work_queue rt) - target_link_libraries(trivial_google rt) - if (OPENSSL_FOUND) - target_link_libraries(ssl_server rt) - endif (OPENSSL_FOUND) +if (TARGET OpenSSL::SSL) + add_executable(ssl_server http/ssl/ssl_server.cpp) + target_link_libraries(ssl_server PRIVATE cppnetlib::uri cppnetlib::client-connections cppnetlib::server-parsers) + set_target_properties(ssl_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) endif() -if (UNIX) - target_link_libraries(fileserver - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-server-parsers) - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - target_link_libraries(fileserver rt) - endif() - if (OPENSSL_FOUND) - target_link_libraries(fileserver ${OPENSSL_LIBRARIES}) - endif(OPENSSL_FOUND) - - target_link_libraries(async_server_file_upload - ${Boost_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - cppnetlib-server-parsers) - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - target_link_libraries(async_server_file_upload rt) - endif () - if (OPENSSL_FOUND) - target_link_libraries(async_server_file_upload ${OPENSSL_LIBRARIES}) - endif (OPENSSL_FOUND) -endif (UNIX) set_target_properties(http_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) set_target_properties(simple_wget PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) @@ -158,12 +51,4 @@ set_target_properties(rss_reader PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLI set_target_properties(trivial_google PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) set_target_properties(hello_world_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) set_target_properties(hello_world_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) -set_target_properties(hello_world_async_server_with_work_queue PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) -if (OPENSSL_FOUND) - set_target_properties(ssl_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) -endif (OPENSSL_FOUND) - -if (UNIX) - set_target_properties(fileserver PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) - set_target_properties(async_server_file_upload PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) -endif (UNIX) +set_target_properties(hello_world_async_server_with_work_queue PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example) \ No newline at end of file diff --git a/libs/network/src/CMakeLists.txt b/libs/network/src/CMakeLists.txt index b0c8a7813..158e6c32b 100644 --- a/libs/network/src/CMakeLists.txt +++ b/libs/network/src/CMakeLists.txt @@ -5,61 +5,51 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) - -include_directories(${CPP-NETLIB_SOURCE_DIR}) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +project(cppnetlib-libs CXX) file(GLOB_RECURSE CPP-NETLIB_HEADERS "${CPP-NETLIB_SOURCE_DIR}/boost/" "*.hpp") -set(CPP-NETLIB_URI_SRCS uri/uri.cpp uri/schemes.cpp) -add_definitions("-DBOOST_SPIRIT_THREADSAFE") -add_library(cppnetlib-uri ${CPP-NETLIB_URI_SRCS}) -set_target_properties(cppnetlib-uri - PROPERTIES VERSION ${CPPNETLIB_VERSION_STRING} - SOVERSION ${CPPNETLIB_VERSION_MAJOR} - PUBLIC_HEADER "${CPP-NETLIB_HEADERS}") -install(TARGETS cppnetlib-uri - EXPORT cppnetlibTargets - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) - -set(CPP-NETLIB_HTTP_SERVER_SRCS server_request_parsers_impl.cpp) -add_library(cppnetlib-server-parsers ${CPP-NETLIB_HTTP_SERVER_SRCS}) -set_target_properties(cppnetlib-server-parsers +add_library(uri uri/uri.cpp uri/schemes.cpp) +target_compile_definitions(uri PRIVATE BOOST_SPIRIT_THREADSAFE) +target_link_libraries(uri PUBLIC cppnetlib Boost::system) +set_target_properties(uri PROPERTIES VERSION ${CPPNETLIB_VERSION_STRING} SOVERSION ${CPPNETLIB_VERSION_MAJOR} PUBLIC_HEADER "${CPP-NETLIB_HEADERS}") -install(TARGETS cppnetlib-server-parsers - EXPORT cppnetlibTargets - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) +install(TARGETS uri + EXPORT cppnetlibTargets + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) -set(CPP-NETLIB_HTTP_CLIENT_SRCS client.cpp) -add_library(cppnetlib-client-connections ${CPP-NETLIB_HTTP_CLIENT_SRCS}) -set_target_properties(cppnetlib-client-connections +add_library(server-parsers server_request_parsers_impl.cpp) +target_link_libraries(server-parsers PUBLIC cppnetlib) +if (TARGET OpenSSL::SSL) + target_link_libraries(server-parsers PUBLIC OpenSSL::SSL) +endif() +set_target_properties(server-parsers PROPERTIES VERSION ${CPPNETLIB_VERSION_STRING} SOVERSION ${CPPNETLIB_VERSION_MAJOR} PUBLIC_HEADER "${CPP-NETLIB_HEADERS}") -target_link_libraries(cppnetlib-client-connections ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) -if (OPENSSL_FOUND) - target_link_libraries(cppnetlib-client-connections ${OPENSSL_LIBRARIES}) - if (CPP-NETLIB_STATIC_OPENSSL) - if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") - set(BSD ON) - endif() - if (NOT MSVC AND NOT MINGW AND NOT BSD) # dynlinker functions are built into libc on BSD - target_link_libraries(cppnetlib-client-connections "-ldl") - endif() - endif() -endif () -if (MINGW) - target_link_libraries(cppnetlib-client-connections ws2_32) -endif () +install(TARGETS server-parsers + EXPORT cppnetlibTargets + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) -install(TARGETS cppnetlib-client-connections - EXPORT cppnetlibTargets - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) +add_library(client-connections client.cpp) +target_link_libraries(client-connections PUBLIC cppnetlib Boost::regex) +if (TARGET OpenSSL::SSL) + target_link_libraries(client-connections PUBLIC OpenSSL::SSL) +endif() +set_target_properties(client-connections + PROPERTIES VERSION ${CPPNETLIB_VERSION_STRING} + SOVERSION ${CPPNETLIB_VERSION_MAJOR} + PUBLIC_HEADER "${CPP-NETLIB_HEADERS}") +install(TARGETS client-connections + EXPORT cppnetlibTargets + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) \ No newline at end of file diff --git a/libs/network/test/CMakeLists.txt b/libs/network/test/CMakeLists.txt index 99a3ca480..52dd3e400 100644 --- a/libs/network/test/CMakeLists.txt +++ b/libs/network/test/CMakeLists.txt @@ -4,38 +4,26 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -include_directories(${CPP-NETLIB_SOURCE_DIR} ${gtest_SOURCE_DIR}/include) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +project(cpp-netlib-tests CXX) add_subdirectory(uri) add_subdirectory(http) -if (Boost_FOUND) - set(TESTS message_test message_transform_test utils_thread_pool - # utils_base64_test -- turn on when ready. - ) - foreach (test ${TESTS}) - if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) - set_source_files_properties(${test}.cpp - PROPERTIES COMPILE_FLAGS "-Wall") - endif() - add_executable(cpp-netlib-${test} ${test}.cpp) - add_dependencies(cpp-netlib-${test} cppnetlib-uri gtest_main) - target_link_libraries(cpp-netlib-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri gtest_main) - if (OPENSSL_FOUND) - target_link_libraries(cpp-netlib-${test} ${OPENSSL_LIBRARIES}) - endif() - if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(cpp-netlib-${test} ws2_32 wsock32) - endif() - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - target_link_libraries(cpp-netlib-${test} rt) - endif() - set_target_properties(cpp-netlib-${test} - PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) - add_test(cpp-netlib-${test} - ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test}) - endforeach (test) +set(TESTS message_test message_transform_test utils_thread_pool +# utils_base64_test -- turn on when ready. +) - # Also copy the server directory to the root of the build directory. - file(COPY server DESTINATION ${CPP-NETLIB_BINARY_DIR}/libs/network/test/) -endif() +foreach (test ${TESTS}) + add_executable(cpp-netlib-${test} ${test}.cpp) + target_link_libraries(cpp-netlib-${test} PUBLIC + cppnetlib::uri gtest_main + $<$:rt> + ) + + set_target_properties(cpp-netlib-${test} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) + add_test(NAME cpp-netlib-${test} COMMAND cpp-netlib-${test}) +endforeach() + +file(COPY server DESTINATION ${CPP-NETLIB_BINARY_DIR}/libs/network/test/) \ No newline at end of file diff --git a/libs/network/test/http/CMakeLists.txt b/libs/network/test/http/CMakeLists.txt index 2948d5b92..874bc2570 100644 --- a/libs/network/test/http/CMakeLists.txt +++ b/libs/network/test/http/CMakeLists.txt @@ -4,106 +4,61 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -include_directories(${CPP-NETLIB_SOURCE_DIR}) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +project(cpp-netlib-http-tests) -if (OPENSSL_FOUND) - include_directories( ${OPENSSL_INCLUDE_DIR} ) - add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS) -endif() +set(TESTS response_incremental_parser_test request_incremental_parser_test + request_linearize_test) +foreach ( test ${TESTS} ) + add_executable(cpp-netlib-http-${test} ${test}.cpp) + target_link_libraries(cpp-netlib-http-${test} PUBLIC + cppnetlib::uri gtest_main + $<$:rt> + ) -if (Boost_FOUND) - set(TESTS response_incremental_parser_test request_incremental_parser_test - request_linearize_test) - foreach ( test ${TESTS} ) - add_executable(cpp-netlib-http-${test} ${test}.cpp) - add_dependencies(cpp-netlib-http-${test} gtest_main - cppnetlib-uri) - target_link_libraries(cpp-netlib-http-${test} - ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} gtest_main - ${CMAKE_THREAD_LIBS_INIT} gtest_main - cppnetlib-uri) - if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(cpp-netlib-http-${test} ws2_32) - endif() - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - target_link_libraries(cpp-netlib-http-${test} rt) - endif() - set_target_properties(cpp-netlib-http-${test} - PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) - add_test(cpp-netlib-http-${test} - ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test}) - endforeach (test) - set(TESTS - client_constructor_test - client_get_test - client_get_different_port_test - # client_get_timeout_test - client_get_ready_test - client_get_streaming_test) - foreach ( test ${TESTS} ) - add_executable(cpp-netlib-http-${test} ${test}.cpp) - add_dependencies(cpp-netlib-http-${test} cppnetlib-uri - cppnetlib-client-connections gtest_main) - target_link_libraries(cpp-netlib-http-${test} - ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri gtest_main cppnetlib-client-connections) - if (OPENSSL_FOUND) - target_link_libraries(cpp-netlib-http-${test} ${OPENSSL_LIBRARIES}) - endif() - if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(cpp-netlib-http-${test} ws2_32) - endif() - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - target_link_libraries(cpp-netlib-http-${test} rt) - endif() - set_target_properties(cpp-netlib-http-${test} - PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) - add_test(cpp-netlib-http-${test} - ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test}) - endforeach (test) + set_target_properties(cpp-netlib-http-${test} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) + add_test(NAME cpp-netlib-http-${test} COMMAND cpp-netlib-http-${test}) +endforeach() - set(SERVER_API_TESTS server_constructor_test - server_header_parser_test) - foreach (test ${SERVER_API_TESTS}) - add_executable(cpp-netlib-http-${test} ${test}.cpp) - add_dependencies(cpp-netlib-http-${test} cppnetlib-server-parsers) - target_link_libraries(cpp-netlib-http-${test} - ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers gtest_main) - if (OPENSSL_FOUND) - target_link_libraries(cpp-netlib-http-${test} ${OPENSSL_LIBRARIES}) - endif() - if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(cpp-netlib-http-${test} ws2_32 wsock32) - endif() - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - target_link_libraries(cpp-netlib-http-${test} rt) - endif() - set_target_properties(cpp-netlib-http-${test} - PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) - add_test(cpp-netlib-http-${test} - ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test}) - endforeach (test) +set(TESTS + client_constructor_test + client_get_test + client_get_different_port_test + # client_get_timeout_test + client_get_ready_test + client_get_streaming_test) +foreach ( test ${TESTS} ) + add_executable(cpp-netlib-http-${test} ${test}.cpp) + target_link_libraries(cpp-netlib-http-${test} PUBLIC + cppnetlib::uri cppnetlib::client-connections gtest_main + $<$:rt> + ) - # Add the server start/stop concurrency test - add_executable(cpp-netlib-http-server_async_run_stop_concurrency - server_async_run_stop_concurrency.cpp) - add_dependencies(cpp-netlib-http-server_async_run_stop_concurrency - cppnetlib-server-parsers) - target_link_libraries(cpp-netlib-http-server_async_run_stop_concurrency - ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers) - if (OPENSSL_FOUND) - target_link_libraries(cpp-netlib-http-server_async_run_stop_concurrency - ${OPENSSL_LIBRARIES}) - endif() - if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU - AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(cpp-netlib-http-server_async_run_stop_concurrency - ws2_32 wsock32) - endif() - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - target_link_libraries(cpp-netlib-http-server_async_run_stop_concurrency rt) - endif() - set_target_properties(cpp-netlib-http-server_async_run_stop_concurrency - PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) - add_test(cpp-netlib-http-server_async_run_stop_concurrency - ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-server_async_run_stop_concurrency) -endif() + set_target_properties(cpp-netlib-http-${test} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) + add_test(NAME cpp-netlib-http-${test} COMMAND cpp-netlib-http-${test}) +endforeach() + +set(SERVER_API_TESTS server_constructor_test + server_header_parser_test) +foreach (test ${SERVER_API_TESTS}) + add_executable(cpp-netlib-http-${test} ${test}.cpp) + target_link_libraries(cpp-netlib-http-${test} PUBLIC + cppnetlib::server-parsers gtest_main + $<$:rt> + ) + set_target_properties(cpp-netlib-http-${test} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) + add_test(NAME cpp-netlib-http-${test} COMMAND cpp-netlib-http-${test}) +endforeach() + +# Add the server start/stop concurrency test +add_executable(cpp-netlib-http-server_async_run_stop_concurrency server_async_run_stop_concurrency.cpp) +target_link_libraries(cpp-netlib-http-server_async_run_stop_concurrency PUBLIC + cppnetlib::server-parsers gtest_main + $<$:rt> +) +set_target_properties(cpp-netlib-http-server_async_run_stop_concurrency + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) +add_test(NAME cpp-netlib-http-server_async_run_stop_concurrency COMMAND cpp-netlib-http-server_async_run_stop_concurrency) \ No newline at end of file diff --git a/libs/network/test/uri/CMakeLists.txt b/libs/network/test/uri/CMakeLists.txt index 524ca90d8..fc7b0cf0e 100644 --- a/libs/network/test/uri/CMakeLists.txt +++ b/libs/network/test/uri/CMakeLists.txt @@ -4,31 +4,20 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -include_directories(${CPP-NETLIB_SOURCE_DIR}) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +project(cpp-netlib-uri-tests) -if (Boost_FOUND) - set(TESTS uri_test uri_builder_test uri_builder_stream_test - uri_encoding_test relative_uri_test) - foreach (test ${TESTS}) - if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) - set_source_files_properties(${test}.cpp - PROPERTIES COMPILE_FLAGS "-Wall") - endif() - add_executable(cpp-netlib-${test} ${test}.cpp) - add_dependencies(cpp-netlib-${test} cppnetlib-uri gtest_main) - target_link_libraries(cpp-netlib-${test} - ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri - gtest_main ${Boost_LIBRARIES}) - if (OPENSSL_FOUND) - target_link_libraries(cpp-netlib-${test} ${OPENSSL_LIBRARIES}) - endif() - if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU - AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(cpp-netlib-${test} ws2_32) - endif() - set_target_properties(cpp-netlib-${test} - PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) - add_test(cpp-netlib-${test} - ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test}) - endforeach (test) -endif() +set(TESTS uri_test uri_builder_test uri_builder_stream_test + uri_encoding_test relative_uri_test) + +foreach (test ${TESTS}) + add_executable(cpp-netlib-${test} ${test}.cpp) + target_link_libraries(cpp-netlib-${test} PUBLIC + cppnetlib::uri gtest_main + $<$:rt> + ) + + set_target_properties(cpp-netlib-${test} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) + add_test(NAME cpp-netlib-${test} COMMAND cpp-netlib-${test}) +endforeach() \ No newline at end of file From cbb10e6bd18a044d41c32153585852c84edee975 Mon Sep 17 00:00:00 2001 From: Tengiz Sharafiev Date: Sat, 24 Mar 2018 13:13:41 +0700 Subject: [PATCH 2/4] Build: fix build with Boost 1.66.0 --- boost/network/protocol/stream_handler.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/boost/network/protocol/stream_handler.hpp b/boost/network/protocol/stream_handler.hpp index 2231af0cf..3ded9ef16 100644 --- a/boost/network/protocol/stream_handler.hpp +++ b/boost/network/protocol/stream_handler.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #ifdef BOOST_NETWORK_ENABLE_HTTPS From 4a202d370873044084354b976c576d0430d88ef4 Mon Sep 17 00:00:00 2001 From: Tengiz Sharafiev Date: Wed, 14 Mar 2018 21:30:27 +0700 Subject: [PATCH 3/4] Work around ambiguous true_type Visual Studio 2017 cannot decide if it is boost::integral_constant boost::true_type or boost::spirit::true_type https://github.com/cpp-netlib/cpp-netlib/commit/a5252b9559466c67bb502c7b9985ff067a64bf63 --- .../protocol/http/server/impl/parsers.ipp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/boost/network/protocol/http/server/impl/parsers.ipp b/boost/network/protocol/http/server/impl/parsers.ipp index b3f733a75..1739d2650 100644 --- a/boost/network/protocol/http/server/impl/parsers.ipp +++ b/boost/network/protocol/http/server/impl/parsers.ipp @@ -49,22 +49,21 @@ namespace http { BOOST_NETWORK_INLINE void parse_version( std::string const& partial_parsed, std::tuple& version_pair) { - using namespace boost::spirit::qi; - parse(partial_parsed.begin(), partial_parsed.end(), - (lit("HTTP/") >> ushort_ >> '.' >> ushort_), version_pair); + boost::spirit::qi::parse(partial_parsed.begin(), partial_parsed.end(), + (boost::spirit::qi::lit("HTTP/") >> boost::spirit::qi::ushort_ >> '.' >> boost::spirit::qi::ushort_), version_pair); } BOOST_NETWORK_INLINE void parse_headers( std::string const& input, std::vector& container) { u8_to_u32_iterator begin = input.begin(), end = input.end(); - using namespace boost::spirit::qi; - typedef as as_u32_string; - parse(begin, end, - *(+((alnum | punct) - ':') >> lit(": ") >> - as_u32_string()[+((unicode::alnum | space | punct) - '\r' - '\n')] >> - lit("\r\n")) >> - lit("\r\n"), + + using as_u32_string = boost::spirit::qi::as; + boost::spirit::qi::parse(begin, end, + *(+((boost::spirit::qi::alnum | boost::spirit::qi::punct) - ':') >> boost::spirit::qi::lit(": ") >> + as_u32_string()[+((boost::spirit::qi::unicode::alnum | boost::spirit::qi::space | boost::spirit::qi::punct) - '\r' - '\n')] >> + boost::spirit::qi::lit("\r\n")) >> + boost::spirit::qi::lit("\r\n"), container); } From 48bbadb6448bfe0be895f3a0cdd9e07b1fcb80ea Mon Sep 17 00:00:00 2001 From: Tengiz Sharafiev Date: Sun, 1 Apr 2018 16:42:49 +0700 Subject: [PATCH 4/4] Build: Add cmake option CPP-NETLIB_WINAPI_VERSION This option allows us to setup _WIN32_WINNT definition value from cmake command line Default value is 0x0501 (_WIN32_WINNT_WINXP) https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c77e8c488..71210c0a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,10 @@ option( CPP-NETLIB_ENABLE_HTTPS "Build cpp-netlib with support for https if Open option( CPP-NETLIB_STATIC_OPENSSL "Build cpp-netlib using static OpenSSL" OFF) option( CPP-NETLIB_STATIC_BOOST "Build cpp-netlib using static Boost" OFF) +if (NOT DEFINED CPP-NETLIB_WINAPI_VERSION) + set(CPP-NETLIB_WINAPI_VERSION 0x0501) +endif() + include(GNUInstallDirs) # determine install path for CMake config files @@ -116,7 +120,7 @@ endif() if (WIN32) - target_compile_definitions(cppnetlib INTERFACE _WIN32_WINNT=0x0501) + target_compile_definitions(cppnetlib INTERFACE _WIN32_WINNT=${CPP-NETLIB_WINAPI_VERSION} BOOST_USE_WINAPI_VERSION=${CPP-NETLIB_WINAPI_VERSION}) if (MSVC) target_compile_options(cppnetlib INTERFACE /bigobj)