Skip to content

Commit

Permalink
NOISSUE BONK
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed May 16, 2023
1 parent cd2e238 commit 727fbfd
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 249 deletions.
156 changes: 55 additions & 101 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
cmake_minimum_required(VERSION 3.1)

if(WIN32)
# In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows
cmake_policy(SET CMP0020 OLD)
cmake_minimum_required(VERSION 3.21)

## 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)
enable_testing()
set(CMAKE_CXX_STANDARD_REQUIRED true)
set(CMAKE_C_STANDARD_REQUIRED true)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

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 some common functionality for building Qt apps (from `cmake` folder)
include(QtCommon)

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(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()

##################################### Set CMake options #####################################
set(CMAKE_AUTOMOC ON)
enable_testing()

include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_COMMIT)
message(STATUS "Git commit: ${GIT_COMMIT}")
message(STATUS "Git refspec: ${GIT_REFSPEC}")

# 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})
Expand All @@ -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}")
Expand Down Expand Up @@ -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 ################################
Expand All @@ -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 #######################################

# 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()
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.")

if(Launcher_LAYOUT_REAL STREQUAL "mac-bundle")
# How to install the build results
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/")
Expand All @@ -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 ################################
Expand Down
14 changes: 7 additions & 7 deletions buildconfig/BuildConfig.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions cmake/MacOSXBundleInfo.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
Expand Down Expand Up @@ -36,7 +32,9 @@
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>NSMicrophoneUsageDescription</key>
<string>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.</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSUIElement</key>
<string>${MACOSX_IS_UIELEMENT}</string>
</dict>
</plist>
91 changes: 0 additions & 91 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
27 changes: 0 additions & 27 deletions launcher/install_prereqs.cmake.in

This file was deleted.

0 comments on commit 727fbfd

Please sign in to comment.