CMakeLists.txt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. # SPDX-FileCopyrightText: 2018 yuzu Emulator Project
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. cmake_minimum_required(VERSION 3.22)
  4. project(yuzu)
  5. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
  6. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules")
  7. include(DownloadExternals)
  8. include(CMakeDependentOption)
  9. include(CTest)
  10. include(FetchContent)
  11. # Set bundled sdl2/qt as dependent options.
  12. # OFF by default, but if ENABLE_SDL2 and MSVC are true then ON
  13. option(ENABLE_SDL2 "Enable the SDL2 frontend" ON)
  14. CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" ON "ENABLE_SDL2;MSVC" OFF)
  15. # On Linux system SDL2 is likely to be lacking HIDAPI support which have drawbacks but is needed for SDL motion
  16. CMAKE_DEPENDENT_OPTION(YUZU_USE_EXTERNAL_SDL2 "Compile external SDL2" ON "ENABLE_SDL2;NOT MSVC" OFF)
  17. cmake_dependent_option(ENABLE_LIBUSB "Enable the use of LibUSB" ON "NOT ANDROID" OFF)
  18. option(ENABLE_OPENGL "Enable OpenGL" ON)
  19. mark_as_advanced(FORCE ENABLE_OPENGL)
  20. option(ENABLE_QT "Enable the Qt frontend" ON)
  21. option(ENABLE_QT6 "Allow usage of Qt6 to be attempted" OFF)
  22. set(QT6_LOCATION "" CACHE PATH "Additional Location to search for Qt6 libraries like C:/Qt/6.3.1/msvc2019_64/")
  23. option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF)
  24. CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" "${MSVC}" "ENABLE_QT" OFF)
  25. option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON)
  26. option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" "${WIN32}")
  27. option(YUZU_USE_EXTERNAL_VULKAN_HEADERS "Use Vulkan-Headers from externals" ON)
  28. option(YUZU_USE_QT_MULTIMEDIA "Use QtMultimedia for Camera" OFF)
  29. option(YUZU_USE_QT_WEB_ENGINE "Use QtWebEngine for web applet implementation" OFF)
  30. option(ENABLE_CUBEB "Enables the cubeb audio backend" ON)
  31. option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF)
  32. option(YUZU_TESTS "Compile tests" "${BUILD_TESTING}")
  33. option(YUZU_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
  34. cmake_dependent_option(YUZU_ROOM "Compile LDN room server" ON "NOT ANDROID" OFF)
  35. CMAKE_DEPENDENT_OPTION(YUZU_CRASH_DUMPS "Compile Windows crash dump (Minidump) support" OFF "WIN32" OFF)
  36. option(YUZU_USE_BUNDLED_VCPKG "Use vcpkg for yuzu dependencies" "${MSVC}")
  37. option(YUZU_CHECK_SUBMODULES "Check if submodules are present" ON)
  38. option(YUZU_ENABLE_LTO "Enable link-time optimization" OFF)
  39. option(YUZU_DOWNLOAD_TIME_ZONE_DATA "Always download time zone binaries" OFF)
  40. CMAKE_DEPENDENT_OPTION(YUZU_USE_FASTER_LD "Check if a faster linker is available" ON "NOT WIN32" OFF)
  41. CMAKE_DEPENDENT_OPTION(ENABLE_OPENSSL "Enable OpenSSL backend for ISslConnection" ON "NOT WIN32" OFF)
  42. # On Android, fetch and compile libcxx before doing anything else
  43. if (ANDROID)
  44. set(CMAKE_SKIP_INSTALL_RULES ON)
  45. set(LLVM_VERSION "15.0.6")
  46. # Note: even though libcxx and libcxxabi have separate releases on the project page,
  47. # the separated releases cannot be compiled. Only in-tree builds work. Therefore we
  48. # must fetch the source release for the entire llvm tree.
  49. FetchContent_Declare(llvm
  50. URL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-project-${LLVM_VERSION}.src.tar.xz"
  51. URL_HASH SHA256=9d53ad04dc60cb7b30e810faf64c5ab8157dadef46c8766f67f286238256ff92
  52. TLS_VERIFY TRUE
  53. )
  54. FetchContent_MakeAvailable(llvm)
  55. # libcxx has support for most of the range library, but it's gated behind a flag:
  56. add_compile_definitions(_LIBCPP_ENABLE_EXPERIMENTAL)
  57. # Disable standard header inclusion
  58. set(ANDROID_STL "none")
  59. # libcxxabi
  60. set(LIBCXXABI_INCLUDE_TESTS OFF)
  61. set(LIBCXXABI_ENABLE_SHARED FALSE)
  62. set(LIBCXXABI_ENABLE_STATIC TRUE)
  63. set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXX_TARGET_INCLUDE_DIRECTORY}" CACHE STRING "" FORCE)
  64. add_subdirectory("${llvm_SOURCE_DIR}/libcxxabi" "${llvm_BINARY_DIR}/libcxxabi")
  65. link_libraries(cxxabi_static)
  66. # libcxx
  67. set(LIBCXX_ABI_NAMESPACE "__ndk1" CACHE STRING "" FORCE)
  68. set(LIBCXX_CXX_ABI "libcxxabi")
  69. set(LIBCXX_INCLUDE_TESTS OFF)
  70. set(LIBCXX_INCLUDE_BENCHMARKS OFF)
  71. set(LIBCXX_INCLUDE_DOCS OFF)
  72. set(LIBCXX_ENABLE_SHARED FALSE)
  73. set(LIBCXX_ENABLE_STATIC TRUE)
  74. set(LIBCXX_ENABLE_ASSERTIONS FALSE)
  75. add_subdirectory("${llvm_SOURCE_DIR}/libcxx" "${llvm_BINARY_DIR}/libcxx")
  76. set_target_properties(cxx-headers PROPERTIES INTERFACE_COMPILE_OPTIONS "-isystem${CMAKE_BINARY_DIR}/${LIBCXX_INSTALL_INCLUDE_DIR}")
  77. link_libraries(cxx_static cxx-headers)
  78. endif()
  79. if (YUZU_USE_BUNDLED_VCPKG)
  80. if (ANDROID)
  81. set(ENV{ANDROID_NDK_HOME} "${ANDROID_NDK}")
  82. list(APPEND VCPKG_MANIFEST_FEATURES "android")
  83. if (CMAKE_ANDROID_ARCH_ABI STREQUAL "arm64-v8a")
  84. set(VCPKG_TARGET_TRIPLET "arm64-android")
  85. # this is to avoid CMake using the host pkg-config to find the host
  86. # libraries when building for Android targets
  87. set(PKG_CONFIG_EXECUTABLE "aarch64-none-linux-android-pkg-config" CACHE FILEPATH "" FORCE)
  88. elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL "x86_64")
  89. set(VCPKG_TARGET_TRIPLET "x64-android")
  90. set(PKG_CONFIG_EXECUTABLE "x86_64-none-linux-android-pkg-config" CACHE FILEPATH "" FORCE)
  91. else()
  92. message(FATAL_ERROR "Unsupported Android architecture ${CMAKE_ANDROID_ARCH_ABI}")
  93. endif()
  94. endif()
  95. if (YUZU_TESTS)
  96. list(APPEND VCPKG_MANIFEST_FEATURES "yuzu-tests")
  97. endif()
  98. if (YUZU_CRASH_DUMPS)
  99. list(APPEND VCPKG_MANIFEST_FEATURES "dbghelp")
  100. endif()
  101. if (ENABLE_WEB_SERVICE)
  102. list(APPEND VCPKG_MANIFEST_FEATURES "web-service")
  103. endif()
  104. include(${CMAKE_SOURCE_DIR}/externals/vcpkg/scripts/buildsystems/vcpkg.cmake)
  105. elseif(NOT "$ENV{VCPKG_TOOLCHAIN_FILE}" STREQUAL "")
  106. # Disable manifest mode (use vcpkg classic mode) when using a custom vcpkg installation
  107. option(VCPKG_MANIFEST_MODE "")
  108. include("$ENV{VCPKG_TOOLCHAIN_FILE}")
  109. endif()
  110. if (YUZU_USE_PRECOMPILED_HEADERS)
  111. if (MSVC AND CCACHE)
  112. # buildcache does not properly cache PCH files, leading to compilation errors.
  113. # See https://github.com/mbitsnbites/buildcache/discussions/230
  114. message(WARNING "buildcache does not properly support Precompiled Headers. Disabling PCH")
  115. set(DYNARMIC_USE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
  116. set(YUZU_USE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
  117. endif()
  118. endif()
  119. if (YUZU_USE_PRECOMPILED_HEADERS)
  120. message(STATUS "Using Precompiled Headers.")
  121. set(CMAKE_PCH_INSTANTIATE_TEMPLATES ON)
  122. endif()
  123. # Default to a Release build
  124. get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  125. if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
  126. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
  127. message(STATUS "Defaulting to a Release build")
  128. endif()
  129. if(EXISTS ${PROJECT_SOURCE_DIR}/hooks/pre-commit AND NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/hooks/pre-commit)
  130. if (EXISTS ${PROJECT_SOURCE_DIR}/.git/)
  131. message(STATUS "Copying pre-commit hook")
  132. file(COPY hooks/pre-commit DESTINATION ${PROJECT_SOURCE_DIR}/.git/hooks)
  133. endif()
  134. endif()
  135. # Sanity check : Check that all submodules are present
  136. # =======================================================================
  137. function(check_submodules_present)
  138. file(READ "${PROJECT_SOURCE_DIR}/.gitmodules" gitmodules)
  139. string(REGEX MATCHALL "path *= *[^ \t\r\n]*" gitmodules ${gitmodules})
  140. foreach(module ${gitmodules})
  141. string(REGEX REPLACE "path *= *" "" module ${module})
  142. if (NOT EXISTS "${PROJECT_SOURCE_DIR}/${module}/.git")
  143. message(FATAL_ERROR "Git submodule ${module} not found. "
  144. "Please run: \ngit submodule update --init --recursive")
  145. endif()
  146. endforeach()
  147. endfunction()
  148. if(EXISTS ${PROJECT_SOURCE_DIR}/.gitmodules AND YUZU_CHECK_SUBMODULES)
  149. check_submodules_present()
  150. endif()
  151. configure_file(${PROJECT_SOURCE_DIR}/dist/compatibility_list/compatibility_list.qrc
  152. ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.qrc
  153. COPYONLY)
  154. if (EXISTS ${PROJECT_SOURCE_DIR}/dist/compatibility_list/compatibility_list.json)
  155. configure_file("${PROJECT_SOURCE_DIR}/dist/compatibility_list/compatibility_list.json"
  156. "${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json"
  157. COPYONLY)
  158. endif()
  159. if (ENABLE_COMPATIBILITY_LIST_DOWNLOAD AND NOT EXISTS ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json)
  160. message(STATUS "Downloading compatibility list for yuzu...")
  161. file(DOWNLOAD
  162. https://api.yuzu-emu.org/gamedb/
  163. "${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json" SHOW_PROGRESS)
  164. endif()
  165. if (NOT EXISTS ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json)
  166. file(WRITE ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json "")
  167. endif()
  168. # Detect current compilation architecture and create standard definitions
  169. # =======================================================================
  170. include(CheckSymbolExists)
  171. function(detect_architecture symbol arch)
  172. if (NOT DEFINED ARCHITECTURE)
  173. set(CMAKE_REQUIRED_QUIET 1)
  174. check_symbol_exists("${symbol}" "" ARCHITECTURE_${arch})
  175. unset(CMAKE_REQUIRED_QUIET)
  176. # The output variable needs to be unique across invocations otherwise
  177. # CMake's crazy scope rules will keep it defined
  178. if (ARCHITECTURE_${arch})
  179. set(ARCHITECTURE "${arch}" PARENT_SCOPE)
  180. set(ARCHITECTURE_${arch} 1 PARENT_SCOPE)
  181. add_definitions(-DARCHITECTURE_${arch}=1)
  182. endif()
  183. endif()
  184. endfunction()
  185. if (NOT ENABLE_GENERIC)
  186. if (MSVC)
  187. detect_architecture("_M_AMD64" x86_64)
  188. detect_architecture("_M_IX86" x86)
  189. detect_architecture("_M_ARM" arm)
  190. detect_architecture("_M_ARM64" arm64)
  191. else()
  192. detect_architecture("__x86_64__" x86_64)
  193. detect_architecture("__i386__" x86)
  194. detect_architecture("__arm__" arm)
  195. detect_architecture("__aarch64__" arm64)
  196. endif()
  197. endif()
  198. if (NOT DEFINED ARCHITECTURE)
  199. set(ARCHITECTURE "GENERIC")
  200. set(ARCHITECTURE_GENERIC 1)
  201. add_definitions(-DARCHITECTURE_GENERIC=1)
  202. endif()
  203. message(STATUS "Target architecture: ${ARCHITECTURE}")
  204. if (UNIX)
  205. add_definitions(-DYUZU_UNIX=1)
  206. endif()
  207. # Configure C++ standard
  208. # ===========================
  209. # boost asio's concept usage doesn't play nicely with some compilers yet.
  210. add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS)
  211. if (MSVC)
  212. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/std:c++20>)
  213. # boost still makes use of deprecated result_of.
  214. add_definitions(-D_HAS_DEPRECATED_RESULT_OF)
  215. else()
  216. set(CMAKE_CXX_STANDARD 20)
  217. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  218. endif()
  219. # Output binaries to bin/
  220. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
  221. # System imported libraries
  222. # =======================================================================
  223. # Enforce the search mode of non-required packages for better and shorter failure messages
  224. find_package(Boost 1.79.0 REQUIRED context)
  225. find_package(enet 1.3 MODULE)
  226. find_package(fmt 9 REQUIRED)
  227. find_package(inih 52 MODULE COMPONENTS INIReader)
  228. find_package(LLVM MODULE COMPONENTS Demangle)
  229. find_package(lz4 REQUIRED)
  230. find_package(nlohmann_json 3.8 REQUIRED)
  231. find_package(Opus 1.3 MODULE)
  232. find_package(ZLIB 1.2 REQUIRED)
  233. find_package(zstd 1.5 REQUIRED)
  234. if (NOT YUZU_USE_EXTERNAL_VULKAN_HEADERS)
  235. find_package(Vulkan 1.3.246 REQUIRED)
  236. endif()
  237. if (ENABLE_LIBUSB)
  238. find_package(libusb 1.0.24 MODULE)
  239. endif()
  240. if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64)
  241. find_package(xbyak 6 CONFIG)
  242. endif()
  243. if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
  244. find_package(dynarmic 6.4.0 CONFIG)
  245. endif()
  246. if (ENABLE_CUBEB)
  247. find_package(cubeb CONFIG)
  248. endif()
  249. if (USE_DISCORD_PRESENCE)
  250. find_package(DiscordRPC MODULE)
  251. endif()
  252. if (ENABLE_WEB_SERVICE)
  253. find_package(cpp-jwt 1.4 CONFIG)
  254. find_package(httplib 0.12 MODULE COMPONENTS OpenSSL)
  255. endif()
  256. if (YUZU_TESTS)
  257. find_package(Catch2 3.0.1 REQUIRED)
  258. endif()
  259. # boost:asio has functions that require AcceptEx et al
  260. if (MINGW)
  261. find_library(MSWSOCK_LIBRARY mswsock REQUIRED)
  262. endif()
  263. if(ENABLE_OPENSSL)
  264. find_package(OpenSSL 3.0.0 REQUIRED)
  265. endif()
  266. # Please consider this as a stub
  267. if(ENABLE_QT6 AND Qt6_LOCATION)
  268. list(APPEND CMAKE_PREFIX_PATH "${Qt6_LOCATION}")
  269. endif()
  270. function(set_yuzu_qt_components)
  271. # Best practice is to ask for all components at once, so they are from the same version
  272. set(YUZU_QT_COMPONENTS2 Core Widgets Concurrent)
  273. if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  274. list(APPEND YUZU_QT_COMPONENTS2 DBus)
  275. endif()
  276. if (YUZU_USE_QT_MULTIMEDIA)
  277. list(APPEND YUZU_QT_COMPONENTS2 Multimedia)
  278. endif()
  279. if (YUZU_USE_QT_WEB_ENGINE)
  280. list(APPEND YUZU_QT_COMPONENTS2 WebEngineCore WebEngineWidgets)
  281. endif()
  282. if (ENABLE_QT_TRANSLATION)
  283. list(APPEND YUZU_QT_COMPONENTS2 LinguistTools)
  284. endif()
  285. set(YUZU_QT_COMPONENTS ${YUZU_QT_COMPONENTS2} PARENT_SCOPE)
  286. endfunction(set_yuzu_qt_components)
  287. # Qt5 requires that we find components, so it doesn't fit our pretty little find package function
  288. if(ENABLE_QT)
  289. set(QT_VERSION 5.15)
  290. # These are used to specify minimum versions
  291. set(QT5_VERSION 5.15)
  292. set(QT6_VERSION 6.3.1)
  293. set_yuzu_qt_components()
  294. if (ENABLE_QT6)
  295. find_package(Qt6 ${QT6_VERSION} COMPONENTS ${YUZU_QT_COMPONENTS})
  296. endif()
  297. if (Qt6_FOUND)
  298. message(STATUS "yuzu/CMakeLists.txt: Qt6Widgets_VERSION ${Qt6Widgets_VERSION}, setting QT_VERSION")
  299. set(QT_VERSION ${Qt6Widgets_VERSION})
  300. set(QT_MAJOR_VERSION 6)
  301. # Qt6 sets cxx_std_17 and we need to undo that
  302. set_target_properties(Qt6::Platform PROPERTIES INTERFACE_COMPILE_FEATURES "")
  303. else()
  304. message(STATUS "yuzu/CMakeLists.txt: Qt6 not found/not selected, trying for Qt5")
  305. # When Qt6 partially found, need this set to use Qt5 when not specifying version
  306. set(QT_DEFAULT_MAJOR_VERSION 5)
  307. set(QT_MAJOR_VERSION 5)
  308. set(YUZU_USE_QT_MULTIMEDIA ON)
  309. # Check for system Qt on Linux, fallback to bundled Qt
  310. if (UNIX AND NOT APPLE)
  311. if (NOT YUZU_USE_BUNDLED_QT)
  312. find_package(Qt5 ${QT5_VERSION} COMPONENTS Widgets DBus Multimedia)
  313. endif()
  314. if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND (NOT Qt5_FOUND OR YUZU_USE_BUNDLED_QT))
  315. # Check for dependencies, then enable bundled Qt download
  316. # Check that the system GLIBCXX version is compatible
  317. find_program(OBJDUMP objdump)
  318. if (NOT OBJDUMP)
  319. message(FATAL_ERROR "Required program `objdump` not found.")
  320. endif()
  321. find_library(LIBSTDCXX libstdc++.so.6)
  322. execute_process(
  323. COMMAND
  324. ${OBJDUMP} -T ${LIBSTDCXX}
  325. COMMAND
  326. grep GLIBCXX_3.4.28
  327. COMMAND
  328. sed "s/[0-9a-f]*.* //"
  329. COMMAND
  330. sed "s/ .*//"
  331. COMMAND
  332. sort -u
  333. OUTPUT_VARIABLE
  334. GLIBCXX_MET
  335. )
  336. if (NOT GLIBCXX_MET)
  337. message(FATAL_ERROR "Qt too old or not found, and bundled Qt package is not \
  338. compatible with this system. Either install Qt ${QT_VERSION}, or provide the path \
  339. to Qt by setting the variable Qt5_ROOT.")
  340. endif()
  341. # Check for headers
  342. find_package(PkgConfig REQUIRED)
  343. pkg_check_modules(QT_DEP_GLU QUIET glu>=9.0.0)
  344. if (NOT QT_DEP_GLU_FOUND)
  345. message(FATAL_ERROR "Qt bundled package dependency `glu` not found. \
  346. Perhaps `libglu1-mesa-dev` needs to be installed?")
  347. endif()
  348. pkg_check_modules(QT_DEP_MESA QUIET dri>=20.0.8)
  349. if (NOT QT_DEP_MESA_FOUND)
  350. message(FATAL_ERROR "Qt bundled package dependency `dri` not found. \
  351. Perhaps `mesa-common-dev` needs to be installed?")
  352. endif()
  353. # Check for X libraries
  354. set(BUNDLED_QT_REQUIREMENTS
  355. libxcb-icccm.so.4
  356. libxcb-image.so.0
  357. libxcb-keysyms.so.1
  358. libxcb-randr.so.0
  359. libxcb-render-util.so.0
  360. libxcb-render.so.0
  361. libxcb-shape.so.0
  362. libxcb-shm.so.0
  363. libxcb-sync.so.1
  364. libxcb-xfixes.so.0
  365. libxcb-xinerama.so.0
  366. libxcb-xkb.so.1
  367. libxcb.so.1
  368. libxkbcommon-x11.so.0
  369. libxkbcommon.so.0
  370. )
  371. set(UNRESOLVED_QT_DEPS "")
  372. foreach (REQUIREMENT ${BUNDLED_QT_REQUIREMENTS})
  373. find_library(BUNDLED_QT_${REQUIREMENT} ${REQUIREMENT})
  374. if (NOT BUNDLED_QT_${REQUIREMENT})
  375. set(UNRESOLVED_QT_DEPS ${UNRESOLVED_QT_DEPS} ${REQUIREMENT})
  376. endif()
  377. unset(BUNDLED_QT_${REQUIREMENT})
  378. endforeach()
  379. unset(BUNDLED_QT_REQUIREMENTS)
  380. if (NOT "${UNRESOLVED_QT_DEPS}" STREQUAL "")
  381. message(FATAL_ERROR "Bundled Qt package missing required dependencies: ${UNRESOLVED_QT_DEPS}")
  382. endif()
  383. set(YUZU_USE_BUNDLED_QT ON CACHE BOOL "Download bundled Qt" FORCE)
  384. endif()
  385. if (YUZU_USE_BUNDLED_QT)
  386. # Binary package currently does not support Qt webengine, so make sure it's disabled
  387. set(YUZU_USE_QT_WEB_ENGINE OFF CACHE BOOL "Use Qt Webengine" FORCE)
  388. endif()
  389. endif()
  390. set(YUZU_QT_NO_CMAKE_SYSTEM_PATH)
  391. if(YUZU_USE_BUNDLED_QT)
  392. if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64)
  393. set(QT_BUILD qt-5.15.2-msvc2019_64)
  394. elseif ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") AND NOT MINGW AND ARCHITECTURE_x86_64)
  395. set(QT_BUILD qt5_5_15_2)
  396. else()
  397. message(FATAL_ERROR "No bundled Qt binaries for your toolchain. Disable YUZU_USE_BUNDLED_QT and provide your own.")
  398. endif()
  399. if (DEFINED QT_BUILD)
  400. download_bundled_external("qt/" ${QT_BUILD} QT_PREFIX)
  401. endif()
  402. set(QT_PREFIX_HINT HINTS "${QT_PREFIX}")
  403. set(YUZU_QT_NO_CMAKE_SYSTEM_PATH "NO_CMAKE_SYSTEM_PATH")
  404. # Binary package for Qt5 has Qt Multimedia
  405. set(YUZU_USE_QT_MULTIMEDIA ON CACHE BOOL "Use Qt Multimedia" FORCE)
  406. endif()
  407. set_yuzu_qt_components()
  408. find_package(Qt5 ${QT5_VERSION} COMPONENTS ${YUZU_QT_COMPONENTS} ${QT_PREFIX_HINT} ${YUZU_QT_NO_CMAKE_SYSTEM_PATH})
  409. endif()
  410. endif()
  411. # find SDL2 exports a bunch of variables that are needed, so its easier to do this outside of the yuzu_find_package
  412. if (ENABLE_SDL2)
  413. if (YUZU_USE_BUNDLED_SDL2)
  414. # Detect toolchain and platform
  415. if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64)
  416. set(SDL2_VER "SDL2-2.0.18")
  417. else()
  418. message(FATAL_ERROR "No bundled SDL2 binaries for your toolchain. Disable YUZU_USE_BUNDLED_SDL2 and provide your own.")
  419. endif()
  420. if (DEFINED SDL2_VER)
  421. download_bundled_external("sdl2/" ${SDL2_VER} SDL2_PREFIX)
  422. endif()
  423. set(SDL2_FOUND YES)
  424. set(SDL2_INCLUDE_DIR "${SDL2_PREFIX}/include" CACHE PATH "Path to SDL2 headers")
  425. set(SDL2_LIBRARY "${SDL2_PREFIX}/lib/x64/SDL2.lib" CACHE PATH "Path to SDL2 library")
  426. set(SDL2_DLL_DIR "${SDL2_PREFIX}/lib/x64/" CACHE PATH "Path to SDL2.dll")
  427. add_library(SDL2::SDL2 INTERFACE IMPORTED)
  428. target_link_libraries(SDL2::SDL2 INTERFACE "${SDL2_LIBRARY}")
  429. target_include_directories(SDL2::SDL2 INTERFACE "${SDL2_INCLUDE_DIR}")
  430. elseif (YUZU_USE_EXTERNAL_SDL2)
  431. message(STATUS "Using SDL2 from externals.")
  432. else()
  433. find_package(SDL2 2.0.18 REQUIRED)
  434. endif()
  435. endif()
  436. # List of all FFmpeg components required
  437. set(FFmpeg_COMPONENTS
  438. avcodec
  439. avfilter
  440. avutil
  441. swscale)
  442. if (UNIX AND NOT APPLE AND NOT ANDROID)
  443. find_package(PkgConfig REQUIRED)
  444. pkg_check_modules(LIBVA libva)
  445. endif()
  446. if (NOT YUZU_USE_BUNDLED_FFMPEG)
  447. # Use system installed FFmpeg
  448. find_package(FFmpeg 4.3 REQUIRED QUIET COMPONENTS ${FFmpeg_COMPONENTS})
  449. endif()
  450. # Prefer the -pthread flag on Linux.
  451. set(THREADS_PREFER_PTHREAD_FLAG ON)
  452. find_package(Threads REQUIRED)
  453. # Platform-specific library requirements
  454. # ======================================
  455. if (APPLE)
  456. # Umbrella framework for everything GUI-related
  457. find_library(COCOA_LIBRARY Cocoa)
  458. set(PLATFORM_LIBRARIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
  459. elseif (WIN32)
  460. # Target Windows 10
  461. add_definitions(-D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00)
  462. set(PLATFORM_LIBRARIES winmm ws2_32 iphlpapi)
  463. if (MINGW)
  464. # PSAPI is the Process Status API
  465. set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} psapi imm32 version)
  466. endif()
  467. if (YUZU_CRASH_DUMPS)
  468. find_library(DBGHELP_LIBRARY dbghelp)
  469. if ("${DBGHELP_LIBRARY}" STREQUAL "DBGHELP_LIBRARY-NOTFOUND")
  470. message(FATAL_ERROR "YUZU_CRASH_DUMPS enabled but dbghelp library not found")
  471. endif()
  472. endif()
  473. elseif (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU|SunOS)$")
  474. set(PLATFORM_LIBRARIES rt)
  475. endif()
  476. # Setup a custom clang-format target (if clang-format can be found) that will run
  477. # against all the src files. This should be used before making a pull request.
  478. # =======================================================================
  479. set(CLANG_FORMAT_POSTFIX "-15")
  480. find_program(CLANG_FORMAT
  481. NAMES clang-format${CLANG_FORMAT_POSTFIX}
  482. clang-format
  483. PATHS ${PROJECT_BINARY_DIR}/externals)
  484. # if find_program doesn't find it, try to download from externals
  485. if (NOT CLANG_FORMAT)
  486. if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
  487. message(STATUS "Clang format not found! Downloading...")
  488. set(CLANG_FORMAT "${PROJECT_BINARY_DIR}/externals/clang-format${CLANG_FORMAT_POSTFIX}.exe")
  489. file(DOWNLOAD
  490. https://github.com/yuzu-emu/ext-windows-bin/raw/master/clang-format${CLANG_FORMAT_POSTFIX}.exe
  491. "${CLANG_FORMAT}" SHOW_PROGRESS
  492. STATUS DOWNLOAD_SUCCESS)
  493. if (NOT DOWNLOAD_SUCCESS EQUAL 0)
  494. message(WARNING "Could not download clang format! Disabling the clang format target")
  495. file(REMOVE ${CLANG_FORMAT})
  496. unset(CLANG_FORMAT)
  497. endif()
  498. else()
  499. message(WARNING "Clang format not found! Disabling the clang format target")
  500. endif()
  501. endif()
  502. if (CLANG_FORMAT)
  503. set(SRCS ${PROJECT_SOURCE_DIR}/src)
  504. set(CCOMMENT "Running clang format against all the .h and .cpp files in src/")
  505. if (WIN32)
  506. add_custom_target(clang-format
  507. COMMAND powershell.exe -Command "Get-ChildItem '${SRCS}/*' -Include *.cpp,*.h -Recurse | Foreach {&'${CLANG_FORMAT}' -i $_.fullname}"
  508. COMMENT ${CCOMMENT})
  509. elseif(MINGW)
  510. add_custom_target(clang-format
  511. COMMAND find `cygpath -u ${SRCS}` -iname *.h -o -iname *.cpp | xargs `cygpath -u ${CLANG_FORMAT}` -i
  512. COMMENT ${CCOMMENT})
  513. else()
  514. add_custom_target(clang-format
  515. COMMAND find ${SRCS} -iname *.h -o -iname *.cpp | xargs ${CLANG_FORMAT} -i
  516. COMMENT ${CCOMMENT})
  517. endif()
  518. unset(SRCS)
  519. unset(CCOMMENT)
  520. endif()
  521. # Include source code
  522. # ===================
  523. # This function should be passed a list of all files in a target. It will automatically generate
  524. # file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
  525. # one in the filesystem.
  526. function(create_target_directory_groups target_name)
  527. # Place any files that aren't in the source list in a separate group so that they don't get in
  528. # the way.
  529. source_group("Other Files" REGULAR_EXPRESSION ".")
  530. get_target_property(target_sources "${target_name}" SOURCES)
  531. foreach(file_name IN LISTS target_sources)
  532. get_filename_component(dir_name "${file_name}" PATH)
  533. # Group names use '\' as a separator even though the entire rest of CMake uses '/'...
  534. string(REPLACE "/" "\\" group_name "${dir_name}")
  535. source_group("${group_name}" FILES "${file_name}")
  536. endforeach()
  537. endfunction()
  538. # Prevent boost from linking against libs when building
  539. target_link_libraries(Boost::headers INTERFACE Boost::disable_autolinking)
  540. # Adjustments for MSVC + Ninja
  541. if (MSVC AND CMAKE_GENERATOR STREQUAL "Ninja")
  542. add_compile_options(
  543. /wd4464 # relative include path contains '..'
  544. /wd4711 # function 'function' selected for automatic inline expansion
  545. /wd4820 # 'bytes' bytes padding added after construct 'member_name'
  546. )
  547. endif()
  548. if (YUZU_USE_FASTER_LD AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  549. # We will assume that if the compiler is GCC, it will attempt to use ld.bfd by default.
  550. # Try to pick a faster linker.
  551. find_program(LLD lld)
  552. find_program(MOLD mold)
  553. if (MOLD AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.1")
  554. message(NOTICE "Selecting mold as linker")
  555. add_link_options("-fuse-ld=mold")
  556. elseif (LLD)
  557. message(NOTICE "Selecting lld as linker")
  558. add_link_options("-fuse-ld=lld")
  559. endif()
  560. endif()
  561. add_subdirectory(externals)
  562. add_subdirectory(src)
  563. # Set yuzu project or yuzu-cmd project as default StartUp Project in Visual Studio depending on whether QT is enabled or not
  564. if(ENABLE_QT)
  565. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT yuzu)
  566. else()
  567. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT yuzu-cmd)
  568. endif()
  569. # Installation instructions
  570. # =========================
  571. # Install freedesktop.org metadata files, following those specifications:
  572. # https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
  573. # https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
  574. # https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
  575. # https://www.freedesktop.org/software/appstream/docs/
  576. if(ENABLE_QT AND UNIX AND NOT APPLE)
  577. install(FILES "dist/org.yuzu_emu.yuzu.desktop"
  578. DESTINATION "share/applications")
  579. install(FILES "dist/yuzu.svg"
  580. DESTINATION "share/icons/hicolor/scalable/apps"
  581. RENAME "org.yuzu_emu.yuzu.svg")
  582. install(FILES "dist/org.yuzu_emu.yuzu.xml"
  583. DESTINATION "share/mime/packages")
  584. install(FILES "dist/org.yuzu_emu.yuzu.metainfo.xml"
  585. DESTINATION "share/metainfo")
  586. endif()