From 1612a7f61d1583859373edc3cf290daa2e719d1a Mon Sep 17 00:00:00 2001 From: Matthew Brecknell Date: Mon, 4 Apr 2022 16:50:39 +1000 Subject: [PATCH] cmake: allow building with coreutils on macOS The seL4 CMake build currently uses the `stat` utility to determine the size of the flattened device tree file. The `stat` utilities in macOS and GNU coreutils have different interfaces, the CMake build needs to determine which one it's using. This change supports building on macOS with GNU coreutils in the PATH, by only using the macOS `stat` interface with `/usr/bin/stat` on a macOS host, and otherwise assuming GNU coreutils. In future, we might be able to avoid the `stat` utility altogether, by using the built-in `file (SIZE ...)` command that became available in CMake version 3.14. For now, we avoid updating our build dependencies. Signed-off-by: Matthew Brecknell --- config.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config.cmake b/config.cmake index 9c4ae9832..589a93f63 100644 --- a/config.cmake +++ b/config.cmake @@ -147,8 +147,10 @@ if(DEFINED KernelDTSList AND (NOT "${KernelDTSList}" STREQUAL "")) if(error) message(FATAL_ERROR "Failed to compile DTS to DTB: ${KernelDTBPath}") endif() - # CMAKE_HOST_APPLE is a built-in CMake variable - if(CMAKE_HOST_APPLE) + # The macOS and GNU coreutils `stat` utilities have different interfaces. + # Check if we're using the macOS version, otherwise assume GNU coreutils. + # CMAKE_HOST_APPLE is a built-in CMake variable. + if(CMAKE_HOST_APPLE AND "${STAT_TOOL}" STREQUAL "/usr/bin/stat") set(STAT_ARGS "-f%z") else() set(STAT_ARGS "-c '%s'")