Add basic UEFI support
This commit is contained in:
13
cmake/Platform/UEFI.cmake
Normal file
13
cmake/Platform/UEFI.cmake
Normal 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)
|
||||||
2
cmake/zig-toolchain-uefi64.cmake
Normal file
2
cmake/zig-toolchain-uefi64.cmake
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
set(ZIG_TARGET "x86_64-uefi-gnu")
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)
|
||||||
@@ -20,6 +20,10 @@ elseif(ZIG_OS STREQUAL "macos")
|
|||||||
set(CMAKE_SYSTEM_NAME "Darwin")
|
set(CMAKE_SYSTEM_NAME "Darwin")
|
||||||
elseif(ZIG_OS STREQUAL "freestanding")
|
elseif(ZIG_OS STREQUAL "freestanding")
|
||||||
set(CMAKE_SYSTEM_NAME "Generic")
|
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()
|
else()
|
||||||
# NOTE: If this happens, add a new case with one of the following system names:
|
# 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
|
# 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_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar${SCRIPT_SUFFIX}")
|
||||||
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib${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}")
|
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}")
|
||||||
|
|||||||
Reference in New Issue
Block a user