Commit b6783d40 authored by Hermann von Kleist's avatar Hermann von Kleist
Browse files

CMake: find_package(asio) if available

parent 84170850
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -24,10 +24,20 @@ target_link_libraries(simple-web-server INTERFACE Threads::Threads)

if(USE_STANDALONE_ASIO)
    target_compile_definitions(simple-web-server INTERFACE ASIO_STANDALONE)
    # There is no canonical way to use Asio from CMake.
    # In particular, Asio does not support CMake natively.
    # However, Conan and Vcpkg do provide CMake support on their own.
    # Prefer the CMake target and fall back to finding asio.hpp.
    if(NOT TARGET asio::asio)
        find_package(asio)
    endif()
    if(TARGET asio::asio)
        target_link_libraries(simple-web-server INTERFACE asio::asio)
    else()
        find_path(ASIO_PATH asio.hpp)
        if(NOT ASIO_PATH)
            message(FATAL_ERROR "Standalone Asio not found")
    else()
        endif()
        target_include_directories(simple-web-server SYSTEM INTERFACE ${ASIO_PATH})
    endif()
else()