minecraft-pi-reborn/cmake/options/prebuilt-armhf-toolchain.cmake

77 lines
2.8 KiB
CMake
Raw Normal View History

2023-11-24 08:07:06 +00:00
# Pick Archive
2024-08-02 05:03:20 +00:00
set(toolchain_version "13.3.rel1")
2022-08-06 00:08:13 +00:00
execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE)
if(arch STREQUAL "x86_64")
2023-11-24 08:07:06 +00:00
set(toolchain_file "arm-gnu-toolchain-${toolchain_version}-x86_64-arm-none-linux-gnueabihf.tar.xz")
2022-08-06 00:08:13 +00:00
elseif(arch STREQUAL "aarch64" OR arch STREQUAL "armv8b" OR arch STREQUAL "armv8l")
2023-11-24 08:07:06 +00:00
set(toolchain_file "arm-gnu-toolchain-${toolchain_version}-aarch64-arm-none-linux-gnueabihf.tar.xz")
2022-08-06 00:08:13 +00:00
else()
message(FATAL_ERROR "Unable To Download Prebuilt ARMHF Toolchain")
endif()
# Download If Needed
2022-08-09 22:38:48 +00:00
include(FetchContent)
FetchContent_Declare(
prebuilt-armhf-toolchain
2024-01-20 07:10:18 +00:00
URL "${CMAKE_CURRENT_LIST_DIR}/../../archives/${toolchain_file}"
2022-08-09 22:38:48 +00:00
)
FetchContent_MakeAvailable(prebuilt-armhf-toolchain)
2022-08-10 21:21:38 +00:00
set(toolchain_dir "${prebuilt-armhf-toolchain_SOURCE_DIR}")
2022-08-09 22:38:48 +00:00
# Force Toolchain
file(WRITE "${toolchain_dir}/toolchain.cmake"
"set(CMAKE_C_COMPILER \"\${CMAKE_CURRENT_LIST_DIR}/bin/arm-none-linux-gnueabihf-gcc\")\n"
"set(CMAKE_CXX_COMPILER \"\${CMAKE_CURRENT_LIST_DIR}/bin/arm-none-linux-gnueabihf-g++\")\n"
"set(CMAKE_SYSTEM_NAME \"Linux\")\n"
"set(CMAKE_SYSTEM_PROCESSOR \"arm\")\n"
2022-09-23 21:55:38 +00:00
"set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n"
2022-08-09 22:38:48 +00:00
)
2024-11-24 22:42:36 +00:00
force_set(MCPI_CMAKE_TOOLCHAIN_FILE "${toolchain_dir}/toolchain.cmake" FILEPATH)
2022-07-07 22:54:11 +00:00
# Build Sysroot
2022-08-10 21:21:38 +00:00
set(sysroot_dir "${CMAKE_CURRENT_BINARY_DIR}/bundled-armhf-sysroot")
2022-08-09 22:38:48 +00:00
if("${toolchain_dir}/bin/arm-none-linux-gnueabihf-gcc" IS_NEWER_THAN "${sysroot_dir}")
2022-07-07 22:54:11 +00:00
# Create Directory
2022-08-09 22:38:48 +00:00
file(REMOVE_RECURSE "${sysroot_dir}")
2022-07-07 22:54:11 +00:00
file(MAKE_DIRECTORY "${sysroot_dir}")
# Copy Files From Toolchain
file(
COPY "${toolchain_dir}/arm-none-linux-gnueabihf/libc/"
DESTINATION "${sysroot_dir}"
USE_SOURCE_PERMISSIONS
FILES_MATCHING
PATTERN "*.so*"
)
# Delete Unneeded Files
file(REMOVE_RECURSE "${sysroot_dir}/usr/lib/audit")
2023-11-11 06:33:19 +00:00
file(REMOVE_RECURSE "${sysroot_dir}/usr/lib/gconv")
2022-07-07 22:54:11 +00:00
# Strip Files
2024-11-18 23:47:13 +00:00
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
2024-06-08 20:30:39 +00:00
file(GLOB_RECURSE files LIST_DIRECTORIES FALSE "${sysroot_dir}/*")
foreach(file IN LISTS files)
2024-11-15 20:26:33 +00:00
execute_process(
COMMAND "${toolchain_dir}/bin/arm-none-linux-gnueabihf-strip" "${file}"
RESULT_VARIABLE ret
ERROR_QUIET
)
2024-06-08 20:30:39 +00:00
# Check Result
if(NOT ret EQUAL 0)
# Delete Invalid Files
file(REMOVE "${file}")
endif()
endforeach()
endif()
2022-07-07 22:54:11 +00:00
endif()
# Install Sysroot (Skipping Empty Directories)
2024-01-16 06:45:52 +00:00
function(install_arm_sysroot)
file(GLOB_RECURSE files LIST_DIRECTORIES FALSE RELATIVE "${sysroot_dir}" "${sysroot_dir}/*")
foreach(file IN LISTS files)
2024-11-15 20:26:33 +00:00
cmake_path(GET file PARENT_PATH parent)
2024-01-16 06:45:52 +00:00
install(PROGRAMS "${sysroot_dir}/${file}" DESTINATION "${MCPI_INSTALL_DIR}/sysroot/${parent}")
endforeach()
endfunction()