Skip to content

Commit

Permalink
setup rust side of hematite lib scafold
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Powers <[email protected]>
  • Loading branch information
Ryex committed Nov 7, 2024
1 parent 1ab10bd commit 95abc73
Show file tree
Hide file tree
Showing 10 changed files with 1,576 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ flatbuild

# Snap
*.snap

# Rust
launcher/hematite/target
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.15) # minimum version required by QuaZip
cmake_minimum_required(VERSION 3.15) # minimum version required by QuaZip & Corrosion

project(Launcher)

Expand Down Expand Up @@ -328,13 +328,17 @@ endif()

if(Launcher_QT_VERSION_MAJOR EQUAL 5)
include(ECMQueryQt)
# ecm_query_qt(QT_BINS_DIR QT_INSTALL_BINS)
ecm_query_qt(QT_PLUGINS_DIR QT_INSTALL_PLUGINS)
ecm_query_qt(QT_LIBS_DIR QT_INSTALL_LIBS)
ecm_query_qt(QT_LIBEXECS_DIR QT_INSTALL_LIBEXECS)
# ecm_query_qt(QT_QML_DIR QT_INSTALL_QML)
else()
# set(QT_BINS_DIR ${QT${QT_VERSION_MAJOR}_INSTALL_PREFIX}/${QT${QT_VERSION_MAJOR}_INSTALL_BINS})
set(QT_PLUGINS_DIR ${QT${QT_VERSION_MAJOR}_INSTALL_PREFIX}/${QT${QT_VERSION_MAJOR}_INSTALL_PLUGINS})
set(QT_LIBS_DIR ${QT${QT_VERSION_MAJOR}_INSTALL_PREFIX}/${QT${QT_VERSION_MAJOR}_INSTALL_LIBS})
set(QT_LIBEXECS_DIR ${QT${QT_VERSION_MAJOR}_INSTALL_PREFIX}/${QT${QT_VERSION_MAJOR}_INSTALL_LIBEXECS})
# set(QT_QML_DIR ${QT${QT_VERSION_MAJOR}_INSTALL_PREFIX}/${QT${QT_VERSION_MAJOR}_INSTALL_QML})
endif()

# NOTE: Qt 6 already sets this by default
Expand Down Expand Up @@ -380,6 +384,7 @@ if(UNIX AND APPLE)
set(PLUGIN_DEST_DIR "${Launcher_Name}.app/Contents/MacOS")
set(FRAMEWORK_DEST_DIR "${Launcher_Name}.app/Contents/Frameworks")
set(RESOURCES_DEST_DIR "${Launcher_Name}.app/Contents/Resources")
# set(QML_DEST_DIR "${RESOURCES_DEST_DIR}/qml")
set(JARS_DEST_DIR "${Launcher_Name}.app/Contents/MacOS/jars")

# Apps to bundle
Expand Down Expand Up @@ -438,7 +443,8 @@ elseif(UNIX)
set(PLUGIN_DEST_DIR "plugins")
set(BUNDLE_DEST_DIR ".")
set(RESOURCES_DEST_DIR ".")

# set(QML_DEST_DIR "qml")

# Apps to bundle
set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/${Launcher_APP_BINARY_NAME}")

Expand All @@ -459,6 +465,7 @@ elseif(WIN32)
set(LIBRARY_DEST_DIR ".")
set(PLUGIN_DEST_DIR ".")
set(RESOURCES_DEST_DIR ".")
# set(QML_DEST_DIR "qml")
set(JARS_DEST_DIR "jars")

