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 <matt@kry10.com>
This commit is contained in:
Matthew Brecknell
2022-04-04 16:50:39 +10:00
committed by Matthew Brecknell
parent 756a37b7d3
commit 1612a7f61d

View File

@@ -147,8 +147,10 @@ if(DEFINED KernelDTSList AND (NOT "${KernelDTSList}" STREQUAL ""))
if(error) if(error)
message(FATAL_ERROR "Failed to compile DTS to DTB: ${KernelDTBPath}") message(FATAL_ERROR "Failed to compile DTS to DTB: ${KernelDTBPath}")
endif() endif()
# CMAKE_HOST_APPLE is a built-in CMake variable # The macOS and GNU coreutils `stat` utilities have different interfaces.
if(CMAKE_HOST_APPLE) # 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") set(STAT_ARGS "-f%z")
else() else()
set(STAT_ARGS "-c '%s'") set(STAT_ARGS "-c '%s'")