Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,15 @@ if(WIN32)
FetchContent_MakeAvailable(dlfcn-win32)
endblock()
target_include_directories(mlx PRIVATE "${dlfcn-win32_SOURCE_DIR}/src")
target_link_libraries(mlx PRIVATE dl)
if(BUILD_SHARED_LIBS)
target_link_libraries(mlx PRIVATE dl)
else()
# A static MLX package must not expose the FetchContent-only dlfcn-win32::dl
# target to installed consumers. Compile the small Windows implementation
# directly into mlx.lib and propagate its system library.
target_sources(mlx PRIVATE "${dlfcn-win32_SOURCE_DIR}/src/dlfcn.c")
target_link_libraries(mlx PRIVATE Psapi.lib)
endif()
endif()

if(MLX_BUILD_CPU)
Expand Down Expand Up @@ -296,8 +304,12 @@ if(MLX_BUILD_CPU)
URL "https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.33/${OPENBLAS_ZIP}"
)
FetchContent_MakeAvailable(openblas)
target_link_libraries(
mlx PRIVATE "${openblas_SOURCE_DIR}/lib/${OPENBLAS_LIB}.lib")
set(OPENBLAS_IMPORT_LIBRARY
"${openblas_SOURCE_DIR}/lib/${OPENBLAS_LIB}.lib")
add_library(MLX::OpenBLAS UNKNOWN IMPORTED GLOBAL)
set_target_properties(MLX::OpenBLAS PROPERTIES IMPORTED_LOCATION
"${OPENBLAS_IMPORT_LIBRARY}")
target_link_libraries(mlx PRIVATE MLX::OpenBLAS)
target_include_directories(mlx
PRIVATE "${openblas_SOURCE_DIR}/${OPENBLAS_INC}")
# Make sure the DLL file is placed in the same dir with executables.
Expand Down Expand Up @@ -417,6 +429,8 @@ if(WIN32)
if(MLX_BUILD_CPU)
# Install OpenBLAS.
install(FILES ${OPENBLAS_DLL_FILE} TYPE BIN)
install(FILES ${OPENBLAS_IMPORT_LIBRARY}
DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif()

Expand Down
19 changes: 19 additions & 0 deletions mlx.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

if(WIN32 AND @MLX_BUILD_CPU@ AND NOT TARGET MLX::OpenBLAS)
add_library(MLX::OpenBLAS UNKNOWN IMPORTED)
set_target_properties(MLX::OpenBLAS PROPERTIES
IMPORTED_LOCATION "@PACKAGE_CMAKE_INSTALL_LIBDIR@/@OPENBLAS_LIB@.lib"
)
endif()

if(@MLX_BUILD_CUDA@)
find_dependency(CUDAToolkit REQUIRED)

set(_MLX_SAVED_CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}")
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
find_dependency(CUDNN REQUIRED)
set(CMAKE_MODULE_PATH "${_MLX_SAVED_CMAKE_MODULE_PATH}")
unset(_MLX_SAVED_CMAKE_MODULE_PATH)
endif()

include(@PACKAGE_MLX_CMAKE_INSTALL_MODULE_DIR@/MLXTargets.cmake)
include(@PACKAGE_MLX_CMAKE_INSTALL_MODULE_DIR@/extension.cmake)

Expand Down
4 changes: 3 additions & 1 deletion mlx/backend/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ set(CUDNN_FRONTEND_BUILD_SAMPLES OFF)
set(CUDNN_FRONTEND_BUILD_TESTS OFF)
set(CUDNN_FRONTEND_BUILD_PYTHON_BINDINGS OFF)
FetchContent_MakeAvailable(cudnn)
target_link_libraries(mlx PRIVATE cudnn_frontend)
# cudnn_frontend is header-only and is only needed while compiling MLX. Do not
# leak its FetchContent target into the installed static link interface.
target_link_libraries(mlx PRIVATE $<BUILD_INTERFACE:cudnn_frontend>)
# Link with the actual cuDNN libraries.
target_link_libraries(mlx PRIVATE CUDNN::cudnn_all)

Expand Down