diff --git a/.gitmodules b/.gitmodules index 668eef80a..e050a9149 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "externals/vcpkg"] path = externals/vcpkg url = https://github.com/microsoft/vcpkg +[submodule "externals/inih/inih"] + path = externals/inih/inih + url = https://github.com/benhoyt/inih diff --git a/CMakeLists.txt b/CMakeLists.txt index 95e0d6aea..c4baaab1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,21 +3,21 @@ cmake_minimum_required(VERSION 3.12) if (${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.15) # Don't override the warning flags in MSVC: cmake_policy(SET CMP0092 NEW) -endif () + # Allow selecting MSVC runtime library using CMAKE_MSVC_RUNTIME_LIBRARY. + cmake_policy(SET CMP0091 NEW) +endif() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules") include(DownloadExternals) include(CMakeDependentOption) -# Include vcpkg toolchain file -set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/externals/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") -include(VcpkgCmakeUtils) - project(citra LANGUAGES C CXX ASM) # Set bundled sdl2/qt as dependent options. # OFF by default, but if ENABLE_SDL2 and MSVC are true then ON option(ENABLE_SDL2 "Enable the SDL2 frontend" ON) + option(ENABLE_QT "Enable the Qt frontend" ON) option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF) CMAKE_DEPENDENT_OPTION(CITRA_USE_BUNDLED_QT "Download bundled Qt binaries" ON "ENABLE_QT;MSVC" OFF) @@ -26,8 +26,6 @@ option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON) option(ENABLE_CUBEB "Enables the cubeb audio backend" ON) -option(ENABLE_VULKAN "Enables the use of the Vulkan API" ON) - option(ENABLE_FFMPEG_AUDIO_DECODER "Enable FFmpeg audio (AAC) decoder" OFF) option(ENABLE_FFMPEG_VIDEO_DUMPER "Enable FFmpeg video dumper" OFF) @@ -35,8 +33,6 @@ if (ENABLE_FFMPEG_AUDIO_DECODER OR ENABLE_FFMPEG_VIDEO_DUMPER) set(ENABLE_FFMPEG ON) endif() -CMAKE_DEPENDENT_OPTION(CITRA_USE_BUNDLED_FFMPEG "Download bundled FFmpeg binaries" ON "ENABLE_FFMPEG;MSVC" OFF) - option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF) CMAKE_DEPENDENT_OPTION(ENABLE_MF "Use Media Foundation decoder (preferred over FFmpeg)" ON "WIN32" OFF) @@ -51,6 +47,14 @@ if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/hooks/pre-commit) DESTINATION ${PROJECT_SOURCE_DIR}/.git/hooks) endif() +# Use ccache for android if available +# ======================================================================= +if (NOT $ENV{NDK_CCACHE} EQUAL "") + set(CCACHE_EXE $ENV{NDK_CCACHE}) + set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXE}) + set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXE}) +endif() + # Sanity check : Check that all submodules are present # ======================================================================= @@ -108,13 +112,13 @@ if (NOT ENABLE_GENERIC) if (MSVC) detect_architecture("_M_AMD64" x86_64) detect_architecture("_M_IX86" x86) - detect_architecture("_M_ARM" arm) - detect_architecture("_M_ARM64" arm64) + detect_architecture("_M_ARM" ARM) + detect_architecture("_M_ARM64" ARM64) else() detect_architecture("__x86_64__" x86_64) detect_architecture("__i386__" x86) - detect_architecture("__arm__" arm) - detect_architecture("__aarch64__" arm64) + detect_architecture("__arm__" ARM) + detect_architecture("__aarch64__" ARM64) endif() endif() if (NOT DEFINED ARCHITECTURE) @@ -134,97 +138,121 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # set up output paths for executable binaries set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/$) - # System imported libraries # ====================== -# Download required dependecies with vcpkg -set(REQUIRED_LIBRARIES - boost-serialization - boost-system - boost-range - boost-icl - boost-date-time - boost-crc - boost-container - boost-asio - catch2 - cryptopp - enet - fmt - glm - glad[gl-api-33,gles2-api-32,extensions] - inih - lodepng - glslang - robin-hood-hashing - zstd -) +# Enable vcpkg features +if (NOT DEFINED VCPKG_MANIFEST_FEATURES) + if (ENABLE_SDL2) + find_package(SDL2 CONFIG) -foreach(LIBRARY ${REQUIRED_LIBRARIES}) - vcpkg_add_package(${LIBRARY}) -endforeach() + if (NOT SDL2_FOUND) + message(STATUS "SDL2 not found. Using vcpkg") + list(APPEND VCPKG_MANIFEST_FEATURES "citra-sdl2") + endif() + endif() -# Xbyak -if (ARCHITECTURE_x86_64) - vcpkg_add_package(xbyak) - find_package(xbyak CONFIG REQUIRED) + if (ENABLE_WEB_SERVICE) + list(APPEND VCPKG_MANIFEST_FEATURES "citra-web-service") + endif() + + if (USE_DISCORD_PRESENCE) + list(APPEND VCPKG_MANIFEST_FEATURES "citra-discord") + endif() + + if (ENABLE_FFMPEG) + find_package(FFmpeg COMPONENTS avcodec avformat avutil swscale swresample) + + if (NOT FFMPEG_FOUND OR "${FFmpeg_avcodec_VERSION}" VERSION_LESS "57.48.101") + message(STATUS "FFmpeg not found. Using vcpkg") + list(APPEND VCPKG_MANIFEST_FEATURES "citra-ffmpeg") + endif() + endif() + + if (ENABLE_FDK) + find_library(FDK_AAC fdk-aac DOC "The path to fdk_aac library") + if(FDK_AAC STREQUAL "FDK_AAC-NOTFOUND") + message(STATUS "FDK AAC not found. Using vcpkg") + list(APPEND VCPKG_MANIFEST_FEATURES "citra-fdk-aac") + endif() + endif() + + # Cache the selected manifest features. + set(VCPKG_MANIFEST_FEATURES ${VCPKG_MANIFEST_FEATURES} CACHE STRING "") endif() +# Prefer static linkage on windows and MinGW +if (MINGW) + set(VCPKG_TARGET_TRIPLET "x64-mingw-static") +elseif (WIN32) + # We could also build a dynamic CRT and not require this flag but vcpkg + # developers actively discourage this. See: + # https://github.com/microsoft/vcpkg/issues/15122#issuecomment-745497720 + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + set(VCPKG_TARGET_TRIPLET "x64-windows-static") +endif() + +# Include vcpkg toolchain file +include(${CMAKE_SOURCE_DIR}/externals/vcpkg/scripts/buildsystems/vcpkg.cmake) + +# Prefer the -pthread flag on Linux. +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + +# Boost +find_package(Boost REQUIRED COMPONENTS serialization) + # DiscordRPC if (USE_DISCORD_PRESENCE) - vcpkg_add_package(discord-rpc) find_package(discord-rpc CONFIG REQUIRED) endif() if (ENABLE_WEB_SERVICE) - # LibreSSL - vcpkg_add_package(openssl) + # OpenSSL find_package(OpenSSL REQUIRED) # JSON - vcpkg_add_package(nlohmann-json) find_package(nlohmann_json CONFIG REQUIRED) # httplib - vcpkg_add_package(cpp-httplib) find_path(CPP_HTTPLIB_INCLUDE_DIRS "httplib.h") add_library(httplib INTERFACE) target_include_directories(httplib INTERFACE ${CPP_HTTPLIB_INCLUDE_DIRS}) # cpp-jwt - vcpkg_add_package(cpp-jwt) find_package(cpp-jwt CONFIG REQUIRED) endif() # (xperia64): Only use libyuv on Android b/c of build issues on Windows and mandatory JPEG if(ANDROID) # libyuv - vcpkg_add_package(libyuv) find_package(libyuv CONFIG REQUIRED) endif() -# Prefer the -pthread flag on Linux. -set(THREADS_PREFER_PTHREAD_FLAG ON) -find_package(Threads REQUIRED) +# Find the rest of our dependecies +set(REQUIRED_PACKAGES + Catch2 + cryptopp + fmt + glad + glm + zstd + unofficial-enet + lodepng + glslang + xbyak +) + +foreach(PACKAGE ${REQUIRED_PACKAGES}) + find_package(${PACKAGE} CONFIG REQUIRED) +endforeach() if (ENABLE_SDL2) - find_package(SDL2 CONFIG) - - if (NOT SDL2_FOUND) - vcpkg_add_package(sdl2) - find_package(SDL2 CONFIG REQUIRED) - endif() - - if (SDL2_FOUND) - add_library(SDL2 INTERFACE) - target_link_libraries(SDL2 INTERFACE SDL2::SDL2 SDL2::SDL2main) - endif() + find_package(SDL2 CONFIG REQUIRED) else() set(SDL2_FOUND NO) endif() - if (ENABLE_QT) if (CITRA_USE_BUNDLED_QT) if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64) @@ -257,64 +285,24 @@ if(NOT APPLE) find_package(LibUSB) endif() if (NOT LIBUSB_FOUND) - vcpkg_add_package(libusb) - find_package(libusb CONFIG) - - if (NOT ${libusb_FOUND}) - set(LIBUSB_INCLUDE_DIRS ${LIBUSB_INCLUDE_DIR}) - set(LIBUSB_LIBRARIES ${LIBUSB_LIBRARY}) - endif() + set(LIBUSB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/externals/libusb/libusb/libusb") + set(LIBUSB_LIBRARIES usb) endif() if (ENABLE_FFMPEG) - vcpkg_add_package(ffmpeg[avcodec,avformat,avdevice,swresample]) - if (ENABLE_FFMPEG_VIDEO_DUMPER) - find_package(FFMPEG REQUIRED COMPONENTS libavcodec libavformat libavutil libswresample) + if(ENABLE_FFMPEG_VIDEO_DUMPER) + set(FFmpeg_COMPONENTS "avcodec avformat avutil swscale swresample") else() - find_package(FFMPEG REQUIRED COMPONENTS libavcodec) + set(FFmpeg_COMPONENTS "avcodec") endif() - if ("${FFmpeg_avcodec_VERSION}" VERSION_LESS "57.48.101") - message(FATAL_ERROR "Found version for libavcodec is too low. The required version is at least 57.48.101 (included in FFmpeg 3.1 and later).") - endif() -endif() - -if (ENABLE_FFMPEG_VIDEO_DUMPER) - add_definitions(-DENABLE_FFMPEG_VIDEO_DUMPER) + find_package(FFmpeg REQUIRED COMPONENTS ${FFmpeg_COMPONENTS}) endif() if (ENABLE_FDK) - vcpkg_add_package(fdk-acc) find_package(fdk-aac CONFIG REQUIRED) endif() -# Find the rest of our dependecies -set(REQUIRED_PACKAGES - Catch2 - cryptopp - fmt - glad - glm - zstd - unofficial-enet - lodepng - robin_hood -) - -foreach(PACKAGE ${REQUIRED_PACKAGES}) - find_package(${PACKAGE} CONFIG REQUIRED) -endforeach() - -# Find Boost::serialization -find_package(Boost REQUIRED COMPONENTS serialization) - -# Find inih -find_path(INIH_INCLUDE_DIR "INIReader.h" REQUIRED) -find_library(INIH_LIB NAMES inih REQUIRED) -add_library(inih INTERFACE) -target_include_directories(inih INTERFACE ${INIH_INCLUDE_DIR}) -target_link_libraries(inih INTERFACE ${INIH_LIB}) - # Platform-specific library requirements # ====================================== @@ -335,10 +323,6 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU|SunOS)$") set(PLATFORM_LIBRARIES rt) endif() -if (ENABLE_VULKAN) - find_package(glslang CONFIG REQUIRED) -endif() - # Setup a custom clang-format target (if clang-format can be found) that will run # against all the src files. This should be used before making a pull request. # ======================================================================= @@ -414,6 +398,13 @@ function(get_timestamp _var) set(${_var} "${timestamp}" PARENT_SCOPE) endfunction() +# Prevent boost from linking against libs when building +add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY + -DBOOST_SYSTEM_NO_LIB + -DBOOST_DATE_TIME_NO_LIB + -DBOOST_REGEX_NO_LIB +) + # generate git/build information include(GetGitRevisionDescription) get_git_head_revision(GIT_REF_SPEC GIT_REV) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 624402b25..e7b3be124 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -22,6 +22,9 @@ if (MSVC) add_subdirectory(getopt) endif() +# inih +add_subdirectory(inih) + # MicroProfile add_library(microprofile INTERFACE) target_include_directories(microprofile INTERFACE ./microprofile) diff --git a/externals/inih/CMakeLists.txt b/externals/inih/CMakeLists.txt new file mode 100644 index 000000000..c054a973f --- /dev/null +++ b/externals/inih/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(inih + inih/ini.c + inih/ini.h + inih/cpp/INIReader.cpp + inih/cpp/INIReader.h +) + +create_target_directory_groups(inih) +target_include_directories(inih INTERFACE .) \ No newline at end of file diff --git a/externals/inih/inih b/externals/inih/inih new file mode 160000 index 000000000..5e1d9e262 --- /dev/null +++ b/externals/inih/inih @@ -0,0 +1 @@ +Subproject commit 5e1d9e2625842dddb3f9c086a50f22e4f45dfc2b diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 471ad929b..6f747fcf5 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include "citra/config.h" #include "citra/default_ini.h" #include "common/file_util.h" diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 2d0deaa75..8288b48a6 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -208,7 +208,7 @@ target_link_libraries(video_core PRIVATE nihstro-headers glad::glad glm::glm Boo # Include Vulkan headers target_include_directories(video_core PRIVATE ../../externals/Vulkan-Headers/include) target_include_directories(video_core PRIVATE ../../externals/vma/include) -target_link_libraries(video_core PRIVATE glslang SPIRV robin_hood::robin_hood) +target_link_libraries(video_core PRIVATE glslang SPIRV) if (ARCHITECTURE_x86_64) target_link_libraries(video_core PUBLIC xbyak::xbyak) diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 000000000..abef623ba --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,80 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json", + "name": "citra-emu", + "version-string": "1.0.0", + "dependencies": [ + "boost-serialization", + "boost-system", + "boost-range", + "boost-icl", + "boost-date-time", + "boost-crc", + "boost-container", + "boost-asio", + "catch2", + "cryptopp", + "enet", + "libusb", + "glm", + "fmt", + { + "name": "glad", + "features": [ + "gl-api-33", + "gles2-api-32", + "extensions" + ] + }, + "libyuv", + "lodepng", + "zstd", + "xbyak", + "glslang" + ], + "features": { + "citra-discord": { + "description": "Discord Rich Presence", + "dependencies": [ + "discord-rpc" + ] + }, + "citra-sdl2": { + "description": "SDL2 frontend", + "dependencies": [ + "sdl2" + ] + }, + "citra-web-service": { + "description": "Web services (telemetry, etc.)", + "dependencies": [ + { + "name": "openssl", + "platform": "windows" + }, + "nlohmann-json", + "cpp-httplib", + "cpp-jwt" + ] + }, + "citra-ffmpeg": { + "description": "Enable FFmpeg utilities", + "dependencies": [ + { + "name": "ffmpeg", + "features": [ + "avcodec", + "avformat", + "avdevice", + "swresample" + ] + } + ] + }, + "citra-fdk-aac": { + "description": "FDK AAC decoder", + "dependencies": [ + "fdk-aac" + ] + } + } +}