Skip to content

Commit ca1d728

Browse files
author
peng.li24
committed
githuhaction:fix
1 parent 2184242 commit ca1d728

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
66
set(CMAKE_C_EXTENSIONS OFF)
77

88
include(GNUInstallDirs)
9-
10-
find_package(blockmalloc CONFIG REQUIRED)
9+
include(FetchContent)
10+
find_package(blockmalloc CONFIG QUIET)
1111

1212
# library
1313
add_library(boxmalloc SHARED
@@ -33,7 +33,27 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
3333
target_compile_definitions(boxmalloc PRIVATE ENABLE_LOG)
3434
endif()
3535

36-
target_link_libraries(boxmalloc PRIVATE blockmalloc::blockmalloc)
36+
## Link to blockmalloc: prefer the imported namespaced target, fall back to in-tree target.
37+
if(TARGET blockmalloc::blockmalloc)
38+
target_link_libraries(boxmalloc PRIVATE blockmalloc::blockmalloc)
39+
elseif(TARGET blockmalloc)
40+
target_link_libraries(boxmalloc PRIVATE blockmalloc)
41+
else()
42+
message(STATUS "blockmalloc not found via find_package or in-tree; attempting FetchContent download")
43+
FetchContent_Declare(
44+
blockmalloc
45+
GIT_REPOSITORY https://github.com/miaobyte/blockmalloc.git
46+
GIT_TAG main
47+
)
48+
FetchContent_MakeAvailable(blockmalloc)
49+
if(TARGET blockmalloc::blockmalloc)
50+
target_link_libraries(boxmalloc PRIVATE blockmalloc::blockmalloc)
51+
elseif(TARGET blockmalloc)
52+
target_link_libraries(boxmalloc PRIVATE blockmalloc)
53+
else()
54+
message(FATAL_ERROR "Could not locate blockmalloc target after FetchContent. Please install blockmalloc or adjust the dependency.")
55+
endif()
56+
endif()
3757

3858
add_subdirectory(test)
3959

0 commit comments

Comments
 (0)