aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadia Holmquist Pedersen <nadia@nhp.sh>2023-12-26 06:51:49 +0100
committerGitHub <noreply@github.com>2023-12-26 06:51:49 +0100
commit27ac8dbc146cd4e3c8fa34c78918297a73065a56 (patch)
treeebacf039b070508b231c0b17c9ed86c076e5b48d
parent4d3af0d91529e7230398d02e7a9e8491b5d8a74d (diff)
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
-rw-r--r--CMakeLists.txt5
-rw-r--r--cmake/ConfigureVcpkg.cmake90
-rw-r--r--cmake/overlay-triplets/arm64-osx-11-release.cmake12
-rw-r--r--cmake/overlay-triplets/x64-osx-1015-release.cmake12
-rw-r--r--vcpkg.json18
5 files changed, 137 insertions, 0 deletions
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"
+ ]
+}