Skip to content

Commit

Permalink
cleanup cmake boost deps
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Sep 11, 2022
1 parent a5b73c0 commit 3ec6862
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
24 changes: 15 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ cmake_minimum_required(VERSION 3.14)

project(winasio)

# format
include(cmake/clang-format.cmake)
if(WINASIO_CI_FORMAT)
message(STATUS "Only added format target.")
return()
endif()

set(winasio_MAIN_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(winasio_MAIN_PROJECT ON)
Expand All @@ -17,21 +10,34 @@ endif()
option(winasio_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${winasio_MAIN_PROJECT})
option(winasio_BuildExamples "Build examples" ${winasio_MAIN_PROJECT})

# format
if(${winasio_MAIN_PROJECT})
include(cmake/clang-format.cmake)
if(WINASIO_CI_FORMAT)
message(STATUS "Only added format target.")
return()
endif()
endif(${winasio_MAIN_PROJECT})


set(Boost_USE_STATIC_LIBS ON) # use static boost
find_package(Boost REQUIRED COMPONENTS log) # log is used for tests

add_library(winasio INTERFACE)
target_include_directories(winasio INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
${Boost_INCLUDE_DIR}
)

# header only
target_compile_definitions(winasio
INTERFACE BOOST_ALL_NO_LIB=1
INTERFACE _WIN32_WINNT=0x0601
)

# currently winasio uses boost log for logging
target_link_libraries(winasio
INTERFACE Boost::log Boost::disable_autolinking Boost::headers
)

if(winasio_BuildExamples)
add_subdirectory(examples)
endif()
Expand Down
2 changes: 1 addition & 1 deletion tests/http/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ foreach(test_file ${SOURCES})
target_include_directories(${test_name}
PRIVATE .
)
target_link_libraries(${test_name} PRIVATE gtest_main winasio ${Boost_LIBRARIES})
target_link_libraries(${test_name} PRIVATE gtest_main winasio)
set_property(TARGET ${test_name} PROPERTY CXX_STANDARD 20) # for semaphore
add_test(NAME ${test_name} COMMAND ${test_name} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endforeach()
14 changes: 13 additions & 1 deletion tests/http/http_server_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>

#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>

#include <cstdio>
#include <utility>

Expand All @@ -17,7 +21,15 @@ namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp>

namespace logging = boost::log;

void log_init() {
logging::core::get()->set_filter(logging::trivial::severity >=
logging::trivial::debug);
}

TEST(HTTPServer, server) {
log_init();
// init http module
winnet::http::http_initializer init;
// add https then this becomes https server
Expand All @@ -39,7 +51,7 @@ TEST(HTTPServer, server) {
BOOST_LOG_TRIVIAL(debug)
<< L"Got a request for url: " << req->CookedUrl.pFullUrl << L" VerbId: "
<< static_cast<int>(req->Verb);
std::cout << request << std::endl;
BOOST_LOG_TRIVIAL(debug) << request;
response.set_status_code(200);
response.set_reason("OK");
response.set_content_type("text/html");
Expand Down
2 changes: 1 addition & 1 deletion tests/winhttp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ foreach(test_file ${SOURCES})
target_include_directories(${test_name}
PRIVATE .
)
target_link_libraries(${test_name} PRIVATE gtest_main winasio ${Boost_LIBRARIES})
target_link_libraries(${test_name} PRIVATE gtest_main winasio)
set_property(TARGET ${test_name} PROPERTY CXX_STANDARD 20) # for semaphore
add_test(NAME ${test_name} COMMAND ${test_name} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endforeach()

0 comments on commit 3ec6862

Please sign in to comment.