CMakeLists.txt 25 KB

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