This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 1542bdfd3 build: fix build with Homebrew Clang on macOS (#3154)
1542bdfd3 is described below

commit 1542bdfd3092423f6a60f8212c9a55f5f6deeffd
Author: sryan yuan <[email protected]>
AuthorDate: Mon Sep 1 17:15:08 2025 +0800

    build: fix build with Homebrew Clang on macOS (#3154)
---
 CMakeLists.txt     | 18 ++++++++++++++++++
 cmake/lua.cmake    |  3 ++-
 cmake/luajit.cmake |  3 ++-
 cmake/lz4.cmake    |  3 ++-
 cmake/zstd.cmake   |  3 ++-
 5 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 26213b60b..08504b6d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -155,6 +155,24 @@ if(ENABLE_OPENSSL)
     find_package(OpenSSL REQUIRED)
 endif()
 
+# Auto-detect macOS SDK path if not set
+if(APPLE AND NOT CMAKE_OSX_SYSROOT)
+  execute_process(
+    COMMAND xcrun --sdk macosx --show-sdk-path
+    OUTPUT_VARIABLE MACOS_SDK_PATH
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    ERROR_QUIET
+    RESULT_VARIABLE result
+  )
+
+  if(result EQUAL 0 AND EXISTS "${MACOS_SDK_PATH}")
+    set(CMAKE_OSX_SYSROOT "${MACOS_SDK_PATH}" CACHE PATH "macOS SDK path" 
FORCE)
+  else()
+    message(FATAL_ERROR "Failed to detect macOS SDK path. "
+            "Install Xcode command line tools or set CMAKE_OSX_SYSROOT 
manually.")
+  endif()
+endif()
+
 include(cmake/gtest.cmake)
 include(cmake/snappy.cmake)
 include(cmake/lz4.cmake)
diff --git a/cmake/lua.cmake b/cmake/lua.cmake
index 0b6827b0c..d3f6794e2 100644
--- a/cmake/lua.cmake
+++ b/cmake/lua.cmake
@@ -30,7 +30,8 @@ if(NOT lua_POPULATED)
 
   set(LUA_CXX ${CMAKE_CXX_COMPILER})
   set(LUA_CFLAGS "-DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC= 
-DLUA_USE_MKSTEMP")
-  if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
+  if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
+   (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_CXX_COMPILER_ID STREQUAL 
"Clang"))
     set(LUA_CFLAGS "${LUA_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
   endif()
 
diff --git a/cmake/luajit.cmake b/cmake/luajit.cmake
index 2e38efa08..eedf29f01 100644
--- a/cmake/luajit.cmake
+++ b/cmake/luajit.cmake
@@ -48,7 +48,8 @@ if (NOT lua_POPULATED)
   FetchContent_Populate(luajit)
 
   set(LUA_CFLAGS "-DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC= 
-DLUA_USE_MKSTEMP")
-  if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
+  if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
+   (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_CXX_COMPILER_ID STREQUAL 
"Clang"))
     set(LUA_CFLAGS "${LUA_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
   endif ()
 
diff --git a/cmake/lz4.cmake b/cmake/lz4.cmake
index 6df0b48f3..442d1e402 100644
--- a/cmake/lz4.cmake
+++ b/cmake/lz4.cmake
@@ -28,7 +28,8 @@ FetchContent_GetProperties(lz4)
 if(NOT lz4_POPULATED)
   FetchContent_Populate(lz4)
 
-  if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
+  if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
+   (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_CXX_COMPILER_ID STREQUAL 
"Clang"))
     set(APPLE_FLAG "CFLAGS=-isysroot ${CMAKE_OSX_SYSROOT}")
   endif()
   
diff --git a/cmake/zstd.cmake b/cmake/zstd.cmake
index abb4f22c6..5a9f249b6 100644
--- a/cmake/zstd.cmake
+++ b/cmake/zstd.cmake
@@ -28,7 +28,8 @@ FetchContent_GetProperties(zstd)
 if(NOT zstd_POPULATED)
   FetchContent_Populate(zstd)
 
-  if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
+  if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
+   (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_CXX_COMPILER_ID STREQUAL 
"Clang"))
     set(APPLE_FLAG "CFLAGS=-isysroot ${CMAKE_OSX_SYSROOT}")
   endif()
 

Reply via email to