# Apps to bundle
Expand Down
51 changes: 44 additions & 7 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ set(CORE_SOURCES
MTPixmapCache.h
)
if (UNIX AND NOT CYGWIN AND NOT APPLE)
set(CORE_SOURCES
set(CORE_SOURCES
${CORE_SOURCES}

# MangoHud
Expand Down Expand Up @@ -1144,7 +1144,7 @@ SET(LAUNCHER_SOURCES
)

if (NOT Apple)
set(LAUNCHER_SOURCES
set(LAUNCHER_SOURCES
${LAUNCHER_SOURCES}

ui/dialogs/UpdateAvailableDialog.h
Expand Down Expand Up @@ -1265,6 +1265,9 @@ include(CompilerWarnings)

# Add executable
add_library(Launcher_logic STATIC ${LOGIC_SOURCES} ${LAUNCHER_SOURCES} ${LAUNCHER_UI} ${LAUNCHER_RESOURCES})
if(BUILD_TESTING)
target_compile_definitions(Launcher_logic PUBLIC LAUNCHER_TEST)
endif()
set_project_warnings(Launcher_logic
"${Launcher_MSVC_WARNINGS}"
"${Launcher_CLANG_WARNINGS}"
Expand Down Expand Up @@ -1310,11 +1313,11 @@ if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path/../Frameworks/")

if(Launcher_ENABLE_UPDATER)
file(DOWNLOAD ${MACOSX_SPARKLE_DOWNLOAD_URL} ${CMAKE_BINARY_DIR}/Sparkle.tar.xz EXPECTED_HASH SHA256=${MACOSX_SPARKLE_SHA256})
file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/Sparkle.tar.xz DESTINATION ${CMAKE_BINARY_DIR}/frameworks/Sparkle)
file(DOWNLOAD ${MACOSX_SPARKLE_DOWNLOAD_URL} ${CMAKE_BINARY_DIR}/Sparkle.tar.xz EXPECTED_HASH SHA256=${MACOSX_SPARKLE_SHA256})
file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/Sparkle.tar.xz DESTINATION ${CMAKE_BINARY_DIR}/frameworks/Sparkle)

find_library(SPARKLE_FRAMEWORK Sparkle "${CMAKE_BINARY_DIR}/frameworks/Sparkle")
add_compile_definitions(SPARKLE_ENABLED)
find_library(SPARKLE_FRAMEWORK Sparkle "${CMAKE_BINARY_DIR}/frameworks/Sparkle")
add_compile_definitions(SPARKLE_ENABLED)
endif()

target_link_libraries(Launcher_logic
Expand All @@ -1324,7 +1327,7 @@ if(APPLE)
"-framework ApplicationServices"
)
if(Launcher_ENABLE_UPDATER)
target_link_libraries(Launcher_logic ${SPARKLE_FRAMEWORK})
target_link_libraries(Launcher_logic ${SPARKLE_FRAMEWORK})
endif()
endif()

Expand All @@ -1345,6 +1348,8 @@ if(DEFINED Launcher_APP_BINARY_DEFS)
target_compile_definitions(Launcher_logic PRIVATE ${Launcher_APP_BINARY_DEFS})
endif()

add_subdirectory(hematite)

install(TARGETS ${Launcher_Name}
BUNDLE DESTINATION "." COMPONENT Runtime
LIBRARY DESTINATION ${LIBRARY_DEST_DIR} COMPONENT Runtime
Expand Down Expand Up @@ -1544,6 +1549,38 @@ if(INSTALL_BUNDLE STREQUAL "full")
PATTERN "*qcertonlybackend*" EXCLUDE
)
endif()
# # QML plugins
# install(
# DIRECTORY "${QT_QML_DIR}/QtQml"
# CONFIGURATIONS Debug RelWithDebInfo ""
# DESTINATION ${QML_DEST_DIR}
# COMPONENT Runtime
# )
# install(
# DIRECTORY "${QT_QML_DIR}/QtQml"
# CONFIGURATIONS Release MinSizeRel
# DESTINATION ${QML_DEST_DIR}
# COMPONENT Runtime
# REGEX "d\\." EXCLUDE
# REGEX "_debug\\." EXCLUDE
# REGEX "\\.dSYM" EXCLUDE
# )
# # QtQuick plugins
# install(
# DIRECTORY "${QT_QML_DIR}/QtQuick"
# CONFIGURATIONS Debug RelWithDebInfo ""
# DESTINATION ${QML_DEST_DIR}
# COMPONENT Runtime
# )
# install(
# DIRECTORY "${QT_QML_DIR}/QtQuick"
# CONFIGURATIONS Release MinSizeRel
# DESTINATION ${QML_DEST_DIR}
# COMPONENT Runtime
# REGEX "d\\." EXCLUDE
# REGEX "_debug\\." EXCLUDE
# REGEX "\\.dSYM" EXCLUDE
# )
# Wayland support
if(EXISTS "${QT_PLUGINS_DIR}/wayland-graphics-integration-client")
install(
Expand Down
2 changes: 2 additions & 0 deletions launcher/hematite/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --"
69 changes: 69 additions & 0 deletions launcher/hematite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

# SPDX-FileCopyrightText: 2022 Rachel Powers <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-only
#
# Prism Launcher - Minecraft Launcher
# Copyright (C) 2022 Rachel Powers <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# Rust always links against non-debug Windows runtime on *-msvc targets
# Note it is best to set this on the command line to ensure all targets are consistent
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
# https://github.com/rust-lang/rust/issues/39016
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()

find_package(CxxQt QUIET)
if(NOT CxxQt_FOUND)
include(FetchContent)
FetchContent_Declare(
CxxQt
GIT_REPOSITORY https://github.com/kdab/cxx-qt-cmake.git
GIT_TAG main
)

FetchContent_MakeAvailable(CxxQt)
endif()

function(LinkCxxQtCrate CRATE_DIR CRATE)
cxx_qt_import_crate(MANIFEST_PATH "${CRATE_DIR}/Cargo.toml" CRATES ${CRATE})


target_link_libraries(${CRATE} INTERFACE Qt::Core)

# if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${CRATE}/qml" AND IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${CRATE}/qml")
#
# file(GLOB build_cxx_qt_qml_files_list "${CMAKE_CURRENT_SOURCE_DIR}/${CRATE}/qml/*")
# list(LENGTH build_cxx_qt_qml_files_list build_cxx_qt_qml_files_list_count)
# if(build_cxx_qt_qml_files_list_count GREATER 0)
#
# target_link_libraries(${CRATE} INTERFACE Qt::Gui Qt::Qml Qt::QuickControls2)
#
# cxx_qt_import_qml_module(${CRATE}_qml
# URI "org.prismlauncher.hematite.${CRATE}"
# SOURCE_CRATE ${CRATE}
# )
#
# target_link_libraries(Launcher_logic PRIVATE ${CRATE}_qml)
# endif()
# endif()

target_link_libraries(Launcher_logic INTERFACE ${CRATE})
endfunction()

# Automated instertion marker for `cargo xtask new`
# BEGIN CRATES_TO_BUILD
# END CRATES_TO BUILD
Loading

0 comments on commit 95abc73

Please sign in to comment.