Skip to content

Commit

Permalink
fix: missing boost targets in the install export set while using Fetc…
Browse files Browse the repository at this point in the history
…hContent

Signed-off-by: ik <[email protected]>
  • Loading branch information
hiiiik committed Aug 9, 2024
1 parent d7b8e64 commit 4d86f3d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(FETCHCONTENT_QUIET OFF)
set(BUILD_SHARED_LIBS ${OPENGEMINI_BUILD_SHARED_LIBS})

set(OPENGEMINI_COMPILE_DEFINITIONS "")

Expand All @@ -52,7 +53,6 @@ if(OPENGEMINI_BUILD_HEADER_ONLY_LIBS)
else()
list(APPEND OPENGEMINI_COMPILE_DEFINITIONS "OPENGEMINI_SEPARATE_COMPILATION")

set(BUILD_SHARED_LIBS ${OPENGEMINI_BUILD_SHARED_LIBS})
if(BUILD_SHARED_LIBS)
message(STATUS "Will generating shared libraries")
else()
Expand Down
3 changes: 2 additions & 1 deletion cmake/OpenGeminiCxxConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ set(OPENGEMINI_ENABLE_SSL_SUPPORT @OPENGEMINI_ENABLE_SSL_SUPPORT@)
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

include(CMakeFindDependencyMacro)
find_dependency(Boost REQUIRED)
find_dependency(Boost REQUIRED COMPONENTS coroutine url)
find_dependency(fmt REQUIRED)
find_dependency(nlohmann_json REQUIRED)

if(OPENGEMINI_ENABLE_SSL_SUPPORT)
find_dependency(OpenSSL REQUIRED)
Expand Down
56 changes: 45 additions & 11 deletions cmake/deps/boost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,48 @@
include_guard()
include(FetchContent)

message(STATUS "Finding Boost package first before trying to download and build it from source")

FetchContent_Declare(Boost
GIT_REPOSITORY https://github.com/boostorg/boost
GIT_TAG boost-1.84.0
GIT_PROGRESS TRUE
FIND_PACKAGE_ARGS
1.81
COMPONENTS coroutine url
)
FetchContent_MakeAvailable(Boost)
find_package(Boost 1.81 QUIET COMPONENTS coroutine url)
if(NOT Boost_FOUND)
message(STATUS "Download Boost and build it from source")
set(BOOST_ENABLE_CMAKE ON)
FetchContent_Declare(Boost
GIT_REPOSITORY https://github.com/boostorg/boost
GIT_TAG boost-1.84.0
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(Boost)

set(OPENGEMINI_EXPORT_BOOST_TARGETS )
macro(append_boost_targets_recursively TARGET_NAME)
if (TARGET ${TARGET_NAME})
get_target_property(TARGET_ORIGIN_NAME ${TARGET_NAME} ALIASED_TARGET)
list(APPEND OPENGEMINI_EXPORT_BOOST_TARGETS ${TARGET_ORIGIN_NAME})
endif()

get_property(DEPEND_TARGETS TARGET ${TARGET_NAME} PROPERTY INTERFACE_LINK_LIBRARIES)
foreach(DEPEND_TARGET IN LISTS DEPEND_TARGETS)
append_boost_targets_recursively(${DEPEND_TARGET})
endforeach()
endmacro()

append_boost_targets_recursively("Boost::asio")
append_boost_targets_recursively("Boost::beast")
append_boost_targets_recursively("Boost::coroutine")
append_boost_targets_recursively("Boost::headers")
append_boost_targets_recursively("Boost::url")

list(REMOVE_DUPLICATES OPENGEMINI_EXPORT_BOOST_TARGETS)

foreach(TARGET_NAME IN LISTS OPENGEMINI_EXPORT_BOOST_TARGETS)
get_property(TARGET_INCLUDE_DIR TARGET ${TARGET_NAME} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
install(
DIRECTORY ${TARGET_INCLUDE_DIR}
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
endforeach()

install(
TARGETS ${OPENGEMINI_EXPORT_BOOST_TARGETS}
EXPORT ${PROJECT_NAME}Targets
)
endif()

0 comments on commit 4d86f3d

Please sign in to comment.