Skip to content

Quickstart

Integration 💻

You can copy the script from our repository in cmake/FetchBoostContent.cmake or the release page, and include it in your project.

include(cmake/FetchBoostContent.cmake)

When FetchContent is not going to be the main strategy for integrating Boost, a second alternative is to use CMake itself to download the script file and include it only when needed.

if (USE_FETCH_CONTENT)
    set(url https://github.com/alandefreitas/FetchBoostContent/blob/master/cmake/FetchBoostContent.cmake)
    set(destination ${CMAKE_CURRENT_BINARY_DIR}/cmake/FetchBoostContent.cmake})
    if (NOT EXISTS destination)
        file(DOWNLOAD ${url} ${destination})
    endif()
    include(${destination})
endif()

This strategy might also be useful to keep the script up-to-date.

Hello world 👋

include(cmake/FetchBoostContent.cmake)

FetchBoostContent_Declare(
        boost_circular_buffer
        GIT_REPOSITORY https://github.com/boostorg/circular_buffer
        GIT_TAG        master
)
FetchBoostContent_MakeAvailable(boost_circular_buffer)

FetchBoostContent_Declare(
        boost_beast
        GIT_REPOSITORY https://github.com/boostorg/beast
        GIT_TAG        master
)

# Check if population has already been performed
FetchBoostContent_GetProperties(boost_beast)
if (NOT boost_beast_POPULATED)
    # Fetch the content using previously declared details
    FetchBoostContent_Populate(boost_beast)

# Create an interface target for all the include dirs
add_library(boost_headers INTERFACE)
add_library(Boost::headers ALIAS boost_headers)
# <library>_SOURCE_DIRS contains the source dir for all <library> dependencies
foreach (dir ${boost_beast_SOURCE_DIRS})
    target_include_directories(boost_headers INTERFACE ${dir}/include)
endforeach()

add_executable(http-client-sync http-client-sync.cpp)
target_link_libraries(http-client-sync Boost::headers)

add_executable(container container.cpp)
target_link_libraries(container Boost::container)