As a follow-up to my post in your other thread (TL;DR: don’t use getPath
), a more proper solution would look something like this:
const cmake = b.findProgram(&.{"cmake"}, &.{}) catch @panic("CMake not found");
const triple = target.result.linuxTriple(b.allocator) catch @panic("OOM");
const cmake_configure = b.addSystemCommand(&.{
cmake,
"-G=Ninja",
"-B",
});
const build_dir = cmake_configure.addOutputDirectoryArg("build");
cmake_configure.addArg("-S");
cmake_configure.addDirectoryArg(upstream.path(""));
cmake_configure.addArgs(&.{
b.fmt("-DCMAKE_C_COMPILER='{s};cc;--target={s}", .{ b.graph.zig_exe, triple }),
b.fmt("-DCMAKE_CXX_COMPILER='{s};c++;--target={s}", .{ b.graph.zig_exe, triple }),
"-DWITH_PERF_TOOL=OFF",
"-DZMQ_BUILD_TESTS=OFF",
"-DENABLE_CPACK=OFF",
"-DENABLE_DRAFTS=ON",
b.fmt("-DCMAKE_BUILD_TYPE={s}", .{if (optimize == .Debug) "Debug" else "Release"}),
});
const cmake_build = b.addSystemCommand(&.{
cmake,
"--build",
});
cmake_build.addDirectoryArg(build_dir);
// replace exe with whatever you want to link with libzmq.a
exe.addObjectFile(build_dir.path(b, "libzmq.a"));
// exe must also depend on the `cmake --build` command
// to ensure libzmq.a is actually built
exe.step.dependOn(&cmake_build.step);
I haven’t tested this, so some details might be off, but I believe this should be roughly correct.