Allow Specifying Custom Sysroot

This commit is contained in:
TheBrokenRail 2022-05-03 21:04:22 -04:00
parent f2a9b274d2
commit ead7e575f3

View File

@ -1,87 +1,94 @@
project(armhf-sysroot) project(armhf-sysroot)
# Packages # Allow Custom Sysroot
set(APT_PACKAGES "libc6" "libstdc++6") set(MCPI_CUSTOM_BUNDLED_ARMHF_SYSROOT "" CACHE PATH "Custom Bundled ARMHF Sysroot")
if(MCPI_CUSTOM_BUNDLED_ARMHF_SYSROOT)
# Custom Sysroot
set(SYSROOT_DIR "${MCPI_CUSTOM_BUNDLED_ARMHF_SYSROOT}")
else()
# Download From APT
set(APT_PACKAGES "libc6" "libstdc++6")
# Trigger Reconfigure On APT Change # Reconfigure CMake If APT Data Is Changed
file(GLOB_RECURSE APT_FILES "apt/*") file(GLOB_RECURSE APT_FILES "apt/*")
foreach(APT_FILE IN LISTS APT_FILES) foreach(APT_FILE IN LISTS APT_FILES)
set_property( set_property(
DIRECTORY DIRECTORY
APPEND APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS "${APT_FILE}" PROPERTY CMAKE_CONFIGURE_DEPENDS "${APT_FILE}"
)
endforeach()
# Copy To Binary Directory
set(APT_DIR "${CMAKE_CURRENT_BINARY_DIR}/apt-build")
file(REMOVE_RECURSE "${APT_DIR}")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/apt/." DESTINATION "${APT_DIR}")
# Make Directories
file(MAKE_DIRECTORY "${APT_DIR}/apt.conf.d")
file(MAKE_DIRECTORY "${APT_DIR}/preferences.d")
file(MAKE_DIRECTORY "${APT_DIR}/dpkg")
file(TOUCH "${APT_DIR}/dpkg/status")
# Create APT Config
string(CONCAT APT_CONFIG
"Dir \"${APT_DIR}\";\n"
"Dir::State \"${APT_DIR}\";\n"
"Dir::Cache \"${APT_DIR}\";\n"
"Dir::Etc::Main \"${APT_DIR}/apt.conf\";\n"
"Dir::Etc::Parts \"${APT_DIR}/apt.conf.d\";\n"
"Dir::Etc::SourceList \"${APT_DIR}/sources.list\";\n"
"Dir::Etc::SourceListParts \"${APT_DIR}/sources.list.d\";\n"
"Dir::Etc::PreferencesParts \"${APT_DIR}/preferences.d\";\n"
"Dir::Etc::TrustedParts \"${APT_DIR}/keys\";\n"
"Dir::State::status \"${APT_DIR}/dpkg/status\";\n"
"Dir::Ignore-Files-Silently \"False\";\n"
"APT::Install-Recommends \"False\";\n"
"APT::Install-Suggests \"False\";\n"
"APT::Immediate-Configure \"False\";\n"
"APT::Architecture \"armhf\";\n"
"APT::Architectures { \"armhf\"; }\n"
"Acquire::Languages \"none\";\n"
"APT::Get::AllowUnauthenticated \"False\";\n"
"Acquire::AllowInsecureRepositories \"False\";\n"
) )
endforeach() file(WRITE "${APT_DIR}/apt.conf" "${APT_CONFIG}")
# Copy To Binary Directory # Environment
set(APT_DIR "${CMAKE_CURRENT_BINARY_DIR}/apt-build") set(APT_ENV
file(REMOVE_RECURSE "${APT_DIR}") "${CMAKE_COMMAND}"
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/apt/." DESTINATION "${APT_DIR}") -E env
# Make Directories "DEBIAN_FRONTEND=noninteractive"
file(MAKE_DIRECTORY "${APT_DIR}/apt.conf.d") "APT_CONFIG=${APT_DIR}/apt.conf"
file(MAKE_DIRECTORY "${APT_DIR}/preferences.d") )
file(MAKE_DIRECTORY "${APT_DIR}/dpkg")
file(TOUCH "${APT_DIR}/dpkg/status")
# Create APT Config # Create Sysroot Directory
string(CONCAT APT_CONFIG set(SYSROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/sysroot")
"Dir \"${APT_DIR}\";\n" file(REMOVE_RECURSE "${SYSROOT_DIR}")
"Dir::State \"${APT_DIR}\";\n" file(MAKE_DIRECTORY "${SYSROOT_DIR}")
"Dir::Cache \"${APT_DIR}\";\n"
"Dir::Etc::Main \"${APT_DIR}/apt.conf\";\n"
"Dir::Etc::Parts \"${APT_DIR}/apt.conf.d\";\n"
"Dir::Etc::SourceList \"${APT_DIR}/sources.list\";\n"
"Dir::Etc::SourceListParts \"${APT_DIR}/sources.list.d\";\n"
"Dir::Etc::PreferencesParts \"${APT_DIR}/preferences.d\";\n"
"Dir::Etc::TrustedParts \"${APT_DIR}/keys\";\n"
"Dir::State::status \"${APT_DIR}/dpkg/status\";\n"
"Dir::Ignore-Files-Silently \"False\";\n"
"APT::Install-Recommends \"False\";\n"
"APT::Install-Suggests \"False\";\n"
"APT::Immediate-Configure \"False\";\n"
"APT::Architecture \"armhf\";\n"
"APT::Architectures { \"armhf\"; }\n"
"Acquire::Languages \"none\";\n"
"APT::Get::AllowUnauthenticated \"False\";\n"
"Acquire::AllowInsecureRepositories \"False\";\n"
)
file(WRITE "${APT_DIR}/apt.conf" "${APT_CONFIG}")
# Environment # Download
set(APT_ENV add_custom_command(
"${CMAKE_COMMAND}" OUTPUT "${APT_DIR}/.update-stamp"
-E env COMMAND ${APT_ENV} apt-get update
DEBIAN_FRONTEND=noninteractive COMMAND "${CMAKE_COMMAND}" -E touch "${APT_DIR}/.update-stamp"
"APT_CONFIG=${APT_DIR}/apt.conf" VERBATIM
) )
add_custom_command(
# Create Sysroot Directory OUTPUT "${APT_DIR}/.download-stamp"
set(SYSROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/sysroot") DEPENDS "${APT_DIR}/.update-stamp"
file(REMOVE_RECURSE "${SYSROOT_DIR}") COMMAND ${APT_ENV} apt-get install -y --no-install-recommends --download-only ${APT_PACKAGES}
file(MAKE_DIRECTORY "${SYSROOT_DIR}") COMMAND "${CMAKE_COMMAND}" -E touch "${APT_DIR}/.download-stamp"
VERBATIM
# Download )
add_custom_command( add_custom_command(
OUTPUT "${APT_DIR}/.update-stamp" OUTPUT "${APT_DIR}/.extract-stamp"
COMMAND ${APT_ENV} apt-get update DEPENDS "${APT_DIR}/.download-stamp"
COMMAND touch ARGS "${APT_DIR}/.update-stamp" COMMAND ${APT_ENV} find "${APT_DIR}/archives" -maxdepth 1 -type f -name "*.deb" -exec dpkg -x {} "${SYSROOT_DIR}" ";"
VERBATIM COMMAND "${CMAKE_COMMAND}" -E touch "${APT_DIR}/.extract-stamp"
) VERBATIM
add_custom_command( )
OUTPUT "${APT_DIR}/.download-stamp" add_custom_target(armhf-sysroot ALL DEPENDS "${APT_DIR}/.extract-stamp")
DEPENDS "${APT_DIR}/.update-stamp" endif()
COMMAND ${APT_ENV} apt-get install -y --no-install-recommends --download-only ${APT_PACKAGES}
COMMAND touch ARGS "${APT_DIR}/.download-stamp"
VERBATIM
)
add_custom_command(
OUTPUT "${APT_DIR}/.extract-stamp"
DEPENDS "${APT_DIR}/.download-stamp"
COMMAND ${APT_ENV} find "${APT_DIR}/archives" -maxdepth 1 -type f -name "*.deb" -exec dpkg -x {} "${SYSROOT_DIR}" ";"
COMMAND touch ARGS "${APT_DIR}/.extract-stamp"
VERBATIM
)
add_custom_target(armhf-sysroot ALL DEPENDS "${APT_DIR}/.extract-stamp")
# Install # Install
install( install(