Skip to content

Commit de2aa4a

Browse files
author
peng.li24
committed
githuhaction:fix
1 parent 910113f commit de2aa4a

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ if(NOT TARGET blockmalloc::blockmalloc)
1717
)
1818
FetchContent_MakeAvailable(blockmalloc)
1919
if(TARGET blockmalloc::blockmalloc)
20-
target_link_libraries(boxmalloc PRIVATE blockmalloc::blockmalloc)
20+
set(BM_TARGET blockmalloc::blockmalloc)
2121
elseif(TARGET blockmalloc)
22-
target_link_libraries(boxmalloc PRIVATE blockmalloc)
22+
set(BM_TARGET blockmalloc)
2323
else()
24-
target_link_libraries(boxmalloc PRIVATE blockmalloc)
24+
set(BM_TARGET blockmalloc)
25+
endif()
2526
endif()
2627

2728
# library
@@ -48,7 +49,28 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
4849
target_compile_definitions(boxmalloc PRIVATE ENABLE_LOG)
4950
endif()
5051

51-
target_link_libraries(boxmalloc PRIVATE blockmalloc::blockmalloc)
52+
# Link to blockmalloc using the resolved target name (BM_TARGET).
53+
# If the target wasn't found during FetchContent, this may still fail and will need
54+
# inspecting the blockmalloc project's exported target name.
55+
if(NOT TARGET BM_TARGET)
56+
# BM_TARGET is a variable, not a CMake target; use it as a name when possible.
57+
# Attempt the common names in order.
58+
if(TARGET blockmalloc::blockmalloc)
59+
target_link_libraries(boxmalloc PRIVATE blockmalloc::blockmalloc)
60+
elseif(TARGET blockmalloc)
61+
target_link_libraries(boxmalloc PRIVATE blockmalloc)
62+
elseif(TARGET block_malloc::block_malloc)
63+
target_link_libraries(boxmalloc PRIVATE block_malloc::block_malloc)
64+
elseif(TARGET block_malloc)
65+
target_link_libraries(boxmalloc PRIVATE block_malloc)
66+
else()
67+
# Last-resort: try linking to the variable content; CMake will error if it's not a target.
68+
target_link_libraries(boxmalloc PRIVATE ${BM_TARGET})
69+
endif()
70+
else()
71+
# BM_TARGET is a CMake variable storing the resolved target name; use it to link.
72+
target_link_libraries(boxmalloc PRIVATE ${BM_TARGET})
73+
endif()
5274

5375
add_subdirectory(test)
5476

0 commit comments

Comments
 (0)