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()
endif() endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_subdirectory(webcc) add_subdirectory(webcc)
if(BUILD_AUTOTEST OR BUILD_EXAMPLES) if(BUILD_AUTOTEST OR BUILD_EXAMPLES)

@ -17,7 +17,8 @@ if(UNIX)
set(AT_LIBS ${AT_LIBS} ${CMAKE_DL_LIBS}) set(AT_LIBS ${AT_LIBS} ${CMAKE_DL_LIBS})
endif() endif()
set(AT_TARGET_NAME webcc_autotest) set(AT_TARGET_NAME autotest)
add_executable(${AT_TARGET_NAME} ${AT_SRCS}) add_executable(${AT_TARGET_NAME} ${AT_SRCS})
target_link_libraries(${AT_TARGET_NAME} ${AT_LIBS}) 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}) set(EXAMPLE_LIBS ${EXAMPLE_LIBS} ${CMAKE_DL_LIBS})
endif() endif()
add_executable(concurrency_test concurrency_test.cc) set(SIMPLE_EXAMPLES
target_link_libraries(concurrency_test ${EXAMPLE_LIBS}) concurrency_test
client_basics
add_executable(client_basics client_basics.cc) hello_world_server
target_link_libraries(client_basics ${EXAMPLE_LIBS}) 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) if(WEBCC_ENABLE_SSL)
add_executable(github_client github_client.cc) add_executable(github_client github_client.cc)
target_link_libraries(github_client ${EXAMPLE_LIBS} jsoncpp) target_link_libraries(github_client ${EXAMPLE_LIBS} jsoncpp)
set_target_properties(github_client PROPERTIES FOLDER "Examples")
endif() 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) if(WIN32)
add_executable(url_unicode url_unicode.cc encoding.cc encoding.h) add_executable(url_unicode url_unicode.cc encoding.cc encoding.h)
target_link_libraries(url_unicode ${EXAMPLE_LIBS}) target_link_libraries(url_unicode ${EXAMPLE_LIBS})
set_target_properties(url_unicode PROPERTIES FOLDER "Examples")
endif() endif()
add_subdirectory(book_server) add_subdirectory(book_server)

@ -10,3 +10,4 @@ set(SRCS
add_executable(book_client ${SRCS}) add_executable(book_client ${SRCS})
target_link_libraries(book_client ${EXAMPLE_LIBS} jsoncpp) 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}) add_executable(book_server ${SRCS})
target_link_libraries(book_server ${EXAMPLE_LIBS} jsoncpp) 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) find_package(Qt5 CONFIG REQUIRED Core Gui Widgets)
set(CMAKE_AUTOMOC ON) 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}) add_executable(qt_app_server ${SRCS})
target_link_libraries(qt_app_server Qt5::Core Qt5::Gui Qt5::Widgets ${EXAMPLE_LIBS}) 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 # Unit test
file(GLOB UT_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} set(UT_TARGET_NAME unittest)
${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
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. # Common libraries to link.
set(UT_LIBS set(UT_LIBS
@ -18,5 +25,6 @@ endif()
add_executable(${UT_TARGET_NAME} ${UT_SRCS}) add_executable(${UT_TARGET_NAME} ${UT_SRCS})
target_link_libraries(${UT_TARGET_NAME} ${UT_LIBS}) 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}) add_test(${UT_TARGET_NAME} ${UT_TARGET_NAME})

@ -1,10 +1,10 @@
# webcc # webcc
# Don't use any deprecated definitions (e.g., io_service). # 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) if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif() endif()
configure_file( configure_file(

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

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

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

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

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

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

@ -8,7 +8,7 @@
// Set 1/0 to enable/disable logging. // Set 1/0 to enable/disable logging.
#define WEBCC_ENABLE_LOG @WEBCC_ENABLE_LOG@ #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 // 0:VERB, 1:INFO, 2:USER, 3:WARN or 4:ERRO
#define WEBCC_LOG_LEVEL @WEBCC_LOG_LEVEL@ #define WEBCC_LOG_LEVEL @WEBCC_LOG_LEVEL@
#endif // WEBCC_ENABLE_LOG #endif // WEBCC_ENABLE_LOG

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save