@@ -40,7 +40,7 @@ if(NOT ZIG_TARGET)
4040 set (Z_ABI "gnu" )
4141 if (Z_OS MATCHES "darwin|macos" )
4242 set (Z_OS "macos" )
43- set (Z_ABI "none" )
43+ set (Z_ABI "none" ) # macOS uses its own ABI, not GNU
4444 elseif (Z_OS MATCHES "windows" )
4545 set (Z_OS "windows" )
4646 elseif (Z_OS MATCHES "linux" )
@@ -64,6 +64,7 @@ elseif(ZIG_TARGET MATCHES "macos")
6464 set (CMAKE_SYSTEM_NAME Darwin)
6565endif ()
6666
67+ # Dummy version satisfies CMake's cross-compilation requirements without affecting Zig's behavior
6768set (CMAKE_SYSTEM_VERSION 1)
6869set (CMAKE_SYSTEM_PROCESSOR ${Z_ARCH} )
6970
@@ -79,6 +80,7 @@ if(ZIG_USE_CCACHE)
7980 endif ()
8081endif ()
8182
83+ # Generate wrapper scripts to inject -target flag and ccache prefix transparently
8284set (ZIG_SHIMS_DIR "${CMAKE_BINARY_DIR} /.zig-shims" )
8385file (MAKE_DIRECTORY "${ZIG_SHIMS_DIR} " )
8486if (CMAKE_HOST_WIN32 )
@@ -110,6 +112,13 @@ set(CMAKE_C_COMPILER "${ZIG_SHIMS_DIR}/zig-cc${EXT}")
110112set (CMAKE_CXX_COMPILER "${ZIG_SHIMS_DIR} /zig-c++${EXT} " )
111113set (CMAKE_AR "${ZIG_SHIMS_DIR} /zig-ar${EXT} " CACHE FILEPATH "Archiver" FORCE )
112114set (CMAKE_RANLIB "${ZIG_SHIMS_DIR} /zig-ranlib${EXT} " CACHE FILEPATH "Ranlib" FORCE )
115+
113116if (CMAKE_SYSTEM_NAME MATCHES "Windows" )
114117 set (CMAKE_RC_COMPILER "${ZIG_SHIMS_DIR} /zig-rc${EXT} " CACHE FILEPATH "Resource Compiler" FORCE )
118+ # Explicitly specify MSVC syntax because zig rc only supports this format
119+ set (CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> /fo <OBJECT> <SOURCE>" )
120+ elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin" )
121+ # Prevent CMake from searching for Xcode SDKs since Zig provides its own sysroot
122+ set (CMAKE_OSX_SYSROOT "" CACHE PATH "Force empty sysroot for Zig" FORCE )
123+ set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force empty deployment target" FORCE )
115124endif ()
0 commit comments