Only link Boost libraries which are actually needed.

Asio does not require Boost.
Bosot.Asio requires Boost.System and optionally Boost.Regex.
The examples require Boost headers and Boost.Filesystem.
The CMake targets pull in their dependencies recursively, no need to
explicitly link the examples to Boost.System.
Boost.Thread should not be neede, according to the docs.
This commit is contained in:
Hermann von Kleist 2023-03-31 11:19:51 +02:00
commit 17c1a8b65f

View file

@ -27,8 +27,8 @@ if(USE_STANDALONE_ASIO)
target_include_directories(simple-web-server INTERFACE ${ASIO_PATH})
endif()
else()
find_package(Boost 1.53.0 COMPONENTS system thread REQUIRED)
target_link_libraries(simple-web-server INTERFACE Boost::boost Boost::system Boost::thread)
find_package(Boost 1.53.0 COMPONENTS system REQUIRED)
target_link_libraries(simple-web-server INTERFACE Boost::boost Boost::system)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
target_compile_definitions(simple-web-server INTERFACE USE_BOOST_REGEX)
find_package(Boost 1.53.0 COMPONENTS regex REQUIRED)
@ -65,15 +65,13 @@ if(CMAKE_SOURCE_DIR STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
add_compile_options(/W1)
endif()
find_package(Boost 1.53.0 COMPONENTS system thread filesystem)
find_package(Boost 1.53.0 COMPONENTS filesystem)
if(Boost_FOUND)
add_executable(http_examples http_examples.cpp)
target_link_libraries(http_examples simple-web-server)
target_link_libraries(http_examples Boost::boost Boost::system Boost::thread Boost::filesystem)
target_link_libraries(http_examples simple-web-server Boost::boost Boost::filesystem)
if(OPENSSL_FOUND)
add_executable(https_examples https_examples.cpp)
target_link_libraries(https_examples simple-web-server)
target_link_libraries(https_examples Boost::boost Boost::system Boost::thread Boost::filesystem)
target_link_libraries(https_examples simple-web-server Boost::boost Boost::filesystem)
endif()
endif()