From a59fae040f322dc6aff78128bbe63b088784133d Mon Sep 17 00:00:00 2001 From: Cheng Date: Tue, 10 Dec 2024 12:07:50 +0900 Subject: [PATCH] Fix library output directory for MSVC (#1681) --- .gitignore | 3 +++ python/src/CMakeLists.txt | 15 +++++++++++++-- setup.py | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8dfe5038e..e748ee2bf 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,9 @@ build/ *.out *.app +# Debug symbols +*.pdb + # VSCode .vscode/ .DS_Store diff --git a/python/src/CMakeLists.txt b/python/src/CMakeLists.txt index 104ad6d69..943f02455 100644 --- a/python/src/CMakeLists.txt +++ b/python/src/CMakeLists.txt @@ -29,8 +29,19 @@ if(NOT MLX_PYTHON_BINDINGS_OUTPUT_DIRECTORY) set(MLX_PYTHON_BINDINGS_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) endif() -set_target_properties(core PROPERTIES LIBRARY_OUTPUT_DIRECTORY - ${MLX_PYTHON_BINDINGS_OUTPUT_DIRECTORY}) +set_target_properties( + core + PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${MLX_PYTHON_BINDINGS_OUTPUT_DIRECTORY} + # Do not append a sub-dir for multi-config generators like MSVC + # and XCode. + LIBRARY_OUTPUT_DIRECTORY_RELEASE + ${MLX_PYTHON_BINDINGS_OUTPUT_DIRECTORY} + LIBRARY_OUTPUT_DIRECTORY_DEBUG + ${MLX_PYTHON_BINDINGS_OUTPUT_DIRECTORY} + LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO + ${MLX_PYTHON_BINDINGS_OUTPUT_DIRECTORY} + LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL + ${MLX_PYTHON_BINDINGS_OUTPUT_DIRECTORY}) target_link_libraries(core PRIVATE mlx) target_compile_definitions(core PRIVATE _VERSION_=${MLX_VERSION}) diff --git a/setup.py b/setup.py index 5f1482bd6..e336ad8cf 100644 --- a/setup.py +++ b/setup.py @@ -67,7 +67,8 @@ def build_extension(self, ext: CMakeExtension) -> None: "-DMLX_BUILD_EXAMPLES=OFF", f"-DMLX_PYTHON_BINDINGS_OUTPUT_DIRECTORY={extdir}{os.sep}", ] - build_args = [] + # Some generators require explcitly passing config when building. + build_args = ["--config", cfg] # Adding CMake arguments set as environment variable # (needed e.g. to build for ARM OSx on conda-forge) if "CMAKE_ARGS" in os.environ: