Skip to content

Commit

Permalink
Allow dynamic linking mimalloc (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekmalneedi committed Jun 9, 2024
1 parent 1d6eb64 commit 2a601b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
33 changes: 26 additions & 7 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,34 @@ if(SLANG_USE_MIMALLOC)
${find_pkg_args})
FetchContent_MakeAvailable(mimalloc)

if(NOT TARGET mimalloc-static)
message(
FATAL_ERROR
"Could not find mimalloc package, min version: ${mimalloc_min_version}")
endif()

if(mimalloc_FOUND)
message(STATUS "Found system mimalloc version: ${mimalloc_VERSION}")
if(TARGET mimalloc)
set(mimalloc_target "mimalloc")
elseif(TARGET mimalloc-static)
set(mimalloc_target "mimalloc-static")
else()
message(
FATAL_ERROR
"Could not find mimalloc package, min version: ${mimalloc_min_version}"
)
endif()

get_target_property(MIMALLOC_CFG ${mimalloc_target} IMPORTED_CONFIGURATIONS)
get_target_property(MIMALLOC_LIB ${mimalloc_target}
IMPORTED_LOCATION_${MIMALLOC_CFG})
get_target_property(MIMALLOC_INC ${mimalloc_target}
INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "Found system mimalloc library: ${MIMALLOC_LIB}")
message(STATUS "Using system mimalloc include: ${MIMALLOC_INC}")
else()
if(NOT TARGET mimalloc-static)
message(
FATAL_ERROR
"Could not find mimalloc package, min version: ${mimalloc_min_version}"
)
endif()
set(mimalloc_target "mimalloc-static")

message(STATUS "Using remote mimalloc library")
if(IS_DIRECTORY "${mimalloc_SOURCE_DIR}")
set_property(DIRECTORY ${mimalloc_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL
Expand Down
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ target_link_libraries(slang_slang PUBLIC fmt::fmt Boost::headers
${CMAKE_THREAD_LIBS_INIT})

if(SLANG_USE_MIMALLOC)
target_link_libraries(slang_slang PUBLIC mimalloc-static)
target_link_libraries(slang_slang PUBLIC ${mimalloc_target})
target_compile_definitions(slang_slang PUBLIC SLANG_USE_MIMALLOC)
endif()

Expand Down

0 comments on commit 2a601b3

Please sign in to comment.