File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree File renamed without changes.
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
66set (CMAKE_C_EXTENSIONS OFF )
77
88include (GNUInstallDirs )
9-
10- find_package (blockmalloc CONFIG REQUIRED )
9+ include ( FetchContent )
10+ find_package (blockmalloc CONFIG QUIET )
1111
1212# library
1313add_library (boxmalloc SHARED
@@ -33,7 +33,27 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
3333 target_compile_definitions (boxmalloc PRIVATE ENABLE_LOG )
3434endif ()
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
3858add_subdirectory (test )
3959
You can’t perform that action at this time.
0 commit comments