Add basic UEFI support

This commit is contained in:
Duncan Ogilvie
2024-11-11 23:37:12 +01:00
parent 03f4b117a3
commit 80b6c1a4f3
3 changed files with 22 additions and 0 deletions

13
cmake/Platform/UEFI.cmake Normal file
View File

@@ -0,0 +1,13 @@
# References:
# - https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6630
# - https://gitlab.kitware.com/cmake/cmake/-/issues/16538
# - https://kubasejdak.com/how-to-cross-compile-for-embedded-with-cmake-like-a-champ
include(Platform/Generic)
set(CMAKE_EXECUTABLE_SUFFIX ".efi")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".efi")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
# UEFI APIs might expect 16-bit wchar_t
add_compile_options(-fshort-wchar)

View File

@@ -0,0 +1,2 @@
set(ZIG_TARGET "x86_64-uefi-gnu")
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)

View File

@@ -20,6 +20,10 @@ elseif(ZIG_OS STREQUAL "macos")
set(CMAKE_SYSTEM_NAME "Darwin")
elseif(ZIG_OS STREQUAL "freestanding")
set(CMAKE_SYSTEM_NAME "Generic")
elseif(ZIG_OS STREQUAL "uefi")
set(CMAKE_SYSTEM_NAME "UEFI")
# Fix compiler detection (lld-link: error: <root>: undefined symbol: EfiMain)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
else()
# NOTE: If this happens, add a new case with one of the following system names:
# https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html#system-names-known-to-cmake
@@ -42,3 +46,6 @@ endif()
set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar${SCRIPT_SUFFIX}")
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib${SCRIPT_SUFFIX}")
set(CMAKE_RC_COMPILER "${CMAKE_CURRENT_LIST_DIR}/zig-rc${SCRIPT_SUFFIX}")
# Add custom UEFI platform to module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")