From 91ff082c979b995ab76a30bfd28c66195b1095af Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 20 Jan 2024 02:10:18 -0500 Subject: [PATCH] Create AppImages Using CPack --- CMakeLists.txt | 84 ++++++++++--------- cmake/cpack/appimage.cmake | 62 ++++++++++++++ cmake/cpack/packaging.cmake | 38 +++++++++ cmake/{ => options}/core-options.cmake | 0 cmake/{ => options}/extra-options.cmake | 3 - cmake/{ => options}/paths.cmake | 0 .../prebuilt-armhf-toolchain.cmake | 2 +- cmake/{ => util}/embed-resource.cmake | 0 cmake/{ => util}/util.cmake | 7 ++ dependencies/LIEF/CMakeLists.txt | 2 + dependencies/glfw/CMakeLists.txt | 2 + dependencies/qemu/CMakeLists.txt | 16 +++- dependencies/zenity/CMakeLists.txt | 2 + scripts/package.sh | 32 ++----- 14 files changed, 177 insertions(+), 73 deletions(-) create mode 100644 cmake/cpack/appimage.cmake create mode 100644 cmake/cpack/packaging.cmake rename cmake/{ => options}/core-options.cmake (100%) rename cmake/{ => options}/extra-options.cmake (97%) rename cmake/{ => options}/paths.cmake (100%) rename cmake/{ => options}/prebuilt-armhf-toolchain.cmake (97%) rename cmake/{ => util}/embed-resource.cmake (100%) rename cmake/{ => util}/util.cmake (84%) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb5252df8..705ca513d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24.0) endif() # Core Options -include(cmake/core-options.cmake) +include(cmake/options/core-options.cmake) # Build Mode if(NOT CMAKE_BUILD_TYPE) @@ -17,12 +17,12 @@ endif() project(minecraft-pi-reborn) # Utility Functions -include(cmake/util.cmake) +include(cmake/util/util.cmake) # Sanity Checks string(CONCAT ARM_SANITY_CHECK "include(CheckSymbolExists)\n" - "check_symbol_exists(\"__arm__\" \"\" IS_ARM_TARGETING)\n" + "check_symbol_exists(\"__arm__\" \"\" IS_ARM_TARGETING)" ) if(BUILD_ARM_COMPONENTS) string(CONCAT ARM_SANITY_CHECK @@ -35,42 +35,10 @@ endif() cmake_language(EVAL CODE "${ARM_SANITY_CHECK}") # Extra Options -include(cmake/extra-options.cmake) +include(cmake/options/extra-options.cmake) -# Superbuild -if(BUILD_NATIVE_COMPONENTS) - include(ExternalProject) - # Arguments - set(ARM_OPTIONS "${MCPI_OPTIONS}") - list(APPEND ARM_OPTIONS "-DMCPI_BUILD_MODE:STRING=arm") - list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_MESSAGE:STRING=NEVER") - list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=/install") - if(NOT MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN) - if(DEFINED CMAKE_TOOLCHAIN_FILE) - list(APPEND ARM_OPTIONS "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}") - endif() - else() - list(APPEND ARM_OPTIONS "-DMCPI_USE_PREBUILT_ARMHF_TOOLCHAIN:BOOL=TRUE") - endif() - # Build - ExternalProject_Add(arm-components - DOWNLOAD_COMMAND "" - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" - CMAKE_CACHE_ARGS ${ARM_OPTIONS} - INSTALL_COMMAND "${CMAKE_COMMAND}" "-E" "rm" "-rf" "/install" - COMMAND - "${CMAKE_COMMAND}" "-E" "env" - "DESTDIR=" - "${CMAKE_COMMAND}" "--install" "" - USES_TERMINAL_CONFIGURE TRUE - USES_TERMINAL_BUILD TRUE - USES_TERMINAL_INSTALL TRUE - BUILD_ALWAYS TRUE - ) - # Install - ExternalProject_Get_Property(arm-components INSTALL_DIR) - install(DIRECTORY "${INSTALL_DIR}/install/${MCPI_INSTALL_DIR}/" DESTINATION "${MCPI_INSTALL_DIR}") -endif() +# Paths +include(cmake/options/paths.cmake) # Required Compile Flags string(CONCAT COMPILE_FLAGS_SETUP @@ -170,3 +138,43 @@ if(BUILD_ARM_COMPONENTS) ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sdk.cmake" DESTINATION "${MCPI_SDK_DIR}") endif() + +# Packaging +if(BUILD_NATIVE_COMPONENTS) + include(cmake/cpack/packaging.cmake) +endif() + +# Superbuild +if(BUILD_NATIVE_COMPONENTS) + include(ExternalProject) + # Arguments + set(ARM_OPTIONS "${MCPI_OPTIONS}") + list(APPEND ARM_OPTIONS "-DMCPI_BUILD_MODE:STRING=arm") + list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_MESSAGE:STRING=NEVER") + list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=/install") + if(NOT MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN) + if(DEFINED CMAKE_TOOLCHAIN_FILE) + list(APPEND ARM_OPTIONS "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}") + endif() + else() + list(APPEND ARM_OPTIONS "-DMCPI_USE_PREBUILT_ARMHF_TOOLCHAIN:BOOL=TRUE") + endif() + # Build + ExternalProject_Add(arm-components + DOWNLOAD_COMMAND "" + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" + CMAKE_CACHE_ARGS ${ARM_OPTIONS} + INSTALL_COMMAND "${CMAKE_COMMAND}" "-E" "rm" "-rf" "/install" + COMMAND + "${CMAKE_COMMAND}" "-E" "env" + "DESTDIR=" + "${CMAKE_COMMAND}" "--install" "" + USES_TERMINAL_CONFIGURE TRUE + USES_TERMINAL_BUILD TRUE + USES_TERMINAL_INSTALL TRUE + BUILD_ALWAYS TRUE + ) + # Install + ExternalProject_Get_Property(arm-components INSTALL_DIR) + install(DIRECTORY "${INSTALL_DIR}/install/${MCPI_INSTALL_DIR}/" DESTINATION "${MCPI_INSTALL_DIR}") +endif() diff --git a/cmake/cpack/appimage.cmake b/cmake/cpack/appimage.cmake new file mode 100644 index 000000000..f8011d6a0 --- /dev/null +++ b/cmake/cpack/appimage.cmake @@ -0,0 +1,62 @@ +# Downlaod AppImage Runtime +set(RUNTIME_ARCH "unknown") +if(CPACK_MCPI_ARCH STREQUAL "armhf") + set(RUNTIME_ARCH "armhf") +elseif(CPACK_MCPI_ARCH STREQUAL "arm64") + set(RUNTIME_ARCH "aarch64") +elseif(CPACK_MCPI_ARCH STREQUAL "amd64") + set(RUNTIME_ARCH "x86_64") +endif() +set(RUNTIME "${CPACK_TOPLEVEL_DIRECTORY}/runtime") +file(DOWNLOAD + "https://github.com/AppImage/AppImageKit/releases/download/continuous/runtime-${RUNTIME_ARCH}" + "${RUNTIME}" + STATUS DOWNLOAD_STATUS +) +list(GET DOWNLOAD_STATUS 0 STATUS_CODE) +list(GET DOWNLOAD_STATUS 1 ERROR_MESSAGE) +if(NOT STATUS_CODE EQUAL 0) + message(FATAL_ERROR "Unable To Downlopad AppImage Runtime: ${ERROR_MESSAGE}") +else() + message(STATUS "Downloaded AppImage Runtime: ${RUNTIME}") +endif() + +# Package +set(APPIMAGE_ARCH "unknown") +if(CPACK_MCPI_ARCH STREQUAL "armhf") + set(APPIMAGE_ARCH "arm") +elseif(CPACK_MCPI_ARCH STREQUAL "arm64") + set(APPIMAGE_ARCH "arm_aarch64") +elseif(CPACK_MCPI_ARCH STREQUAL "amd64") + set(APPIMAGE_ARCH "x86_64") +endif() +execute_process( + COMMAND + "${CMAKE_COMMAND}" "-E" "env" + "ARCH=${APPIMAGE_ARCH}" + "appimagetool" + "--updateinformation" "zsync|https://gitea.thebrokenrail.com/minecraft-pi-reborn/minecraft-pi-reborn/releases/download/latest/${CPACK_PACKAGE_FILE_NAME_ZSYNC}.AppImage.zsync" + "--runtime-file" "${RUNTIME}" + "--comp" "xz" + "${CPACK_TEMPORARY_DIRECTORY}" + "${CPACK_PACKAGE_FILE_NAME}.AppImage" + WORKING_DIRECTORY "${CPACK_PACKAGE_DIRECTORY}" + RESULT_VARIABLE APPIMAGETOOL_RESULT +) +if(NOT APPIMAGETOOL_RESULT EQUAL 0) + message(FATAL_ERROR "Unable Package AppImage") +endif() + +# Rename ZSync File +file(RENAME "${CPACK_PACKAGE_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}.AppImage.zsync" "${CPACK_PACKAGE_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME_ZSYNC}.AppImage.zsync") + +# Summary Message +function(check_file name) + if(EXISTS "${CPACK_PACKAGE_DIRECTORY}/${name}") + message(STATUS "Generated: ${name}") + else() + message(FATAL_ERROR "Missing File: ${name}") + endif() +endfunction() +check_file("${CPACK_PACKAGE_FILE_NAME}.AppImage") +check_file("${CPACK_PACKAGE_FILE_NAME_ZSYNC}.AppImage.zsync") diff --git a/cmake/cpack/packaging.cmake b/cmake/cpack/packaging.cmake new file mode 100644 index 000000000..e1de6aa76 --- /dev/null +++ b/cmake/cpack/packaging.cmake @@ -0,0 +1,38 @@ +# Determine Architecture +set(CPACK_MCPI_ARCH "unknown") +include(CheckSymbolExists) +function(check_arch symbol name) + set(CMAKE_REQUIRED_QUIET TRUE) + check_symbol_exists("${symbol}" "" "IS_ARCH_${name}") + unset(CMAKE_REQUIRED_QUIET) + if("${IS_ARCH_${name}}") + set(CPACK_MCPI_ARCH "${name}" PARENT_SCOPE) + endif() +endfunction() +check_arch("__arm__" "armhf") +check_arch("__aarch64__" "arm64") +check_arch("__x86_64__" "amd64") + +# CPack +set(CPACK_PACKAGE_NAME "${MCPI_VARIANT_NAME}") +set(CPACK_PACKAGE_VENDOR "TheBrokenRail & Mojang AB") +set(CPACK_VERBATIM_VARIABLES TRUE) +set(CPACK_MONOLITHIC_INSTALL TRUE) +set(CPACK_PACKAGE_FILE_NAME "${MCPI_VARIANT_NAME}-${MCPI_VERSION}-${CPACK_MCPI_ARCH}") +set(CPACK_PACKAGE_FILE_NAME_ZSYNC "${MCPI_VARIANT_NAME}-latest-${CPACK_MCPI_ARCH}") + +# Version +string(REPLACE "." ";" VERSION_LIST "${MCPI_VERSION}") +list(GET VERSION_LIST 0 CPACK_PACKAGE_VERSION_MAJOR) +list(GET VERSION_LIST 1 CPACK_PACKAGE_VERSION_MINOR) +list(GET VERSION_LIST 2 CPACK_PACKAGE_VERSION_PATCH) + +# AppImage +if(MCPI_IS_APPIMAGE_BUILD) + set(CPACK_GENERATOR "External") + set(CPACK_EXTERNAL_ENABLE_STAGING TRUE) + set(CPACK_EXTERNAL_PACKAGE_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/appimage.cmake") +endif() + +# Package +include(CPack) diff --git a/cmake/core-options.cmake b/cmake/options/core-options.cmake similarity index 100% rename from cmake/core-options.cmake rename to cmake/options/core-options.cmake diff --git a/cmake/extra-options.cmake b/cmake/options/extra-options.cmake similarity index 97% rename from cmake/extra-options.cmake rename to cmake/options/extra-options.cmake index eb727e90a..17b2c6231 100644 --- a/cmake/extra-options.cmake +++ b/cmake/options/extra-options.cmake @@ -61,6 +61,3 @@ mcpi_option(APP_TITLE "App Title" STRING "${DEFAULT_APP_TITLE}") # Skin Server mcpi_option(SKIN_SERVER "Skin Server" STRING "https://raw.githubusercontent.com/MCPI-Revival/Skins/data") - -# Paths -include("${CMAKE_CURRENT_LIST_DIR}/paths.cmake") diff --git a/cmake/paths.cmake b/cmake/options/paths.cmake similarity index 100% rename from cmake/paths.cmake rename to cmake/options/paths.cmake diff --git a/cmake/prebuilt-armhf-toolchain.cmake b/cmake/options/prebuilt-armhf-toolchain.cmake similarity index 97% rename from cmake/prebuilt-armhf-toolchain.cmake rename to cmake/options/prebuilt-armhf-toolchain.cmake index d4c6fb6f1..f9181491d 100644 --- a/cmake/prebuilt-armhf-toolchain.cmake +++ b/cmake/options/prebuilt-armhf-toolchain.cmake @@ -13,7 +13,7 @@ endif() include(FetchContent) FetchContent_Declare( prebuilt-armhf-toolchain - URL "${CMAKE_CURRENT_LIST_DIR}/../archives/${toolchain_file}" + URL "${CMAKE_CURRENT_LIST_DIR}/../../archives/${toolchain_file}" ) FetchContent_MakeAvailable(prebuilt-armhf-toolchain) set(toolchain_dir "${prebuilt-armhf-toolchain_SOURCE_DIR}") diff --git a/cmake/embed-resource.cmake b/cmake/util/embed-resource.cmake similarity index 100% rename from cmake/embed-resource.cmake rename to cmake/util/embed-resource.cmake diff --git a/cmake/util.cmake b/cmake/util/util.cmake similarity index 84% rename from cmake/util.cmake rename to cmake/util/util.cmake index 20d4f71e0..ae67a4a38 100644 --- a/cmake/util.cmake +++ b/cmake/util/util.cmake @@ -24,3 +24,10 @@ function(embed_resource target file) # Add To Target target_sources("${target}" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") endfunction() + +# Nicer Output +function(message log_level) + if((NOT MESSAGE_QUIET) OR (NOT (log_level STREQUAL "STATUS" OR log_level MATCHES "^CHECK_"))) + _message("${log_level}" ${ARGN}) + endif() +endfunction() diff --git a/dependencies/LIEF/CMakeLists.txt b/dependencies/LIEF/CMakeLists.txt index 3cbdb1861..83a2238a2 100644 --- a/dependencies/LIEF/CMakeLists.txt +++ b/dependencies/LIEF/CMakeLists.txt @@ -24,7 +24,9 @@ set(LIEF_OAT FALSE CACHE BOOL "" FORCE) set(LIEF_VDEX FALSE CACHE BOOL "" FORCE) # Download +set(MESSAGE_QUIET TRUE) add_subdirectory(src EXCLUDE_FROM_ALL) +unset(MESSAGE_QUIET) # Ensure Build add_custom_target(LIEF-build ALL DEPENDS LIB_LIEF) diff --git a/dependencies/glfw/CMakeLists.txt b/dependencies/glfw/CMakeLists.txt index 23afb2174..f2b250d9b 100644 --- a/dependencies/glfw/CMakeLists.txt +++ b/dependencies/glfw/CMakeLists.txt @@ -16,7 +16,9 @@ set(GLFW_BUILD_COCOA FALSE CACHE BOOL "" FORCE) set(GLFW_BUILD_X11 TRUE CACHE BOOL "" FORCE) set(GLFW_BUILD_WAYLAND TRUE CACHE BOOL "" FORCE) set(GLFW_LIBRARY_TYPE "SHARED" CACHE BOOL "" FORCE) +set(MESSAGE_QUIET TRUE) add_subdirectory(src EXCLUDE_FROM_ALL) +unset(MESSAGE_QUIET) # Ensure Build add_custom_target(glfw-build ALL DEPENDS glfw) diff --git a/dependencies/qemu/CMakeLists.txt b/dependencies/qemu/CMakeLists.txt index 3cf3c4c03..4ca7426ee 100644 --- a/dependencies/qemu/CMakeLists.txt +++ b/dependencies/qemu/CMakeLists.txt @@ -11,17 +11,25 @@ if(MCPI_IS_FLATPAK_BUILD) set(QEMU_PATCH "sed" "-i" "s/libdrm/libdrm-dis/g" "/meson.build") endif() +# Inherit Make Jobserver ()If Present) +include(ProcessorCount) +ProcessorCount(NPROC) +set(MAKE "make" "-j${NPROC}") +if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") + set(MAKE "$(MAKE)") +endif() + # Build include(ExternalProject) -set(pkgconfig_env "") +set(PKGCONFIG_ENV "") if(DEFINED ENV{PKG_CONFIG_LIBDIR}) - set(pkgconfig_env "PKG_CONFIG_LIBDIR=$ENV{PKG_CONFIG_LIBDIR}") + set(PKGCONFIG_ENV "PKG_CONFIG_LIBDIR=$ENV{PKG_CONFIG_LIBDIR}") endif() ExternalProject_Add(qemu URL "${CMAKE_CURRENT_SOURCE_DIR}/../../archives/qemu-${QEMU_VERSION}.tar.xz" CONFIGURE_COMMAND "${CMAKE_COMMAND}" "-E" "env" - ${pkgconfig_env} + ${PKGCONFIG_ENV} "CFLAGS=-s" "CXXFLAGS=-s" "/configure" @@ -33,7 +41,7 @@ ExternalProject_Add(qemu "--target-list=arm-linux-user" "--without-default-features" USES_TERMINAL_CONFIGURE TRUE - BUILD_COMMAND "make" "qemu-arm" + BUILD_COMMAND ${MAKE} "qemu-arm" USES_TERMINAL_BUILD TRUE INSTALL_COMMAND "" TEST_COMMAND "" diff --git a/dependencies/zenity/CMakeLists.txt b/dependencies/zenity/CMakeLists.txt index df761c16f..752744801 100644 --- a/dependencies/zenity/CMakeLists.txt +++ b/dependencies/zenity/CMakeLists.txt @@ -6,7 +6,9 @@ add_compile_options(-w) ## Zenity # Download +set(MESSAGE_QUIET TRUE) add_subdirectory(src EXCLUDE_FROM_ALL) +unset(MESSAGE_QUIET) # Ensure Build add_custom_target(zenity-build ALL DEPENDS zenity) diff --git a/scripts/package.sh b/scripts/package.sh index dd6e3fb2b..e00c99a7f 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -11,32 +11,10 @@ ARCH="$(echo "$2" | tr '[:upper:]' '[:lower:]')" ./scripts/setup.sh "${MODE}" "${ARCH}" -DMCPI_IS_APPIMAGE_BUILD=ON ./scripts/build.sh "${MODE}" "${ARCH}" -# Download Runtime -mkdir -p build/appimage -if [ ! -f "build/appimage/runtime-${ARCH}" ]; then - case "${ARCH}" in - 'armhf') RUNTIME_ARCH='armhf';; - 'arm64') RUNTIME_ARCH='aarch64';; - 'i386') RUNTIME_ARCH='i686';; - 'amd64') RUNTIME_ARCH='x86_64';; - esac - wget -O "build/appimage/runtime-${ARCH}" "https://github.com/AppImage/AppImageKit/releases/download/continuous/runtime-${RUNTIME_ARCH}" -fi - # Package -case "${ARCH}" in - 'armhf') APPIMAGE_ARCH='arm';; - 'arm64') APPIMAGE_ARCH='arm_aarch64';; - 'i386') APPIMAGE_ARCH='i686';; - 'amd64') APPIMAGE_ARCH='x86_64';; -esac -ARCH="${APPIMAGE_ARCH}" appimagetool \ - --updateinformation "zsync|https://gitea.thebrokenrail.com/minecraft-pi-reborn/minecraft-pi-reborn/releases/download/latest/${NAME}-${MODE}-latest-${ARCH}.AppImage.zsync" \ - --runtime-file "build/appimage/runtime-${ARCH}" \ - --comp xz \ - "./out/${MODE}-${ARCH}" \ - "./out/${NAME}-${MODE}-$(cat VERSION)-${ARCH}.AppImage" +cd "build/${MODE}-${ARCH}" +rm -f *.AppImage* +cmake --build . --target package -# Move ZSync -rm -f "./out/${NAME}-${MODE}-latest-${ARCH}.AppImage.zsync" -mv "./${NAME}-${MODE}-$(cat VERSION)-${ARCH}.AppImage.zsync" "./out/${NAME}-${MODE}-latest-${ARCH}.AppImage.zsync" +# Copy Output +cp *.AppImage* ../../out