CMakeLists.txt 25 KB

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