Commit cacb962ba7

Andrew Kelley <andrew@ziglang.org>
2022-12-10 00:19:25
CMake: add workaround for CMAKE_AR not supporting spaces
This allows using `zig ar` for `CMAKE_AR`. Unfortunately, it requires a patch to CMakeLists.txt and cannot be done merely with flags to the cmake line.
1 parent c9231f0
ci/aarch64-windows.ps1
@@ -46,8 +46,7 @@ Set-Location -Path 'build-release'
   -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" `
   -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" `
   -DCMAKE_AR="$ZIG" `
-  -DCMAKE_C_ARCHIVE_CREATE="<CMAKE_AR> ar qc <TARGET> <LINK_FLAGS> <OBJECTS>" `
-  -DCMAKE_CXX_ARCHIVE_CREATE="<CMAKE_AR> ar qc <TARGET> <LINK_FLAGS> <OBJECTS>" `
+  -DZIG_AR_WORKAROUND=ON `
   -DZIG_TARGET_TRIPLE="$TARGET" `
   -DZIG_TARGET_MCPU="$MCPU" `
   -DZIG_STATIC=ON
CMakeLists.txt
@@ -120,6 +120,7 @@ string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_INCLUDE_DIR_ESCAPED "${ZIG_LIBC_
 set(ZIG_TARGET_TRIPLE "native" CACHE STRING "arch-os-abi to output binaries for")
 set(ZIG_TARGET_MCPU "native" CACHE STRING "-mcpu parameter to output binaries for")
 set(ZIG_SINGLE_THREADED off CACHE BOOL "limit the zig compiler to use only 1 thread")
+set(ZIG_AR_WORKAROUND off CACHE BOOL "append 'ar' subcommand to CMAKE_AR")
 
 if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
     set(ZIG_USE_LLVM_CONFIG ON CACHE BOOL "use llvm-config to find LLVM libraries")
@@ -127,6 +128,11 @@ else()
     set(ZIG_USE_LLVM_CONFIG OFF CACHE BOOL "use llvm-config to find LLVM libraries")
 endif()
 
+if(ZIG_AR_WORKAROUND)
+  string(REPLACE "<CMAKE_AR>" "<CMAKE_AR> ar" CMAKE_C_ARCHIVE_CREATE ${CMAKE_C_ARCHIVE_CREATE})
+  string(REPLACE "<CMAKE_AR>" "<CMAKE_AR> ar" CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_CXX_ARCHIVE_CREATE})
+endif()
+
 find_package(llvm 15)
 find_package(clang 15)
 find_package(lld 15)