refine the usage of build options

master
Chunting Gu 5 years ago
parent 233aa5910c
commit 1b8b0b24ac

@ -20,10 +20,10 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${BUILD_DIR}/bin/release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${BUILD_DIR}/bin/release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BUILD_DIR}/bin/release)
option(WEBCC_ENABLE_AUTOTEST "Build automation test?" OFF)
option(WEBCC_ENABLE_UNITTEST "Build unit test?" OFF)
option(WEBCC_ENABLE_EXAMPLES "Build examples?" ON)
option(WEBCC_ENABLE_QT_EXAMPLES "Build Qt application examples?" OFF)
option(BUILD_AUTOTEST "Build automation test?" OFF)
option(BUILD_UNITTEST "Build unit test?" OFF)
option(BUILD_EXAMPLES "Build examples?" ON)
option(BUILD_QT_EXAMPLES "Build Qt application examples?" OFF)
set(WEBCC_ENABLE_LOG 1 CACHE STRING "Enable logging? (1:Yes, 0:No)")
set(WEBCC_ENABLE_SSL 0 CACHE STRING "Enable SSL/HTTPS (need OpenSSL)? (1:Yes, 0:No)")
@ -31,14 +31,14 @@ set(WEBCC_ENABLE_GZIP 0 CACHE STRING "Enable gzip compression (need Zlib)? (1:Y
set(WEBCC_LOG_LEVEL 2 CACHE STRING "Log level (0:VERB, 1:INFO, 2:USER, 3:WARN or 4:ERRO)")
if(WEBCC_ENABLE_UNITTEST)
if(BUILD_UNITTEST)
enable_testing()
endif()
if(WIN32)
# Asio needs this!
# 0x0601 means Win7. So our application targets Win7 and above.
add_definitions(-D_WIN32_WINNT=0x0601)
add_compile_definitions(_WIN32_WINNT=0x0601)
endif()
# C++ standard requirements.
@ -89,7 +89,7 @@ endif()
add_subdirectory(webcc)
if(WEBCC_ENABLE_AUTOTEST OR WEBCC_ENABLE_EXAMPLES)
if(BUILD_AUTOTEST OR BUILD_EXAMPLES)
# For including jsoncpp as "json/json.h".
include_directories(${THIRD_PARTY_DIR}/src/jsoncpp)
@ -97,7 +97,7 @@ if(WEBCC_ENABLE_AUTOTEST OR WEBCC_ENABLE_EXAMPLES)
endif()
# GTest
if(WEBCC_ENABLE_AUTOTEST OR WEBCC_ENABLE_UNITTEST)
if(BUILD_AUTOTEST OR BUILD_UNITTEST)
find_package(GTest REQUIRED)
if(GTEST_FOUND)
add_definitions(-DGTEST_LANG_CXX11=1)
@ -105,14 +105,14 @@ if(WEBCC_ENABLE_AUTOTEST OR WEBCC_ENABLE_UNITTEST)
endif()
endif()
if(WEBCC_ENABLE_AUTOTEST)
if(BUILD_AUTOTEST)
add_subdirectory(autotest)
endif()
if(WEBCC_ENABLE_UNITTEST)
if(BUILD_UNITTEST)
add_subdirectory(unittest)
endif()
if(WEBCC_ENABLE_EXAMPLES)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

@ -141,7 +141,9 @@ $ ls -l /usr/local/lib/libboost*
### Googletest
TODO
```
$ sudo apt install libgtest-dev
```
### Webcc
@ -156,13 +158,14 @@ $ cd build
```
$ cmake -G"Unix Makefiles" \
-DBUILD_AUTOTEST=OFF \
-DBUILD_UNITTEST=OFF \
-DBUILD_EXAMPLES=ON \
-DBUILD_QT_EXAMPLES=OFF \
-DWEBCC_ENABLE_LOG=1 \
-DWEBCC_LOG_LEVEL=0 \
-DWEBCC_ENABLE_SSL=1 \
-DWEBCC_ENABLE_GZIP=1 \
-DWEBCC_ENABLE_AUTOTEST=OFF \
-DWEBCC_ENABLE_UNITTEST=OFF \
-DWEBCC_ENABLE_EXAMPLES=ON \
..
```

@ -48,6 +48,6 @@ endif()
add_subdirectory(book_server)
add_subdirectory(book_client)
if(WEBCC_ENABLE_QT_EXAMPLES)
if(BUILD_QT_EXAMPLES)
add_subdirectory(qt_app_server)
endif()

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

@ -29,7 +29,7 @@ public:
return GetSize() == 0;
}
#if WEBCC_ENABLE_GZIP
#ifdef 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_;
}
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
bool Compress() override;

@ -78,7 +78,7 @@ void Client::Close() {
void Client::Connect(RequestPtr request) {
if (request->url().scheme() == "https") {
#if WEBCC_ENABLE_SSL
#ifdef 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) {
}
}
#if WEBCC_ENABLE_GZIP
#ifdef 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);
#if WEBCC_ENABLE_GZIP
#ifdef 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
#if WEBCC_ENABLE_LOG
#ifdef 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@
#if WEBCC_ENABLE_LOG
#ifdef 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"
#if WEBCC_ENABLE_LOG
#ifdef 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"
#if WEBCC_ENABLE_LOG
#ifdef WEBCC_ENABLE_LOG
#include <cstring> // for strrchr()
#include <string>

@ -7,7 +7,7 @@
#include "webcc/string.h"
#include "webcc/utility.h"
#if WEBCC_ENABLE_GZIP
#ifdef 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());
#if WEBCC_ENABLE_GZIP
#ifdef 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"
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@ -32,7 +32,7 @@ RequestPtr RequestBuilder::operator()() {
if (body_) {
request->SetContentType(media_type_, charset_);
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
if (gzip_ && body_->Compress()) {
request->SetHeader(headers::kContentEncoding, "gzip");
}
@ -54,7 +54,7 @@ RequestPtr RequestBuilder::operator()() {
return request;
}
#if WEBCC_ENABLE_GZIP
#ifdef 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);
}
#if WEBCC_ENABLE_GZIP
#ifdef 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();
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
// Compress the body data (only for string body).
// NOTE:
@ -220,7 +220,7 @@ private:
// Persistent connection.
bool keep_alive_ = true;
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
bool gzip_ = false;
#endif // WEBCC_ENABLE_GZIP
};

@ -4,7 +4,7 @@
#include "webcc/logger.h"
#include "webcc/utility.h"
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@ -24,7 +24,7 @@ ResponsePtr ResponseBuilder::operator()() {
if (body_) {
response->SetContentType(media_type_, charset_);
#if WEBCC_ENABLE_GZIP
#ifdef 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();
#if WEBCC_ENABLE_GZIP
#ifdef 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_;
#if WEBCC_ENABLE_GZIP
#ifdef 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"
#if WEBCC_ENABLE_SSL
#ifdef WEBCC_ENABLE_SSL
#if (defined(_WIN32) || defined(_WIN64))
#include <windows.h>
@ -75,7 +75,7 @@ bool Socket::Close() {
// -----------------------------------------------------------------------------
#if WEBCC_ENABLE_SSL
#ifdef WEBCC_ENABLE_SSL
#if (defined(_WIN32) || defined(_WIN64))

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

Loading…
Cancel
Save