fix build option issues; refine cmake

master
Chunting Gu 5 years ago
parent 1c35b97654
commit 7f345b7a4e

@ -87,6 +87,8 @@ if(WEBCC_ENABLE_GZIP)
endif()
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_subdirectory(webcc)
if(BUILD_AUTOTEST OR BUILD_EXAMPLES)

@ -17,7 +17,8 @@ if(UNIX)
set(AT_LIBS ${AT_LIBS} ${CMAKE_DL_LIBS})
endif()
set(AT_TARGET_NAME webcc_autotest)
set(AT_TARGET_NAME autotest)
add_executable(${AT_TARGET_NAME} ${AT_SRCS})
target_link_libraries(${AT_TARGET_NAME} ${AT_LIBS})
set_target_properties(${AT_TARGET_NAME} PROPERTIES FOLDER "Tests")

@ -8,41 +8,34 @@ if(UNIX)
set(EXAMPLE_LIBS ${EXAMPLE_LIBS} ${CMAKE_DL_LIBS})
endif()
add_executable(concurrency_test concurrency_test.cc)
target_link_libraries(concurrency_test ${EXAMPLE_LIBS})
add_executable(client_basics client_basics.cc)
target_link_libraries(client_basics ${EXAMPLE_LIBS})
set(SIMPLE_EXAMPLES
concurrency_test
client_basics
hello_world_server
static_file_server
file_downloader
server_states
form_client
form_server
form_urlencoded_client
)
foreach(example ${SIMPLE_EXAMPLES})
add_executable(${example} ${example}.cc)
target_link_libraries(${example} ${EXAMPLE_LIBS})
set_target_properties(${example} PROPERTIES FOLDER "Examples")
endforeach()
if(WEBCC_ENABLE_SSL)
add_executable(github_client github_client.cc)
target_link_libraries(github_client ${EXAMPLE_LIBS} jsoncpp)
set_target_properties(github_client PROPERTIES FOLDER "Examples")
endif()
add_executable(hello_world_server hello_world_server.cc)
target_link_libraries(hello_world_server ${EXAMPLE_LIBS})
add_executable(static_file_server static_file_server.cc)
target_link_libraries(static_file_server ${EXAMPLE_LIBS})
add_executable(file_downloader file_downloader.cc)
target_link_libraries(file_downloader ${EXAMPLE_LIBS})
add_executable(server_states server_states.cc)
target_link_libraries(server_states ${EXAMPLE_LIBS})
add_executable(form_client form_client.cc)
target_link_libraries(form_client ${EXAMPLE_LIBS})
add_executable(form_urlencoded_client form_urlencoded_client.cc)
target_link_libraries(form_urlencoded_client ${EXAMPLE_LIBS})
add_executable(form_server form_server.cc)
target_link_libraries(form_server ${EXAMPLE_LIBS})
if(WIN32)
add_executable(url_unicode url_unicode.cc encoding.cc encoding.h)
target_link_libraries(url_unicode ${EXAMPLE_LIBS})
set_target_properties(url_unicode PROPERTIES FOLDER "Examples")
endif()
add_subdirectory(book_server)

