boostorg / cmake

CMake support infrastructure Boost submodule
87 stars 26 forks source link

How to include the boost::asio header #44

Closed hungptit closed 10 months ago

hungptit commented 10 months ago

I can use some boost libraries successfully using this pattern.

set(BOOST_INCLUDE_LIBRARIES json)
set(BOOST_ENABLE_CMAKE ON)

include(FetchContent)
FetchContent_Declare(
  Boost
  GIT_REPOSITORY https://github.com/boostorg/boost.git
  GIT_TAG boost-1.83.0
  GIT_SHALLOW TRUE
)

FetchContent_MakeAvailable(Boost)

# Compile some code against boost::json
set(LIBNAME "smoketests_utilities")
add_library(
  ${LIBNAME} STATIC
  address.cpp
  client.cpp
  server.cpp)
target_link_libraries(${LIBNAME} PRIVATE address Boost::json)

The above pattern does not work for boost::asio. What is the right way to add header-only libraries to the include path?

pdimov commented 10 months ago

You need to add Boost::asio to target_link_libraries.

hungptit commented 10 months ago

It works. Thank you, Peter.