References:
- https://cmake.org/cmake/help/latest/module/FindBoost.html
- https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake
If Boost is always needed
find_package(Boost REQUIRED)
add_executable(progname file1.cxx file2.cxx)
target_include_directories(progname PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(progname PRIVATE ${Boost_LIBRARIES})If Boost is optional
find_package(Boost)
if(Boost_FOUND)
add_executable(progname file1.cxx file2.cxx)
target_include_directories(progname PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(progname PRIVATE ${Boost_LIBRARIES})
endif()If you need specific libraries from Boost:
find_package(Boost COMPONENTS stuff)e.g.
find_package(Boost COMPONENTS filesystem regex)