diff --git a/cmake/modules/NativeExecutable.cmake b/cmake/modules/NativeExecutable.cmake --- a/cmake/modules/NativeExecutable.cmake +++ b/cmake/modules/NativeExecutable.cmake @@ -33,6 +33,19 @@ endforeach() endfunction() +function(non_native_target_link_headers_only TARGET LIB VERSION) + # Drop dependency during native builds + if(__IS_NATIVE_BUILD) + return() + endif() + + # Header only libraries have imported targets with no associated component + find_package(${LIB} ${VERSION} REQUIRED) + foreach(COMPONENT ${ARGN}) + target_link_libraries(${TARGET} ${LIB}::${COMPONENT}) + endforeach() +endfunction() + # It is imperative that NATIVE_BUILD_DIR be in the cache. set(NATIVE_BUILD_DIR "${CMAKE_BINARY_DIR}/native" CACHE PATH "The path of the native build directory" FORCE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -471,6 +471,12 @@ link_event(util event) +macro(link_boost_headers_only TARGET) + non_native_target_link_headers_only(${TARGET} Boost 1.64 ${ARGN}) +endmacro() + +link_boost_headers_only(util headers) + function(add_network_sources NETWORK_SOURCES) set(NETWORK_DIR abc)