@ -1,8 +1,8 @@
set(SRCS
book.cc
book.h
book_json.cc
book_json.h
book.cc
book.h
book_json.cc
book_json.h
book_client.cc
book_client.h
main.cc
@ -10,3 +10,4 @@ set(SRCS
add_executable(book_client ${SRCS})
target_link_libraries(book_client ${EXAMPLE_LIBS} jsoncpp)
set_target_properties(book_client PROPERTIES FOLDER "Examples")

@ -12,3 +12,4 @@ set(SRCS
add_executable(book_server ${SRCS})
target_link_libraries(book_server ${EXAMPLE_LIBS} jsoncpp)
set_target_properties(book_server PROPERTIES FOLDER "Examples")

@ -1,11 +1,10 @@
project(qt_app_server)
find_package(Qt5 CONFIG REQUIRED Core Gui Widgets)
set(CMAKE_AUTOMOC ON)
file(GLOB SRCS *.cpp *.h)
set(SRCS main.cc main_window.cc main_window.h)
add_executable(qt_app_server ${SRCS})
target_link_libraries(qt_app_server Qt5::Core Qt5::Gui Qt5::Widgets ${EXAMPLE_LIBS})
set_target_properties(qt_app_server PROPERTIES FOLDER "Examples")

@ -1,9 +1,16 @@
# Unit test
file(GLOB UT_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
set(UT_TARGET_NAME unittest)
set(UT_TARGET_NAME webcc_unittest)
set(UT_SRCS
base64_unittest.cc
body_unittest.cc
request_parser_unittest.cc
response_builder_unittest.cc
router_unittest.cc
string_unittest.cc
url_unittest.cc
)
# Common libraries to link.
set(UT_LIBS
@ -18,5 +25,6 @@ endif()
add_executable(${UT_TARGET_NAME} ${UT_SRCS})
target_link_libraries(${UT_TARGET_NAME} ${UT_LIBS})
set_target_properties(${UT_TARGET_NAME} PROPERTIES FOLDER "Tests")
add_test(${UT_TARGET_NAME} ${UT_TARGET_NAME})

@ -1,10 +1,10 @@
# webcc
# Don't use any deprecated definitions (e.g., io_service).
add_definitions(-DBOOST_ASIO_NO_DEPRECATED)
add_compile_definitions(BOOST_ASIO_NO_DEPRECATED)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
configure_file(

@ -5,7 +5,7 @@
#include "webcc/logger.h"
#include "webcc/utility.h"
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@ -15,7 +15,7 @@ namespace webcc {
// -----------------------------------------------------------------------------
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
bool StringBody::Compress() {
if (compressed_) {

@ -29,7 +29,7 @@ public:
return GetSize() == 0;
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Compress the data with Gzip.
// If data size <= threshold (1400 bytes), no compression will be taken
@ -90,7 +90,7 @@ public:
return compressed_;
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
bool Compress() override;

@ -78,7 +78,7 @@ void Client::Close() {
void Client::Connect(RequestPtr request) {
if (request->url().scheme() == "https") {
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
socket_.reset(new SslSocket{ io_context_, ssl_verify_ });
DoConnect(request, "443");
#else

@ -19,7 +19,7 @@ void ClientSession::Accept(const std::string& content_types) {
}
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Content-Encoding Tokens:
// (https://en.wikipedia.org/wiki/HTTP_compression)

@ -51,7 +51,7 @@ public:
// Set content types to accept.
void Accept(const std::string& content_types);
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Accept Gzip compressed response data or not.
void AcceptGzip(bool gzip = true);

@ -6,7 +6,7 @@
// Set 1/0 to enable/disable logging.
#define WEBCC_ENABLE_LOG 1
#ifdef WEBCC_ENABLE_LOG
#if WEBCC_ENABLE_LOG
// 0:VERB, 1:INFO, 2:USER, 3:WARN or 4:ERRO
#define WEBCC_LOG_LEVEL 2
#endif

@ -8,7 +8,7 @@
// Set 1/0 to enable/disable logging.
#define WEBCC_ENABLE_LOG @WEBCC_ENABLE_LOG@
#ifdef WEBCC_ENABLE_LOG
#if WEBCC_ENABLE_LOG
// 0:VERB, 1:INFO, 2:USER, 3:WARN or 4:ERRO
#define WEBCC_LOG_LEVEL @WEBCC_LOG_LEVEL@
#endif // WEBCC_ENABLE_LOG

@ -1,6 +1,6 @@
#include "webcc/logger.h"
#ifdef WEBCC_ENABLE_LOG
#if WEBCC_ENABLE_LOG
#include <cassert>
#include <chrono>

@ -4,7 +4,7 @@
// This file was generated from "config.h.in" by CMake.
#include "webcc/config.h"
#ifdef WEBCC_ENABLE_LOG
#if WEBCC_ENABLE_LOG
#include <cstring> // for strrchr()
#include <string>

@ -7,7 +7,7 @@
#include "webcc/string.h"
#include "webcc/utility.h"
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@ -48,7 +48,7 @@ bool StringBodyHandler::Finish() {
auto body = std::make_shared<StringBody>(std::move(content_), IsCompressed());
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
LOG_INFO("Decompress the HTTP content...");
if (!body->Decompress()) {
LOG_ERRO("Cannot decompress the HTTP content!");

@ -5,7 +5,7 @@
#include "webcc/string.h"
#include "webcc/utility.h"
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@ -32,7 +32,7 @@ RequestPtr RequestBuilder::operator()() {
if (body_) {
request->SetContentType(media_type_, charset_);
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
if (gzip_ && body_->Compress()) {
request->SetHeader(headers::kContentEncoding, "gzip");
}
@ -54,7 +54,7 @@ RequestPtr RequestBuilder::operator()() {
return request;
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Accept Gzip compressed response data or not.
RequestBuilder& RequestBuilder::AcceptGzip(bool gzip) {

@ -124,7 +124,7 @@ public:
return Header(headers::kAccept, content_types);
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Accept Gzip compressed response data or not.
RequestBuilder& AcceptGzip(bool gzip = true);
@ -179,7 +179,7 @@ public:
// Add the `Date` header to the request.
RequestBuilder& Date();
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Compress the body data (only for string body).
// NOTE:
@ -220,7 +220,7 @@ private:
// Persistent connection.
bool keep_alive_ = true;
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
bool gzip_ = false;
#endif // WEBCC_ENABLE_GZIP
};

@ -4,7 +4,7 @@
#include "webcc/logger.h"
#include "webcc/utility.h"
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@ -24,7 +24,7 @@ ResponsePtr ResponseBuilder::operator()() {
if (body_) {
response->SetContentType(media_type_, charset_);
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
if (gzip_) {
// Don't try to compress the response if the request doesn't accept gzip.
if (request_ && request_->AcceptEncodingGzip()) {

@ -109,7 +109,7 @@ public:
// Add the `Date` header to the response.
ResponseBuilder& Date();
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
ResponseBuilder& Gzip(bool gzip = true) {
gzip_ = gzip;
return *this;
@ -131,7 +131,7 @@ private:
// Character set of the body (e.g., "utf-8").
std::string charset_;
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Compress the body data (only for string body).
bool gzip_ = false;
#endif // WEBCC_ENABLE_GZIP

@ -1,6 +1,6 @@
#include "webcc/socket.h"
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
#if (defined(_WIN32) || defined(_WIN64))
#include <windows.h>
@ -75,7 +75,7 @@ bool Socket::Close() {
// -----------------------------------------------------------------------------
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
#if (defined(_WIN32) || defined(_WIN64))

@ -8,7 +8,7 @@
#include "webcc/config.h"
#include "webcc/request.h"
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
#include "boost/asio/ssl.hpp"
#endif // WEBCC_ENABLE_SSL
@ -62,7 +62,7 @@ private:
// -----------------------------------------------------------------------------
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
class SslSocket : public SocketBase {
public:

Loading…
Cancel
Save