`CMAKE_AR` and `CMAKE_RANLIB` do not accept a command with arguments
A while back I found this post that talks about cross compiling with zig. They said that doing it with CMake is left as an exercise to the reader, so I tried. The way it works is that your compiler becomes:
zig cc -target aarch64-linux-gnu
Eventually I found in the documentation of CMAKE_<LANG>_COMPILER that you can do this like so:
set(CMAKE_C_COMPILER "zig" cc -target aarch64-linux-gnu)
set(CMAKE_CXX_COMPILER "zig" c++ -target aarch64-linux-gnu)
Doing this configures everything correctly (it detects Clang 13 as expected), but then gives an error because CMAKE_AR
(and CMAKE_RANLIB
) are not set. These exist in the form of zig ar
and zig ranlib
, so I did:
set(CMAKE_AR "zig" ar)
set(CMAKE_RANLIB "zig" ranlib)
Unfortunately this results in a compilation error (configuring is fine):
error: unknown command: ;ar
I put a full example here: https://gitlab.kitware.com/mrexodia/cmake-zig
Let me know if anyone has any pointers where I can look to fix this in CMake, for now I found a workaround but it would be awesome if zig
worked out of the box with CMake.