CMakeLists.txt 28 KB

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