From 4cbe6052147420ee09ae855d57a81cef3467af15 Mon Sep 17 00:00:00 2001 From: Jack Wind Date: Tue, 20 May 2025 13:22:26 -0400 Subject: [PATCH] Feat: Allow per-target Metal debug flags (#2201) * feat: allow per-target Metal debug flags * formatting fix --- cmake/extension.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/extension.cmake b/cmake/extension.cmake index 3270b0056..13db804a1 100644 --- a/cmake/extension.cmake +++ b/cmake/extension.cmake @@ -11,13 +11,14 @@ include(CMakeParseArguments) # Args: TARGET: Custom target to be added for the metal library TITLE: Name of # the .metallib OUTPUT_DIRECTORY: Where to place ${TITLE}.metallib SOURCES: List # of source files INCLUDE_DIRS: List of include dirs DEPS: List of dependency -# files (like headers) +# files (like headers) DEBUG: Boolean, if true, enables debug compile options +# for this specific library. If not provided, uses global MLX_METAL_DEBUG. # # clang format on macro(mlx_build_metallib) # Parse args - set(oneValueArgs TARGET TITLE OUTPUT_DIRECTORY) + set(oneValueArgs TARGET TITLE OUTPUT_DIRECTORY DEBUG) set(multiValueArgs SOURCES INCLUDE_DIRS DEPS) cmake_parse_arguments(MTLLIB "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -26,6 +27,10 @@ macro(mlx_build_metallib) # Collect compile options set(MTLLIB_COMPILE_OPTIONS -Wall -Wextra -fno-fast-math -Wno-c++17-extensions) + if(MLX_METAL_DEBUG OR MTLLIB_DEBUG) + set(MTLLIB_COMPILE_OPTIONS ${MTLLIB_COMPILE_OPTIONS} -gline-tables-only + -frecord-sources) + endif() # Prepare metallib build command add_custom_command(