boostorg / cmake

CMake support infrastructure Boost submodule
94 stars 27 forks source link

How to include the boost::asio header #44

Closed hungptit closed 1 year ago

hungptit commented 1 year 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 1 year ago

You need to add Boost::asio to target_link_libraries.

hungptit commented 1 year ago

It works. Thank you, Peter.