From ac7e337809ffddd6568f310044a421cafc9c5a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 16 May 2023 21:10:02 +0200 Subject: [PATCH] NOISSUE BONK --- CMakeLists.txt | 156 ++++++++++----------------- buildconfig/BuildConfig.cpp.in | 14 +-- cmake/MacOSXBundleInfo.plist.in | 10 +- launcher/CMakeLists.txt | 91 ---------------- launcher/install_prereqs.cmake.in | 27 ----- launcher/minecraft/GradleSpecifier.h | 7 +- libraries/katabasis/CMakeLists.txt | 13 --- 7 files changed, 69 insertions(+), 249 deletions(-) delete mode 100644 launcher/install_prereqs.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 720bda40..9c0f13b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,38 +1,51 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.21) -if(WIN32) - # In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows - cmake_policy(SET CMP0020 OLD) +## Main build script. It all begins here. + +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +## +# NOTE: we need to set these first +# Normally, these would be passed in on command line during the configuration step, but it's too annoying to rememeber to do that. +# +# See: https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_ARCHITECTURES.html +# See: https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_DEPLOYMENT_TARGET.html +if(APPLE) + # No M1 build with Qt 5 + set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "macOS architecture(s) to build for.") + # Target 10.14 for the improved theming support + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "minimum macOS versions to build for.") endif() -project(Launcher) +set(CMAKE_CXX_STANDARD_REQUIRED true) +set(CMAKE_C_STANDARD_REQUIRED true) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD 11) + +# Include some common functionality for building Qt apps (from `cmake` folder) +include(QtCommon) + +set(BUILD_NUMBER 0 CACHE STRING "Build number from the CI, if any. 0 means custom/local build.") + +project(Launcher VERSION 6.0.0.${BUILD_NUMBER}) +fix_project_version() + enable_testing() -string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BUILD_DIR}" IS_IN_SOURCE_BUILD) -if(IS_IN_SOURCE_BUILD) - message(FATAL_ERROR "You are building the Launcher in-source. Please separate the build tree from the source tree.") -endif() +include(GetGitRevisionDescription) +get_git_head_revision(GIT_REFSPEC GIT_COMMIT) +message(STATUS "Git commit: ${GIT_COMMIT}") +message(STATUS "Git refspec: ${GIT_REFSPEC}") -option(Launcher_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF) -if(Launcher_RUN_CLANG_TIDY) - find_program(CLANG_TIDY_COMMAND NAMES clang-tidy) - if(NOT CLANG_TIDY_COMMAND) - message(WARNING "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!") - set(DO_CLANG_TIDY "" CACHE STRING "" FORCE) - else() - set(CLANG_TIDY_CHECKS "-modernize-use-trailing-return-type,-readability-magic-numbers,-modernize-avoid-c-arrays") - set(DO_CLANG_TIDY "${CLANG_TIDY_COMMAND};-checks=${CLANG_TIDY_CHECKS};-header-filter='${CMAKE_SOURCE_DIR}/src/*'") - endif() - # TODO: make this per-target, differentiate between libraries and main codebase - set(CMAKE_CXX_CLANG_TIDY ${DO_CLANG_TIDY}) -endif() - - -##################################### Set CMake options ##################################### -set(CMAKE_AUTOMOC ON) +# Yes, current directory is on the search path of .cpp files set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") +# Automatically handle Qt code generation +set(CMAKE_AUTOMOC ON) + +# This means the application does not show up on the dock and does not have a global menu (see cmake/QtCommon.cmake) +set(MACOSX_IS_UIELEMENT 0) + # Output all executables and shared libs in the main build folder, not in subfolders. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) @@ -42,10 +55,6 @@ endif() set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${PROJECT_BINARY_DIR}/jars) ######## Set compiler flags ######## -set(CMAKE_CXX_STANDARD_REQUIRED true) -set(CMAKE_C_STANDARD_REQUIRED true) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_C_STANDARD 11) include(GenerateExportHeader) set(CMAKE_CXX_FLAGS " -Wall -pedantic -Werror -Wno-deprecated-declarations -Wno-gnu-zero-variadic-macro-arguments -fstack-protector-strong --param=ssp-buffer-size=4 ${CMAKE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE " -O3 -D_FORTIFY_SOURCE=2 ${CMAKE_CXX_FLAGS_RELEASE}") @@ -100,17 +109,7 @@ set(Launcher_SUBREDDIT_URL "" CACHE STRING "URL for the subreddit.") # Use the secrets library or a public stub? option(Launcher_EMBED_SECRETS "Determines whether to embed secrets. Secrets are separate and non-public." OFF) -#### Check the current Git commit and branch -include(GetGitRevisionDescription) -get_git_head_revision(Launcher_GIT_REFSPEC Launcher_GIT_COMMIT) - -message(STATUS "Git commit: ${Launcher_GIT_COMMIT}") -message(STATUS "Git refspec: ${Launcher_GIT_REFSPEC}") - -set(Launcher_RELEASE_VERSION_NAME "${Launcher_VERSION_MAJOR}.${Launcher_VERSION_MINOR}.${Launcher_VERSION_HOTFIX}") - -#### Custom target to just print the version. -add_custom_target(version echo "Version: ${Launcher_RELEASE_VERSION_NAME}") +#### Custom target to feed the version to github actions. add_custom_target(ga_version echo ::set-output name=version::${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}) ################################ 3rd Party Libs ################################ @@ -122,71 +121,36 @@ find_package(Qt6 REQUIRED COMPONENTS Core Widgets Concurrent Network Test Xml) if(Launcher_EMBED_SECRETS) add_subdirectory(secrets) + set(RESOURCE_FOLDER "secrets") else() add_subdirectory(notsecrets) + set(RESOURCE_FOLDER "notsecrets") endif() ####################################### Install layout ####################################### +set(COMPANY "${Launcher_Copyright}") +set(COPYRIGHT "Copyright 2015-2023 ${Launcher_Copyright}") +set(IDENTIFIER "org.multimc.${Launcher_Name}") +set(DESCRIPTION "${Launcher_Name}: Minecraft launcher and management utility.") + # How to install the build results -set(Launcher_LAYOUT "auto" CACHE STRING "The layout for the launcher installation (auto, win-bundle, lin-nodeps, mac-bundle)") -set_property(CACHE Launcher_LAYOUT PROPERTY STRINGS auto win-bundle lin-nodeps mac-bundle) - -if(Launcher_LAYOUT STREQUAL "auto") - if(UNIX AND APPLE) - set(Launcher_LAYOUT_REAL "mac-bundle") - elseif(UNIX) - set(Launcher_LAYOUT_REAL "lin-nodeps") - elseif(WIN32) - set(Launcher_LAYOUT_REAL "win-bundle") - else() - message(FATAL_ERROR "Cannot choose a sensible install layout for your platform.") - endif() -else() - set(Launcher_LAYOUT_REAL ${Launcher_LAYOUT}) -endif() - -if(Launcher_LAYOUT_REAL STREQUAL "mac-bundle") +if(UNIX AND APPLE) set(BINARY_DEST_DIR "${Launcher_Name}.app/Contents/MacOS") set(LIBRARY_DEST_DIR "${Launcher_Name}.app/Contents/MacOS") - set(PLUGIN_DEST_DIR "${Launcher_Name}.app/Contents/MacOS") - set(RESOURCES_DEST_DIR "${Launcher_Name}.app/Contents/Resources") set(JARS_DEST_DIR "${Launcher_Name}.app/Contents/MacOS/jars") set(BUNDLE_DEST_DIR ".") - # Apps to bundle - set(APPS "\${CMAKE_INSTALL_PREFIX}/${Launcher_Name}.app") - - # Mac bundle settings - set(MACOSX_BUNDLE_BUNDLE_NAME "${Launcher_Name}") - set(MACOSX_BUNDLE_INFO_STRING "${Launcher_Name}: Minecraft launcher and management utility.") - set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.multimc.${Launcher_Name}") - set(MACOSX_BUNDLE_BUNDLE_VERSION "${Launcher_VERSION_MAJOR}.${Launcher_VERSION_MINOR}.${Launcher_VERSION_HOTFIX}.${Launcher_VERSION_BUILD}") - set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${Launcher_VERSION_MAJOR}.${Launcher_VERSION_MINOR}.${Launcher_VERSION_HOTFIX}.${Launcher_VERSION_BUILD}") - set(MACOSX_BUNDLE_LONG_VERSION_STRING "${Launcher_VERSION_MAJOR}.${Launcher_VERSION_MINOR}.${Launcher_VERSION_HOTFIX}.${Launcher_VERSION_BUILD}") - set(MACOSX_BUNDLE_ICON_FILE ${Launcher_Name}.icns) - set(MACOSX_BUNDLE_COPYRIGHT "Copyright 2015-2023 ${Launcher_Copyright}") - - # directories to look for dependencies - set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) - - # install as bundle - set(INSTALL_BUNDLE "full") - # Add the icon - install(FILES ${Launcher_Branding_ICNS} DESTINATION ${RESOURCES_DEST_DIR} RENAME ${Launcher_Name}.icns) + install(FILES ${Launcher_Branding_ICNS} DESTINATION "${Launcher_Name}.app/Contents/Resources" RENAME ${Launcher_Name}.icns) -elseif(Launcher_LAYOUT_REAL STREQUAL "lin-nodeps") +elseif(UNIX) set(BINARY_DEST_DIR "bin") set(LIBRARY_DEST_DIR "bin") - set(PLUGIN_DEST_DIR "plugins") - set(BUNDLE_DEST_DIR ".") - set(RESOURCES_DEST_DIR ".") set(JARS_DEST_DIR "bin/jars") - # install as bundle with no dependencies included - set(INSTALL_BUNDLE "nodeps") + set(BUNDLE_DEST_DIR ".") # Set RPATH SET(Launcher_BINARY_RPATH "$ORIGIN/") @@ -195,24 +159,14 @@ elseif(Launcher_LAYOUT_REAL STREQUAL "lin-nodeps") configure_file(launcher/Launcher.in "${CMAKE_CURRENT_BINARY_DIR}/LauncherScript" @ONLY) install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/LauncherScript" DESTINATION ${BUNDLE_DEST_DIR} RENAME ${Launcher_Name}) -elseif(Launcher_LAYOUT_REAL STREQUAL "win-bundle") +elseif(WIN32) set(BINARY_DEST_DIR ".") set(LIBRARY_DEST_DIR ".") - set(PLUGIN_DEST_DIR ".") - set(BUNDLE_DEST_DIR ".") - set(RESOURCES_DEST_DIR ".") set(JARS_DEST_DIR "jars") - # Apps to bundle - set(APPS "\${CMAKE_INSTALL_PREFIX}/${Launcher_Name}.exe") - - # directories to look for dependencies - set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) - - # install as bundle - set(INSTALL_BUNDLE "full") + set(BUNDLE_DEST_DIR ".") else() - message(FATAL_ERROR "No sensible install layout set.") + message(FATAL_ERROR "Cannot choose a sensible install layout for your platform.") endif() ################################ Included Libs ################################ diff --git a/buildconfig/BuildConfig.cpp.in b/buildconfig/BuildConfig.cpp.in index 8c04dd4d..818d91ca 100644 --- a/buildconfig/BuildConfig.cpp.in +++ b/buildconfig/BuildConfig.cpp.in @@ -17,19 +17,19 @@ Config::Config() USER_AGENT_UNCACHED = USER_AGENT + " (Uncached)"; // Version information - VERSION_MAJOR = @Launcher_VERSION_MAJOR@; - VERSION_MINOR = @Launcher_VERSION_MINOR@; - VERSION_HOTFIX = @Launcher_VERSION_HOTFIX@; - VERSION_BUILD = @Launcher_VERSION_BUILD@; + VERSION_MAJOR = @PROJECT_VERSION_MAJOR@; + VERSION_MINOR = @PROJECT_VERSION_MINOR@; + VERSION_HOTFIX = @PROJECT_VERSION_PATCH@; + VERSION_BUILD = @PROJECT_VERSION_TWEAK@; BUILD_PLATFORM = "@Launcher_BUILD_PLATFORM@"; UPDATER_BASE = "@Launcher_UPDATER_BASE@"; ANALYTICS_ID = "@Launcher_ANALYTICS_ID@"; NOTIFICATION_URL = "@Launcher_NOTIFICATION_URL@"; - FULL_VERSION_STR = "@Launcher_VERSION_MAJOR@.@Launcher_VERSION_MINOR@.@Launcher_VERSION_BUILD@"; + FULL_VERSION_STR = "@PROJECT_VERSION@"; - GIT_COMMIT = "@Launcher_GIT_COMMIT@"; - GIT_REFSPEC = "@Launcher_GIT_REFSPEC@"; + GIT_COMMIT = "@GIT_COMMIT@"; + GIT_REFSPEC = "@GIT_REFSPEC@"; if(GIT_REFSPEC.startsWith("refs/heads/") && !UPDATER_BASE.isEmpty() && !BUILD_PLATFORM.isEmpty() && VERSION_BUILD >= 0) { VERSION_CHANNEL = GIT_REFSPEC; diff --git a/cmake/MacOSXBundleInfo.plist.in b/cmake/MacOSXBundleInfo.plist.in index 3302244f..3072cfc8 100644 --- a/cmake/MacOSXBundleInfo.plist.in +++ b/cmake/MacOSXBundleInfo.plist.in @@ -2,10 +2,6 @@ - NSPrincipalClass - NSApplication - NSHighResolutionCapable - True CFBundleDevelopmentRegion English CFBundleExecutable @@ -36,7 +32,9 @@ NSHumanReadableCopyright ${MACOSX_BUNDLE_COPYRIGHT} - NSMicrophoneUsageDescription - MultiMC does not need access to your microphone for itself. Likely it's requesting it on behalf of a Minecraft mod you installed, which needs to access your microphone in order to function properly. + NSPrincipalClass + NSApplication + LSUIElement + ${MACOSX_IS_UIELEMENT} diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index b059c287..ad6a3800 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -961,94 +961,3 @@ install(TARGETS ${Launcher_Name} LIBRARY DESTINATION ${LIBRARY_DEST_DIR} COMPONENT Runtime RUNTIME DESTINATION ${BINARY_DEST_DIR} COMPONENT Runtime ) - -#### The bundle mess! #### -# Bundle utilities are used to complete the portable packages - they add all the libraries that would otherwise be missing on the target system. -# NOTE: it seems that this absolutely has to be here, and nowhere else. -if(INSTALL_BUNDLE STREQUAL "full") - # Add qt.conf - this makes Qt stop looking for things outside the bundle - install( - CODE "file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${RESOURCES_DEST_DIR}/qt.conf\" \" \")" - COMPONENT Runtime - ) - # Bundle plugins - if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - # Image formats - install( - DIRECTORY "${QT_PLUGINS_DIR}/imageformats" - DESTINATION ${PLUGIN_DEST_DIR} - COMPONENT Runtime - REGEX "tga|tiff|mng|webp" EXCLUDE - ) - # Icon engines - install( - DIRECTORY "${QT_PLUGINS_DIR}/iconengines" - DESTINATION ${PLUGIN_DEST_DIR} - COMPONENT Runtime - REGEX "fontawesome" EXCLUDE - ) - # Platform plugins - install( - DIRECTORY "${QT_PLUGINS_DIR}/platforms" - DESTINATION ${PLUGIN_DEST_DIR} - COMPONENT Runtime - REGEX "minimal|linuxfb|offscreen" EXCLUDE - ) - # Style plugins - if(EXISTS "${QT_PLUGINS_DIR}/styles") - install( - DIRECTORY "${QT_PLUGINS_DIR}/styles" - DESTINATION ${PLUGIN_DEST_DIR} - COMPONENT Runtime - ) - endif() - else() - # Image formats - install( - DIRECTORY "${QT_PLUGINS_DIR}/imageformats" - DESTINATION ${PLUGIN_DEST_DIR} - COMPONENT Runtime - REGEX "tga|tiff|mng|webp" EXCLUDE - REGEX "d\\." EXCLUDE - REGEX "_debug\\." EXCLUDE - REGEX "\\.dSYM" EXCLUDE - ) - # Icon engines - install( - DIRECTORY "${QT_PLUGINS_DIR}/iconengines" - DESTINATION ${PLUGIN_DEST_DIR} - COMPONENT Runtime - REGEX "fontawesome" EXCLUDE - REGEX "d\\." EXCLUDE - REGEX "_debug\\." EXCLUDE - REGEX "\\.dSYM" EXCLUDE - ) - # Platform plugins - install( - DIRECTORY "${QT_PLUGINS_DIR}/platforms" - DESTINATION ${PLUGIN_DEST_DIR} - COMPONENT Runtime - REGEX "minimal|linuxfb|offscreen" EXCLUDE - REGEX "d\\." EXCLUDE - REGEX "_debug\\." EXCLUDE - REGEX "\\.dSYM" EXCLUDE - ) - # Style plugins - if(EXISTS "${QT_PLUGINS_DIR}/styles") - install( - DIRECTORY "${QT_PLUGINS_DIR}/styles" - DESTINATION ${PLUGIN_DEST_DIR} - COMPONENT Runtime - REGEX "d\\." EXCLUDE - REGEX "_debug\\." EXCLUDE - REGEX "\\.dSYM" EXCLUDE - ) - endif() - endif() - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/install_prereqs.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/install_prereqs.cmake" - @ONLY - ) - install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/install_prereqs.cmake" COMPONENT Runtime) -endif() diff --git a/launcher/install_prereqs.cmake.in b/launcher/install_prereqs.cmake.in deleted file mode 100644 index e4408d16..00000000 --- a/launcher/install_prereqs.cmake.in +++ /dev/null @@ -1,27 +0,0 @@ -set(CMAKE_MODULE_PATH "@CMAKE_MODULE_PATH@") - -file(GLOB_RECURSE QTPLUGINS "${CMAKE_INSTALL_PREFIX}/@PLUGIN_DEST_DIR@/*@CMAKE_SHARED_LIBRARY_SUFFIX@") -function(gp_resolved_file_type_override resolved_file type_var) - if(resolved_file MATCHES "^/(usr/)?lib/libQt") - set(${type_var} other PARENT_SCOPE) - elseif(resolved_file MATCHES "^/(usr/)?lib(.+)?/libxcb-") - set(${type_var} other PARENT_SCOPE) - elseif(resolved_file MATCHES "^/(usr/)?lib(.+)?/libicu") - set(${type_var} other PARENT_SCOPE) - elseif(resolved_file MATCHES "^/(usr/)?lib(.+)?/libpng") - set(${type_var} other PARENT_SCOPE) - elseif(resolved_file MATCHES "^/(usr/)?lib(.+)?/libproxy") - set(${type_var} other PARENT_SCOPE) - elseif((resolved_file MATCHES "^/(usr/)?lib(.+)?/libstdc\\+\\+") AND (UNIX AND NOT APPLE)) - set(${type_var} other PARENT_SCOPE) - endif() -endfunction() - -set(gp_tool "@CMAKE_GP_TOOL@") -set(gp_cmd_paths ${gp_cmd_paths} - "@CMAKE_GP_CMD_PATHS@" -) - -include(BundleUtilities) -fixup_bundle("@APPS@" "${QTPLUGINS}" "@DIRS@") - diff --git a/launcher/minecraft/GradleSpecifier.h b/launcher/minecraft/GradleSpecifier.h index 65f98a77..a5caab90 100644 --- a/launcher/minecraft/GradleSpecifier.h +++ b/launcher/minecraft/GradleSpecifier.h @@ -37,11 +37,10 @@ struct GradleSpecifier m_groupId = elements[1]; m_artifactId = elements[2]; m_version = elements[3]; - m_classifier = elements[4]; - if(!elements[5].isEmpty()) - { + if(elements.size() >= 5) + m_classifier = elements[4]; + if(elements.size() >= 6) m_extension = elements[5]; - } return *this; } QString serialize() const diff --git a/libraries/katabasis/CMakeLists.txt b/libraries/katabasis/CMakeLists.txt index b5e93c0d..cc7bece4 100644 --- a/libraries/katabasis/CMakeLists.txt +++ b/libraries/katabasis/CMakeLists.txt @@ -1,18 +1,5 @@ cmake_minimum_required(VERSION 3.6) -string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BUILD_DIR}" IS_IN_SOURCE_BUILD) -if(IS_IN_SOURCE_BUILD) - message(FATAL_ERROR "You are building Katabasis in-source. Please separate the build tree from the source tree.") -endif() - -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - if(CMAKE_HOST_SYSTEM_VERSION MATCHES ".*[Mm]icrosoft.*" OR - CMAKE_HOST_SYSTEM_VERSION MATCHES ".*WSL.*" - ) - message(FATAL_ERROR "Building Katabasis is not supported in Linux-on-Windows distributions. Use a real Linux machine, not a fraudulent one.") - endif() -endif() - project(Katabasis) enable_testing()