From f16de402cf976c8a2f364bcd36126588c1232204 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Tue, 26 Dec 2023 04:26:38 +0100 Subject: Screen.cpp: include missing headers --- src/frontend/qt_sdl/Screen.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/frontend/qt_sdl/Screen.cpp b/src/frontend/qt_sdl/Screen.cpp index 6de4d78..61b6891 100644 --- a/src/frontend/qt_sdl/Screen.cpp +++ b/src/frontend/qt_sdl/Screen.cpp @@ -25,9 +25,11 @@ #include #include #include +#include #include #include +#include #ifndef _WIN32 #ifndef APPLE #include -- cgit v1.2.3 From 4d3af0d91529e7230398d02e7a9e8491b5d8a74d Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Tue, 26 Dec 2023 05:12:26 +0100 Subject: Make that FindWayland warning shut up Hopefully "stable" distros use a not-ancient-enough CMake version that this should be okay. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 337c4a1..2f80767 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.16) cmake_policy(VERSION 3.15) if (POLICY CMP0076) -- cgit v1.2.3 From 27ac8dbc146cd4e3c8fa34c78918297a73065a56 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Tue, 26 Dec 2023 06:51:49 +0100 Subject: Integrate support for building with dependencies from vcpkg (#1880) * Integrate support for building with dependencies from vcpkg Configure the build using -DUSE_VCPKG=ON to use vcpkg. By default recommended triplets targeting the OS versions official builds support are used. You can opt out of this with -DUSE_RECOMMENDED_TRIPLETS=OFF. * Add the vcpkg manifest * Fetch vcpkg with FetchContent if we don't have it * macOS cross compiling fixes - can't use the x86_64 one as host triplet on arm64 because building Qt fails for whatever reason. Because of course it does :D - vcpkg doesn't always like periods in triplet names so removed those * x86_64 macOS should also use its recommended target when building arm64 builds --- CMakeLists.txt | 5 ++ cmake/ConfigureVcpkg.cmake | 90 +++++++++++++++++++++++ cmake/overlay-triplets/arm64-osx-11-release.cmake | 12 +++ cmake/overlay-triplets/x64-osx-1015-release.cmake | 12 +++ vcpkg.json | 18 +++++ 5 files changed, 137 insertions(+) create mode 100644 cmake/ConfigureVcpkg.cmake create mode 100644 cmake/overlay-triplets/arm64-osx-11-release.cmake create mode 100644 cmake/overlay-triplets/x64-osx-1015-release.cmake create mode 100644 vcpkg.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f80767..97dfc5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,11 @@ set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +option(USE_VCPKG "Use vcpkg for dependency packages" OFF) +if (USE_VCPKG) + include(ConfigureVcpkg) +endif() + project(melonDS VERSION 0.9.5 DESCRIPTION "DS emulator, sorta" diff --git a/cmake/ConfigureVcpkg.cmake b/cmake/ConfigureVcpkg.cmake new file mode 100644 index 0000000..f7f7f62 --- /dev/null +++ b/cmake/ConfigureVcpkg.cmake @@ -0,0 +1,90 @@ +include(FetchContent) + +set(_DEFAULT_VCPKG_ROOT "${CMAKE_SOURCE_DIR}/vcpkg") +set(VCPKG_ROOT "${_DEFAULT_VCPKG_ROOT}" CACHE STRING "The path to the vcpkg repository") + +if (VCPKG_ROOT STREQUAL "${_DEFAULT_VCPKG_ROOT}") + FetchContent_Declare(vcpkg + GIT_REPOSITORY "https://github.com/Microsoft/vcpkg.git" + GIT_TAG 2023.10.19 + SOURCE_DIR "${CMAKE_SOURCE_DIR}/vcpkg") + FetchContent_MakeAvailable(vcpkg) +endif() + +set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_SOURCE_DIR}/cmake/overlay-triplets") + +option(USE_RECOMMENDED_TRIPLETS "Use the recommended triplets that are used for official builds" ON) + +if (CMAKE_OSX_ARCHITECTURES MATCHES ";") + message(FATAL_ERROR "macOS universal builds are not supported. Build them individually and combine afterwards instead.") +endif() + +if (USE_RECOMMENDED_TRIPLETS) + execute_process( + COMMAND uname -m + OUTPUT_VARIABLE _HOST_PROCESSOR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + set(_CAN_TARGET_AS_HOST OFF) + + if (APPLE) + if (NOT CMAKE_OSX_ARCHITECTURES) + if (_HOST_PROCESSOR STREQUAL arm64) + set(CMAKE_OSX_ARCHITECTURES arm64) + else() + set(CMAKE_OSX_ARCHITECTURES x86_64) + endif() + endif() + + if (CMAKE_OSX_ARCHITECTURES STREQUAL arm64) + set(_WANTED_TRIPLET arm64-osx-11-release) + set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0) + else() + set(_WANTED_TRIPLET x64-osx-1015-release) + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15) + endif() + elseif(WIN32) + # TODO Windows arm64 if possible + set(_CAN_TARGET_AS_HOST ON) + set(_WANTED_TRIPLET x64-mingw-static) + endif() + + # Don't override it if the user set something else + if (NOT VCPKG_TARGET_TRIPLET) + set(VCPKG_TARGET_TRIPLET "${_WANTED_TRIPLET}") + else() + set(_WANTED_TRIPLET "${VCPKG_TARGET_TRIPLET}") + endif() + + if (APPLE) + if (_HOST_PROCESSOR MATCHES arm64) + if (_WANTED_TRIPLET MATCHES "^arm64-osx-") + set(_CAN_TARGET_AS_HOST ON) + elseif (_WANTED_TRIPLET STREQUAL "x64-osx-1015-release") + # Use the default triplet for when building for arm64 + # because we're probably making a universal build + set(VCPKG_HOST_TRIPLET arm64-osx-11-release) + endif() + else() + if (_WANTED_TRIPLET MATCHES "^x64-osx-") + set(_CAN_TARGET_AS_HOST ON) + elseif (_WANTED_TRIPLET STREQUAL "arm64-osx-11-release") + set(VCPKG_HOST_TRIPLET x64-osx-1015-release) + endif() + endif() + endif() + + # If host and target triplet differ, vcpkg seems to always assume that the host can't run the target's binaries. + # In cases like cross compiling from ARM -> Intel macOS, or target being an older version of the host OS, we *can* do that so the packages built targeting the host are redundant. + if (_CAN_TARGET_AS_HOST AND NOT VCPKG_HOST_TRIPLET) + option(VCPKG_TARGET_AS_HOST "Use the target as host triplet to speed up builds" ON) + else() + option(VCPKG_TARGET_AS_HOST "Use the target as host triplet to speed up builds" OFF) + endif() + + if (VCPKG_TARGET_AS_HOST) + set(VCPKG_HOST_TRIPLET "${VCPKG_TARGET_TRIPLET}" CACHE STRING "Host triplet to use for vcpkg") + endif() +endif() + +set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") diff --git a/cmake/overlay-triplets/arm64-osx-11-release.cmake b/cmake/overlay-triplets/arm64-osx-11-release.cmake new file mode 100644 index 0000000..7c4b43a --- /dev/null +++ b/cmake/overlay-triplets/arm64-osx-11-release.cmake @@ -0,0 +1,12 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +set(VCPKG_CMAKE_SYSTEM_VERSION 11.0) +set(VCPKG_OSX_ARCHITECTURES arm64) +set(VCPKG_BUILD_TYPE release) +set(VCPKG_OSX_DEPLOYMENT_TARGET 11.0) + +set(VCPKG_C_FLAGS -mmacosx-version-min=11.0) +set(VCPKG_CXX_FLAGS -mmacosx-version-min=11.0) diff --git a/cmake/overlay-triplets/x64-osx-1015-release.cmake b/cmake/overlay-triplets/x64-osx-1015-release.cmake new file mode 100644 index 0000000..fcb67a7 --- /dev/null +++ b/cmake/overlay-triplets/x64-osx-1015-release.cmake @@ -0,0 +1,12 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +set(VCPKG_CMAKE_SYSTEM_VERSION 10.15) +set(VCPKG_OSX_ARCHITECTURES x86_64) +set(VCPKG_BUILD_TYPE release) +set(VCPKG_OSX_DEPLOYMENT_TARGET 10.15) + +set(VCPKG_C_FLAGS -mmacosx-version-min=10.15) +set(VCPKG_CXX_FLAGS -mmacosx-version-min=10.15) diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..2ff0c54 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,18 @@ +{ + "dependencies": [ + "sdl2", + "libarchive", + "libslirp", + "zstd", + { + "name": "qtbase", + "default-features": false, + "features": ["gui", "png", "thread", "widgets", "opengl", "zstd"] + }, + { + "name": "qtmultimedia", + "default-features": false + }, + "qtsvg" + ] +} -- cgit v1.2.3 From 65780e6ba2bd1eb567290db33cf3de1d4fec9c3f Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Tue, 26 Dec 2023 08:14:20 +0100 Subject: Update vcpkg --- cmake/ConfigureVcpkg.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/ConfigureVcpkg.cmake b/cmake/ConfigureVcpkg.cmake index f7f7f62..95cbcdb 100644 --- a/cmake/ConfigureVcpkg.cmake +++ b/cmake/ConfigureVcpkg.cmake @@ -6,7 +6,7 @@ set(VCPKG_ROOT "${_DEFAULT_VCPKG_ROOT}" CACHE STRING "The path to the vcpkg repo if (VCPKG_ROOT STREQUAL "${_DEFAULT_VCPKG_ROOT}") FetchContent_Declare(vcpkg GIT_REPOSITORY "https://github.com/Microsoft/vcpkg.git" - GIT_TAG 2023.10.19 + GIT_TAG 2023.12.12 SOURCE_DIR "${CMAKE_SOURCE_DIR}/vcpkg") FetchContent_MakeAvailable(vcpkg) endif() -- cgit v1.2.3 From ac3153d86bc66e5839e45b3a1fbc91f7e8b64a91 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Tue, 26 Dec 2023 08:14:30 +0100 Subject: "Incorrectly" link libslirp to stop its broken build system fucking up our linker flags --- src/frontend/qt_sdl/CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 9da2c91..c2fa5b5 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -84,11 +84,11 @@ if (BUILD_STATIC) endif() pkg_check_modules(SDL2 REQUIRED IMPORTED_TARGET sdl2) -pkg_check_modules(Slirp REQUIRED IMPORTED_TARGET slirp) +pkg_check_modules(Slirp REQUIRED slirp) pkg_check_modules(LibArchive REQUIRED IMPORTED_TARGET libarchive) pkg_check_modules(Zstd REQUIRED IMPORTED_TARGET libzstd) -fix_interface_includes(PkgConfig::SDL2 PkgConfig::Slirp PkgConfig::LibArchive) +fix_interface_includes(PkgConfig::SDL2 PkgConfig::LibArchive) add_compile_definitions(ARCHIVE_SUPPORT_ENABLED) @@ -160,9 +160,12 @@ else() target_include_directories(melonDS PUBLIC ${Qt5Gui_PRIVATE_INCLUDE_DIRS}) endif() target_link_libraries(melonDS PRIVATE core) -target_link_libraries(melonDS PRIVATE PkgConfig::SDL2 PkgConfig::Slirp PkgConfig::LibArchive PkgConfig::Zstd) +target_link_libraries(melonDS PRIVATE PkgConfig::SDL2 PkgConfig::LibArchive PkgConfig::Zstd) target_link_libraries(melonDS PRIVATE ${QT_LINK_LIBS} ${CMAKE_DL_LIBS}) +target_include_directories(melonDS PRIVATE "${Slirp_INCLUDE_DIRS}") +target_link_libraries(melonDS PRIVATE "${Slirp_LINK_LIBRARIES}") + if (UNIX) option(PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) elseif (WIN32) -- cgit v1.2.3 From 740489f7a4a848bd3f96f1c911a6c7db5f6cc27f Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Tue, 26 Dec 2023 08:49:02 +0100 Subject: Don't call Reset on nullptr --- src/frontend/qt_sdl/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 3f53f3c..7ba37c1 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -329,10 +329,14 @@ bool EmuThread::UpdateConsole(UpdateConsoleNDSArgs&& ndsargs, UpdateConsoleGBAAr NDS::Current = nullptr; NDS = CreateConsole(std::move(nextndscart), std::move(nextgbacart)); + + if (NDS == nullptr) + return false; + NDS->Reset(); NDS::Current = NDS.get(); - return NDS != nullptr; + return true; } auto arm9bios = ROMManager::LoadARM9BIOS(); -- cgit v1.2.3 From d55a384c8807cd0962399dac69e8ee1a9d5c53fd Mon Sep 17 00:00:00 2001 From: Jesse Talavera Date: Tue, 26 Dec 2023 10:34:04 -0500 Subject: Apply some quick hotfixes (#1931) --- src/DSi_NAND.cpp | 4 +++- src/FATStorage.cpp | 10 ++-------- src/FATStorage.h | 4 ++-- src/NDSCart.cpp | 10 ++++++++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/DSi_NAND.cpp b/src/DSi_NAND.cpp index 5f76714..8da0254 100644 --- a/src/DSi_NAND.cpp +++ b/src/DSi_NAND.cpp @@ -122,7 +122,8 @@ NANDImage::NANDImage(NANDImage&& other) noexcept : ConsoleID(other.ConsoleID), FATIV(other.FATIV), FATKey(other.FATKey), - ESKey(other.ESKey) + ESKey(other.ESKey), + Length(other.Length) { other.CurFile = nullptr; } @@ -140,6 +141,7 @@ NANDImage& NANDImage::operator=(NANDImage&& other) noexcept FATIV = other.FATIV; FATKey = other.FATKey; ESKey = other.ESKey; + Length = other.Length; other.CurFile = nullptr; } diff --git a/src/FATStorage.cpp b/src/FATStorage.cpp index 52011a8..9a1a9ad 100644 --- a/src/FATStorage.cpp +++ b/src/FATStorage.cpp @@ -32,14 +32,8 @@ using namespace Platform; using std::string; FATStorage::FATStorage(const std::string& filename, u64 size, bool readonly, const std::optional& sourcedir) : - FilePath(filename), - FileSize(size), - ReadOnly(readonly), - SourceDir(sourcedir) + FATStorage(FATStorageArgs { filename, size, readonly, sourcedir }) { - Load(filename, size, sourcedir); - - File = Platform::OpenLocalFile(FilePath, FileMode::ReadWriteExisting); } FATStorage::FATStorage(const FATStorageArgs& args) noexcept : @@ -55,7 +49,7 @@ FATStorage::FATStorage(FATStorageArgs&& args) noexcept : { Load(FilePath, FileSize, SourceDir); - File = nullptr; + File = Platform::OpenLocalFile(FilePath, FileMode::ReadWriteExisting); } FATStorage::FATStorage(FATStorage&& other) noexcept diff --git a/src/FATStorage.h b/src/FATStorage.h index 1e89b76..48a411b 100644 --- a/src/FATStorage.h +++ b/src/FATStorage.h @@ -48,8 +48,8 @@ class FATStorage { public: FATStorage(const std::string& filename, u64 size, bool readonly, const std::optional& sourcedir = std::nullopt); - FATStorage(const FATStorageArgs& args) noexcept; - FATStorage(FATStorageArgs&& args) noexcept; + explicit FATStorage(const FATStorageArgs& args) noexcept; + explicit FATStorage(FATStorageArgs&& args) noexcept; FATStorage(FATStorage&& other) noexcept; FATStorage(const FATStorage& other) = delete; FATStorage& operator=(const FATStorage& other) = delete; diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index a5fe318..a64d8a2 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -1657,9 +1657,15 @@ std::unique_ptr ParseROM(std::unique_ptr&& romdata, u32 romlen std::unique_ptr sram = args ? std::move(args->SRAM) : nullptr; u32 sramlen = args ? args->SRAMLength : 0; if (homebrew) - cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, args ? std::move(args->SDCard) : std::nullopt); + { + std::optional sdcard = args && args->SDCard ? std::make_optional(std::move(*args->SDCard)) : std::nullopt; + cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, std::move(sdcard)); + } else if (gametitle[0] == 0 && !strncmp("SD/TF-NDS", gametitle + 1, 9) && gamecode == 0x414D5341) - cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, CartR4TypeR4, CartR4LanguageEnglish, args ? std::move(args->SDCard) : std::nullopt); + { + std::optional sdcard = args && args->SDCard ? std::make_optional(std::move(*args->SDCard)) : std::nullopt; + cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, CartR4TypeR4, CartR4LanguageEnglish, std::move(sdcard)); + } else if (cartid & 0x08000000) cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, std::move(sram), sramlen); else if (irversion != 0) -- cgit v1.2.3