From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andrew Udvare <audvare@gmail.com>
Date: Fri, 9 Oct 2026 21:39:20 -0400
Subject: [PATCH] Always treat the build as cross-compiling

Most of Darling is built for Darwin, and the build relies on
CMAKE_CROSSCOMPILING being true (which setting CMAKE_SYSTEM_NAME
normally implies): otherwise CMake replaces the first word of a custom
command with an executable target of the same name, so commands such as
`true` ran the Darwin `true` from shell_cmds and failed with "Exec
format error". Toolchain files used by distributions' build tools set
CMAKE_CROSSCOMPILING to FALSE, so set it explicitly after project().

Signed-off-by: Andrew Udvare <audvare@gmail.com>
---
 CMakeLists.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3ee83c570..2b4024da5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,6 +67,11 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0 CACHE STRING "The version of macOS we're si
 
 project(darling)
 
+# Most of Darling is built for Darwin. Without this, a toolchain file that sets it to FALSE (as
+# distributions' build tools do) makes custom commands such as `true` resolve to the Darwin
+# executable targets of the same name, which cannot run on the host.
+set(CMAKE_CROSSCOMPILING TRUE)
+
 enable_language(ASM)
 
 # CMake's default ASM rule appends to an existing archive (unlike C/C++), which fails once ranlib has made it fat
