cmake: add ghostty_vt_add_target() for cross-compilation

Add a ghostty_vt_add_target() CMake function that lets downstream
projects build libghostty-vt for a specific Zig target triple. The
function encapsulates zig discovery, build-type-to-optimize mapping,
the zig build invocation, and output path conventions so consumers
do not need to duplicate any of that logic. It creates named IMPORTED
targets (e.g. ghostty-vt-static-linux-amd64) that work alongside the
existing native ghostty-vt and ghostty-vt-static targets.

The build-type mapping is factored into a shared _GHOSTTY_ZIG_OPT_FLAG
variable used by both the native build and the new function.

The static library targets now propagate c++ as a link dependency on
non-Windows platforms, fixing link failures when consumers use static
linking with the default SIMD-enabled build.

A new example/c-vt-cmake-cross/ demonstrates end-to-end cross-
compilation using zig cc as the C compiler, auto-detecting a cross
target based on the host OS.
This commit is contained in:
Mitchell Hashimoto
2026-04-09 21:01:54 -07:00
parent 48a01b8bd5
commit f2e299fb46
9 changed files with 472 additions and 31 deletions

View File

@@ -278,6 +278,11 @@ jobs:
fail-fast: false
matrix:
dir: ${{ fromJSON(needs.list-examples.outputs.cmake) }}
exclude:
# Cross-compilation with zig cc requires a single-config
# generator (Makefiles/Ninja). The Windows CI uses Visual
# Studio which always uses MSVC and ignores CMAKE_C_COMPILER.
- dir: c-vt-cmake-cross
name: Example ${{ matrix.dir }} (Windows)
runs-on: namespace-profile-ghostty-windows
timeout-minutes: 45