From b194d65a6a6dbe83473faaaacaa29c4fa07c5b27 Mon Sep 17 00:00:00 2001 From: Cheng Date: Tue, 9 Sep 2025 08:27:18 +0900 Subject: [PATCH] Some tweaks in cmake files (#2574) * Do proper check of Metal lib * Update doctest to get rid of cmake version hack --- CMakeLists.txt | 26 +++++++++++++------------- tests/CMakeLists.txt | 7 ++----- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a65ba0bc..7779e9901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,22 +87,21 @@ cmake_policy(SET CMP0135 NEW) add_library(mlx) -if(MLX_BUILD_METAL) - set(METAL_LIB "-framework Metal") - set(FOUNDATION_LIB "-framework Foundation") - set(QUARTZ_LIB "-framework QuartzCore") -endif() - if(MLX_BUILD_CUDA) enable_language(CUDA) endif() -if(MLX_BUILD_METAL AND NOT METAL_LIB) - message(STATUS "Metal not found. Unable to build GPU") - set(MLX_BUILD_METAL OFF) - set(MLX_METAL_DEBUG OFF) -elseif(MLX_BUILD_METAL) - message(STATUS "Building METAL sources") +if(MLX_BUILD_METAL) + find_library(METAL_LIB Metal) + find_library(FOUNDATION_LIB Foundation) + find_library(QUARTZ_LIB QuartzCore) + if(METAL_LIB) + message(STATUS "Metal found ${METAL_LIB}") + else() + message( + FATAL_ERROR + "Metal not found. Set MLX_BUILD_METAL=OFF to build without GPU") + endif() if(MLX_METAL_DEBUG) add_compile_definitions(MLX_METAL_DEBUG) @@ -111,7 +110,8 @@ elseif(MLX_BUILD_METAL) # Throw an error if xcrun not found execute_process( COMMAND zsh "-c" "/usr/bin/xcrun -sdk macosx --show-sdk-version" - OUTPUT_VARIABLE MACOS_SDK_VERSION COMMAND_ERROR_IS_FATAL ANY) + OUTPUT_VARIABLE MACOS_SDK_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) if(${MACOS_SDK_VERSION} LESS 14.0) message( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2c44bf4f6..9e977d628 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,10 +1,7 @@ -# Doctest works fine with cmake 3.5 -set(CMAKE_POLICY_VERSION_MINIMUM 3.5) - FetchContent_Declare( doctest - GIT_REPOSITORY "https://github.com/onqtam/doctest" - GIT_TAG "ae7a13539fb71f270b87eb2e874fbac80bc8dda2") + GIT_REPOSITORY https://github.com/onqtam/doctest.git + GIT_TAG v2.4.12) FetchContent_MakeAvailable(doctest) add_executable(tests ${PROJECT_SOURCE_DIR}/tests/tests.cpp)