CMakeLists.txt 25 KB

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