CMakeLists.txt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. cmake_minimum_required(VERSION 3.15)
  2. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
  3. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules")
  4. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/find-modules")
  5. include(DownloadExternals)
  6. include(CMakeDependentOption)
  7. project(yuzu)
  8. # Set bundled sdl2/qt as dependent options.
  9. # OFF by default, but if ENABLE_SDL2 and MSVC are true then ON
  10. option(ENABLE_SDL2 "Enable the SDL2 frontend" ON)
  11. CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" ON "ENABLE_SDL2;MSVC" OFF)
  12. # On Linux system SDL2 is likely to be lacking HIDAPI support which have drawbacks but is needed for SDL motion
  13. CMAKE_DEPENDENT_OPTION(YUZU_USE_EXTERNAL_SDL2 "Compile external SDL2" ON "ENABLE_SDL2;NOT MSVC" OFF)
  14. option(ENABLE_QT "Enable the Qt frontend" ON)
  15. option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF)
  16. CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" "${MSVC}" "ENABLE_QT" OFF)
  17. option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON)
  18. option(YUZU_USE_BUNDLED_LIBUSB "Compile bundled libusb" OFF)
  19. option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" "${WIN32}")
  20. option(YUZU_USE_QT_WEB_ENGINE "Use QtWebEngine for web applet implementation" OFF)
  21. option(ENABLE_CUBEB "Enables the cubeb audio backend" ON)
  22. option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF)
  23. option(YUZU_USE_BUNDLED_OPUS "Compile bundled opus" ON)
  24. option(YUZU_TESTS "Compile tests" ON)
  25. # Default to a Release build
  26. get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  27. if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
  28. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
  29. message(STATUS "Defaulting to a Release build")
  30. endif()
  31. if(EXISTS ${PROJECT_SOURCE_DIR}/hooks/pre-commit AND NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/hooks/pre-commit)
  32. if (EXISTS ${PROJECT_SOURCE_DIR}/.git/)
  33. message(STATUS "Copying pre-commit hook")
  34. file(COPY hooks/pre-commit DESTINATION ${PROJECT_SOURCE_DIR}/.git/hooks)
  35. endif()
  36. endif()
  37. # Sanity check : Check that all submodules are present
  38. # =======================================================================
  39. function(check_submodules_present)
  40. file(READ "${PROJECT_SOURCE_DIR}/.gitmodules" gitmodules)
  41. string(REGEX MATCHALL "path *= *[^ \t\r\n]*" gitmodules ${gitmodules})
  42. foreach(module ${gitmodules})
  43. string(REGEX REPLACE "path *= *" "" module ${module})
  44. if (NOT EXISTS "${PROJECT_SOURCE_DIR}/${module}/.git")
  45. message(FATAL_ERROR "Git submodule ${module} not found. "
  46. "Please run: \ngit submodule update --init --recursive")
  47. endif()
  48. endforeach()
  49. endfunction()
  50. if(EXISTS ${PROJECT_SOURCE_DIR}/.gitmodules)
  51. check_submodules_present()
  52. endif()
  53. configure_file(${PROJECT_SOURCE_DIR}/dist/compatibility_list/compatibility_list.qrc
  54. ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.qrc
  55. COPYONLY)
  56. if (ENABLE_COMPATIBILITY_LIST_DOWNLOAD AND NOT EXISTS ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json)
  57. message(STATUS "Downloading compatibility list for yuzu...")
  58. file(DOWNLOAD
  59. https://api.yuzu-emu.org/gamedb/
  60. "${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json" SHOW_PROGRESS)
  61. endif()
  62. if (NOT EXISTS ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json)
  63. file(WRITE ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json "")
  64. endif()
  65. # Detect current compilation architecture and create standard definitions
  66. # =======================================================================
  67. include(CheckSymbolExists)
  68. function(detect_architecture symbol arch)
  69. if (NOT DEFINED ARCHITECTURE)
  70. set(CMAKE_REQUIRED_QUIET 1)
  71. check_symbol_exists("${symbol}" "" ARCHITECTURE_${arch})
  72. unset(CMAKE_REQUIRED_QUIET)
  73. # The output variable needs to be unique across invocations otherwise
  74. # CMake's crazy scope rules will keep it defined
  75. if (ARCHITECTURE_${arch})
  76. set(ARCHITECTURE "${arch}" PARENT_SCOPE)
  77. set(ARCHITECTURE_${arch} 1 PARENT_SCOPE)
  78. add_definitions(-DARCHITECTURE_${arch}=1)
  79. endif()
  80. endif()
  81. endfunction()
  82. if (NOT ENABLE_GENERIC)
  83. if (MSVC)
  84. detect_architecture("_M_AMD64" x86_64)
  85. detect_architecture("_M_IX86" x86)
  86. detect_architecture("_M_ARM" ARM)
  87. detect_architecture("_M_ARM64" ARM64)
  88. else()
  89. detect_architecture("__x86_64__" x86_64)
  90. detect_architecture("__i386__" x86)
  91. detect_architecture("__arm__" ARM)
  92. detect_architecture("__aarch64__" ARM64)
  93. endif()
  94. endif()
  95. if (NOT DEFINED ARCHITECTURE)
  96. set(ARCHITECTURE "GENERIC")
  97. set(ARCHITECTURE_GENERIC 1)
  98. add_definitions(-DARCHITECTURE_GENERIC=1)
  99. endif()
  100. message(STATUS "Target architecture: ${ARCHITECTURE}")
  101. if (UNIX)
  102. add_definitions(-DYUZU_UNIX=1)
  103. endif()
  104. # Configure C++ standard
  105. # ===========================
  106. # boost asio's concept usage doesn't play nicely with some compilers yet.
  107. add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS)
  108. if (MSVC)
  109. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/std:c++latest>)
  110. # boost still makes use of deprecated result_of.
  111. add_definitions(-D_HAS_DEPRECATED_RESULT_OF)
  112. else()
  113. set(CMAKE_CXX_STANDARD 20)
  114. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  115. endif()
  116. # Output binaries to bin/
  117. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
  118. # System imported libraries
  119. # If not found, download any missing through Conan
  120. # =======================================================================
  121. set(CONAN_CMAKE_SILENT_OUTPUT TRUE)
  122. set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
  123. if (YUZU_CONAN_INSTALLED)
  124. if (IS_MULTI_CONFIG)
  125. include(${CMAKE_BINARY_DIR}/conanbuildinfo_multi.cmake)
  126. else()
  127. include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
  128. endif()
  129. list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}")
  130. list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
  131. conan_basic_setup()
  132. message(STATUS "Adding conan installed libraries to the search path")
  133. endif()
  134. macro(yuzu_find_packages)
  135. set(options FORCE_REQUIRED)
  136. cmake_parse_arguments(FN "${options}" "" "" ${ARGN})
  137. # Cmake has a *serious* lack of 2D array or associative array...
  138. # Capitalization matters here. We need the naming to match the generated paths from Conan
  139. set(REQUIRED_LIBS
  140. # Cmake Pkg Prefix Version Conan Pkg
  141. "fmt 8.0.1 fmt/8.1.1"
  142. "lz4 1.8 lz4/1.9.2"
  143. "nlohmann_json 3.8 nlohmann_json/3.8.0"
  144. "ZLIB 1.2 zlib/1.2.11"
  145. "zstd 1.5 zstd/1.5.0"
  146. # can't use opus until AVX check is fixed: https://github.com/yuzu-emu/yuzu/pull/4068
  147. #"opus 1.3 opus/1.3.1"
  148. )
  149. if (YUZU_TESTS)
  150. list(APPEND REQUIRED_LIBS
  151. "Catch2 2.13.7 catch2/2.13.7"
  152. )
  153. endif()
  154. foreach(PACKAGE ${REQUIRED_LIBS})
  155. string(REGEX REPLACE "[ \t\r\n]+" ";" PACKAGE_SPLIT ${PACKAGE})
  156. list(GET PACKAGE_SPLIT 0 PACKAGE_PREFIX)
  157. list(GET PACKAGE_SPLIT 1 PACKAGE_VERSION)
  158. list(GET PACKAGE_SPLIT 2 PACKAGE_CONAN)
  159. # This function is called twice, once to check if the packages exist on the system already
  160. # and a second time to check if conan installed them properly. The second check passes in FORCE_REQUIRED
  161. if (NOT ${PACKAGE_PREFIX}_FOUND)
  162. if (FN_FORCE_REQUIRED)
  163. find_package(${PACKAGE_PREFIX} ${PACKAGE_VERSION} REQUIRED)
  164. else()
  165. find_package(${PACKAGE_PREFIX} ${PACKAGE_VERSION})
  166. endif()
  167. endif()
  168. if (NOT ${PACKAGE_PREFIX}_FOUND)
  169. list(APPEND CONAN_REQUIRED_LIBS ${PACKAGE_CONAN})
  170. else()
  171. # Set a legacy findPackage.cmake style PACKAGE_LIBRARIES variable for subprojects that rely on this
  172. set(${PACKAGE_PREFIX}_LIBRARIES "${PACKAGE_PREFIX}::${PACKAGE_PREFIX}")
  173. endif()
  174. endforeach()
  175. unset(FN_FORCE_REQUIRED)
  176. endmacro()
  177. find_package(Boost 1.73.0 COMPONENTS context headers)
  178. if (Boost_FOUND)
  179. set(Boost_LIBRARIES Boost::boost)
  180. # Conditionally add Boost::context only if the active version of the Conan or system Boost package provides it
  181. # The old version is missing Boost::context, so we want to avoid adding in that case
  182. # The new version requires adding Boost::context to prevent linking issues
  183. #
  184. # This one is used by Conan on subsequent CMake configures, not the first configure.
  185. if (TARGET Boost::context)
  186. list(APPEND Boost_LIBRARIES Boost::context)
  187. endif()
  188. else()
  189. message(STATUS "Boost 1.79.0 or newer not found, falling back to Conan")
  190. list(APPEND CONAN_REQUIRED_LIBS "boost/1.79.0")
  191. endif()
  192. # boost:asio has functions that require AcceptEx et al
  193. if (MINGW)
  194. find_library(MSWSOCK_LIBRARY mswsock REQUIRED)
  195. endif()
  196. # Attempt to locate any packages that are required and report the missing ones in CONAN_REQUIRED_LIBS
  197. yuzu_find_packages()
  198. # Qt5 requires that we find components, so it doesn't fit our pretty little find package function
  199. if(ENABLE_QT)
  200. set(QT_VERSION 5.15)
  201. # We want to load the generated conan qt config so that we get the QT_ROOT var so that we can use the official
  202. # Qt5Config inside the root folder instead of the conan generated one.
  203. if(EXISTS ${CMAKE_BINARY_DIR}/qtConfig.cmake)
  204. include(${CMAKE_BINARY_DIR}/qtConfig.cmake)
  205. list(APPEND CMAKE_MODULE_PATH "${CONAN_QT_ROOT_RELEASE}")
  206. list(APPEND CMAKE_PREFIX_PATH "${CONAN_QT_ROOT_RELEASE}")
  207. endif()
  208. # Check for system Qt on Linux, fallback to bundled Qt
  209. if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  210. if (NOT YUZU_USE_BUNDLED_QT)
  211. find_package(Qt5 ${QT_VERSION} COMPONENTS Widgets DBus)
  212. endif()
  213. if (NOT Qt5_FOUND OR YUZU_USE_BUNDLED_QT)
  214. # Check for dependencies, then enable bundled Qt download
  215. # Check that the system GLIBCXX version is compatible
  216. find_program(OBJDUMP objdump)
  217. if ("${OBJDUMP}" STREQUAL "OBJDUMP-NOTFOUND")
  218. message(FATAL_ERROR "Required program `objdump` not found.")
  219. endif()
  220. find_library(LIBSTDCXX libstdc++.so.6)
  221. execute_process(
  222. COMMAND
  223. ${OBJDUMP} -T ${LIBSTDCXX}
  224. COMMAND
  225. grep GLIBCXX_3.4.28
  226. COMMAND
  227. sed "s/[0-9a-f]*.* //"
  228. COMMAND
  229. sed "s/ .*//"
  230. COMMAND
  231. sort -u
  232. OUTPUT_VARIABLE
  233. GLIBCXX_MET
  234. )
  235. if (NOT GLIBCXX_MET)
  236. message(FATAL_ERROR "Qt too old or not found, and bundled Qt package is not \
  237. compatible with this system. Either install Qt ${QT_VERSION}, or provide the path \
  238. to Qt by setting the variable Qt5_ROOT.")
  239. endif()
  240. # Check for headers
  241. Include(FindPkgConfig REQUIRED)
  242. pkg_check_modules(QT_DEP_GLU QUIET glu>=9.0.0)
  243. if (NOT QT_DEP_GLU_FOUND)
  244. message(FATAL_ERROR "Qt bundled pacakge dependency `glu` not found. \
  245. Perhaps `libglu1-mesa-dev` needs to be installed?")
  246. endif()
  247. pkg_check_modules(QT_DEP_MESA QUIET dri>=20.0.8)
  248. if (NOT QT_DEP_MESA_FOUND)
  249. message(FATAL_ERROR "Qt bundled pacakge dependency `dri` not found. \
  250. Perhaps `mesa-common-dev` needs to be installed?")
  251. endif()
  252. # Check for X libraries
  253. set(BUNDLED_QT_REQUIREMENTS
  254. libxcb-icccm.so.4
  255. libxcb-image.so.0
  256. libxcb-keysyms.so.1
  257. libxcb-randr.so.0
  258. libxcb-render-util.so.0
  259. libxcb-render.so.0
  260. libxcb-shape.so.0
  261. libxcb-shm.so.0
  262. libxcb-sync.so.1
  263. libxcb-xfixes.so.0
  264. libxcb-xinerama.so.0
  265. libxcb-xkb.so.1
  266. libxcb.so.1
  267. libxkbcommon-x11.so.0
  268. libxkbcommon.so.0
  269. )
  270. set(UNRESOLVED_QT_DEPS "")
  271. foreach (REQUIREMENT ${BUNDLED_QT_REQUIREMENTS})
  272. find_library(BUNDLED_QT_${REQUIREMENT} ${REQUIREMENT})
  273. if ("${BUNDLED_QT_${REQUIREMENT}}" STREQUAL "BUNDLED_QT_${REQUIREMENT}-NOTFOUND")
  274. set(UNRESOLVED_QT_DEPS ${UNRESOLVED_QT_DEPS} ${REQUIREMENT})
  275. endif()
  276. unset(BUNDLED_QT_${REQUIREMENT})
  277. endforeach()
  278. unset(BUNDLED_QT_REQUIREMENTS)
  279. if (NOT "${UNRESOLVED_QT_DEPS}" STREQUAL "")
  280. message(FATAL_ERROR "Bundled Qt package missing required dependencies: ${UNRESOLVED_QT_DEPS}")
  281. endif()
  282. set(YUZU_USE_BUNDLED_QT ON CACHE BOOL "Download bundled Qt" FORCE)
  283. endif()
  284. if (YUZU_USE_BUNDLED_QT)
  285. # Binary package currently does not support Qt webengine, so make sure it's disabled
  286. set(YUZU_USE_QT_WEB_ENGINE OFF CACHE BOOL "Use Qt Webengine" FORCE)
  287. endif()
  288. endif()
  289. set(YUZU_QT_NO_CMAKE_SYSTEM_PATH)
  290. # Workaround for an issue where conan tries to build Qt from scratch instead of download prebuilt binaries
  291. set(QT_PREFIX_HINT)
  292. if(YUZU_USE_BUNDLED_QT)
  293. if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64)
  294. set(QT_BUILD qt-5.15.2-msvc2019_64)
  295. elseif ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") AND NOT MINGW AND ARCHITECTURE_x86_64)
  296. set(QT_BUILD qt5_5_15_2)
  297. else()
  298. message(FATAL_ERROR "No bundled Qt binaries for your toolchain. Disable YUZU_USE_BUNDLED_QT and provide your own.")
  299. endif()
  300. if (DEFINED QT_BUILD)
  301. download_bundled_external("qt/" ${QT_BUILD} QT_PREFIX)
  302. endif()
  303. set(QT_PREFIX_HINT HINTS "${QT_PREFIX}")
  304. set(YUZU_QT_NO_CMAKE_SYSTEM_PATH "NO_CMAKE_SYSTEM_PATH")
  305. endif()
  306. if ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") AND YUZU_USE_BUNDLED_QT)
  307. find_package(Qt5 ${QT_VERSION} REQUIRED COMPONENTS Widgets Concurrent DBus ${QT_PREFIX_HINT} ${YUZU_QT_NO_CMAKE_SYSTEM_PATH})
  308. else()
  309. find_package(Qt5 ${QT_VERSION} REQUIRED COMPONENTS Widgets Concurrent ${QT_PREFIX_HINT} ${YUZU_QT_NO_CMAKE_SYSTEM_PATH})
  310. endif()
  311. if (YUZU_USE_QT_WEB_ENGINE)
  312. find_package(Qt5 COMPONENTS WebEngineCore WebEngineWidgets)
  313. endif()
  314. if (ENABLE_QT_TRANSLATION)
  315. find_package(Qt5 REQUIRED COMPONENTS LinguistTools ${QT_PREFIX_HINT})
  316. endif()
  317. endif()
  318. # find SDL2 exports a bunch of variables that are needed, so its easier to do this outside of the yuzu_find_package
  319. if (ENABLE_SDL2)
  320. if (YUZU_USE_BUNDLED_SDL2)
  321. # Detect toolchain and platform
  322. if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64)
  323. set(SDL2_VER "SDL2-2.0.18")
  324. else()
  325. message(FATAL_ERROR "No bundled SDL2 binaries for your toolchain. Disable YUZU_USE_BUNDLED_SDL2 and provide your own.")
  326. endif()
  327. if (DEFINED SDL2_VER)
  328. download_bundled_external("sdl2/" ${SDL2_VER} SDL2_PREFIX)
  329. endif()
  330. set(SDL2_FOUND YES)
  331. set(SDL2_INCLUDE_DIR "${SDL2_PREFIX}/include" CACHE PATH "Path to SDL2 headers")
  332. set(SDL2_LIBRARY "${SDL2_PREFIX}/lib/x64/SDL2.lib" CACHE PATH "Path to SDL2 library")
  333. set(SDL2_DLL_DIR "${SDL2_PREFIX}/lib/x64/" CACHE PATH "Path to SDL2.dll")
  334. add_library(SDL2 INTERFACE)
  335. target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARY}")
  336. target_include_directories(SDL2 INTERFACE "${SDL2_INCLUDE_DIR}")
  337. elseif (YUZU_USE_EXTERNAL_SDL2)
  338. message(STATUS "Using SDL2 from externals.")
  339. else()
  340. find_package(SDL2 2.0.18 REQUIRED)
  341. # Some installations don't set SDL2_LIBRARIES
  342. if("${SDL2_LIBRARIES}" STREQUAL "")
  343. message(WARNING "SDL2_LIBRARIES wasn't set, manually setting to SDL2::SDL2")
  344. set(SDL2_LIBRARIES "SDL2::SDL2")
  345. endif()
  346. include_directories(SYSTEM ${SDL2_INCLUDE_DIRS})
  347. add_library(SDL2 INTERFACE)
  348. target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARIES}")
  349. endif()
  350. endif()
  351. # Install any missing dependencies with conan install
  352. if (CONAN_REQUIRED_LIBS)
  353. message(STATUS "Packages ${CONAN_REQUIRED_LIBS} not found!")
  354. # Use Conan to fetch the libraries that aren't found
  355. # Download conan.cmake automatically, you can also just copy the conan.cmake file
  356. if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
  357. message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
  358. file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/release/0.18/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
  359. endif()
  360. include(${CMAKE_BINARY_DIR}/conan.cmake)
  361. conan_check(VERSION 1.45.0 REQUIRED)
  362. # Manually add iconv to fix a dep conflict between qt and sdl2
  363. # We don't need to add it through find_package or anything since the other two can find it just fine
  364. if ("${CONAN_REQUIRED_LIBS}" MATCHES "qt" AND "${CONAN_REQUIRED_LIBS}" MATCHES "sdl")
  365. list(APPEND CONAN_REQUIRED_LIBS "libiconv/1.16")
  366. endif()
  367. if (IS_MULTI_CONFIG)
  368. conan_cmake_run(REQUIRES ${CONAN_REQUIRED_LIBS}
  369. OPTIONS ${CONAN_LIB_OPTIONS}
  370. BUILD missing
  371. CONFIGURATION_TYPES "Release;Debug"
  372. GENERATORS cmake_multi cmake_find_package_multi)
  373. include(${CMAKE_BINARY_DIR}/conanbuildinfo_multi.cmake)
  374. else()
  375. conan_cmake_run(REQUIRES ${CONAN_REQUIRED_LIBS}
  376. OPTIONS ${CONAN_LIB_OPTIONS}
  377. BUILD missing
  378. GENERATORS cmake cmake_find_package_multi)
  379. include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
  380. endif()
  381. list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}")
  382. list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
  383. conan_basic_setup()
  384. set(YUZU_CONAN_INSTALLED TRUE CACHE BOOL "If true, the following builds will add conan to the lib search path" FORCE)
  385. # Now that we've installed what we are missing, try to locate them again,
  386. # this time with required, so we bail if its not found.
  387. yuzu_find_packages(FORCE_REQUIRED)
  388. if (NOT Boost_FOUND)
  389. find_package(Boost 1.73.0 REQUIRED COMPONENTS context headers)
  390. set(Boost_LIBRARIES Boost::boost)
  391. # Conditionally add Boost::context only if the active version of the Conan Boost package provides it
  392. # The old version is missing Boost::context, so we want to avoid adding in that case
  393. # The new version requires adding Boost::context to prevent linking issues
  394. if (TARGET Boost::context)
  395. list(APPEND Boost_LIBRARIES Boost::context)
  396. endif()
  397. endif()
  398. # Due to issues with variable scopes in functions, we need to also find_package(qt5) outside of the function
  399. if(ENABLE_QT)
  400. list(APPEND CMAKE_MODULE_PATH "${CONAN_QT_ROOT_RELEASE}")
  401. list(APPEND CMAKE_PREFIX_PATH "${CONAN_QT_ROOT_RELEASE}")
  402. find_package(Qt5 5.15 REQUIRED COMPONENTS Widgets)
  403. if (YUZU_USE_QT_WEB_ENGINE)
  404. find_package(Qt5 REQUIRED COMPONENTS WebEngineCore WebEngineWidgets)
  405. endif()
  406. endif()
  407. endif()
  408. # Reexport some targets that are named differently when using the upstream CmakeConfig vs the generated Conan config
  409. # In order to ALIAS targets to a new name, they first need to be IMPORTED_GLOBAL
  410. # Dynarmic checks for target `boost` and so we want to make sure it can find it through our system instead of using their external
  411. if (TARGET Boost::Boost)
  412. set_target_properties(Boost::Boost PROPERTIES IMPORTED_GLOBAL TRUE)
  413. add_library(Boost::boost ALIAS Boost::Boost)
  414. add_library(boost ALIAS Boost::Boost)
  415. elseif (TARGET Boost::boost)
  416. set_target_properties(Boost::boost PROPERTIES IMPORTED_GLOBAL TRUE)
  417. add_library(boost ALIAS Boost::boost)
  418. endif()
  419. # Ensure libusb is properly configured (based on dolphin libusb include)
  420. if(NOT APPLE AND NOT YUZU_USE_BUNDLED_LIBUSB)
  421. include(FindPkgConfig)
  422. if (PKG_CONFIG_FOUND AND NOT CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD")
  423. pkg_check_modules(LIBUSB QUIET libusb-1.0>=1.0.24)
  424. else()
  425. find_package(LibUSB)
  426. endif()
  427. if (LIBUSB_FOUND)
  428. add_library(usb INTERFACE)
  429. target_include_directories(usb INTERFACE "${LIBUSB_INCLUDE_DIRS}")
  430. target_link_libraries(usb INTERFACE "${LIBUSB_LIBRARIES}")
  431. else()
  432. message(WARNING "libusb not found, falling back to externals")
  433. set(YUZU_USE_BUNDLED_LIBUSB ON)
  434. endif()
  435. endif()
  436. # List of all FFmpeg components required
  437. set(FFmpeg_COMPONENTS
  438. avcodec
  439. avutil
  440. swscale)
  441. if (UNIX AND NOT APPLE)
  442. Include(FindPkgConfig REQUIRED)
  443. pkg_check_modules(LIBVA libva)
  444. endif()
  445. if (NOT YUZU_USE_BUNDLED_FFMPEG)
  446. # Use system installed FFmpeg
  447. find_package(FFmpeg 4.3 QUIET COMPONENTS ${FFmpeg_COMPONENTS})
  448. if (FFmpeg_FOUND)
  449. # Overwrite aggregate defines from FFmpeg module to avoid over-linking libraries.
  450. # Prevents shipping too many libraries with the AppImage.
  451. set(FFmpeg_LIBRARIES "")
  452. set(FFmpeg_INCLUDE_DIR "")
  453. foreach(COMPONENT ${FFmpeg_COMPONENTS})
  454. set(FFmpeg_LIBRARIES ${FFmpeg_LIBRARIES} ${FFmpeg_LIBRARY_${COMPONENT}} CACHE PATH "Paths to FFmpeg libraries" FORCE)
  455. set(FFmpeg_INCLUDE_DIR ${FFmpeg_INCLUDE_DIR} ${FFmpeg_INCLUDE_${COMPONENT}} CACHE PATH "Path to FFmpeg headers" FORCE)
  456. endforeach()
  457. else()
  458. message(WARNING "FFmpeg not found or too old, falling back to externals")
  459. set(YUZU_USE_BUNDLED_FFMPEG ON)
  460. endif()
  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. # WSAPoll and SHGetKnownFolderPath (AppData/Roaming) didn't exist before WinNT 6.x (Vista)
  473. add_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600)
  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. elseif (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU|SunOS)$")
  480. set(PLATFORM_LIBRARIES rt)
  481. endif()
  482. # Setup a custom clang-format target (if clang-format can be found) that will run
  483. # against all the src files. This should be used before making a pull request.
  484. # =======================================================================
  485. set(CLANG_FORMAT_POSTFIX "-12")
  486. find_program(CLANG_FORMAT
  487. NAMES clang-format${CLANG_FORMAT_POSTFIX}
  488. clang-format
  489. PATHS ${PROJECT_BINARY_DIR}/externals)
  490. # if find_program doesn't find it, try to download from externals
  491. if (NOT CLANG_FORMAT)
  492. if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
  493. message(STATUS "Clang format not found! Downloading...")
  494. set(CLANG_FORMAT "${PROJECT_BINARY_DIR}/externals/clang-format${CLANG_FORMAT_POSTFIX}.exe")
  495. file(DOWNLOAD
  496. https://github.com/yuzu-emu/ext-windows-bin/raw/master/clang-format${CLANG_FORMAT_POSTFIX}.exe
  497. "${CLANG_FORMAT}" SHOW_PROGRESS
  498. STATUS DOWNLOAD_SUCCESS)
  499. if (NOT DOWNLOAD_SUCCESS EQUAL 0)
  500. message(WARNING "Could not download clang format! Disabling the clang format target")
  501. file(REMOVE ${CLANG_FORMAT})
  502. unset(CLANG_FORMAT)
  503. endif()
  504. else()
  505. message(WARNING "Clang format not found! Disabling the clang format target")
  506. endif()
  507. endif()
  508. if (CLANG_FORMAT)
  509. set(SRCS ${PROJECT_SOURCE_DIR}/src)
  510. set(CCOMMENT "Running clang format against all the .h and .cpp files in src/")
  511. if (WIN32)
  512. add_custom_target(clang-format
  513. COMMAND powershell.exe -Command "Get-ChildItem '${SRCS}/*' -Include *.cpp,*.h -Recurse | Foreach {&'${CLANG_FORMAT}' -i $_.fullname}"
  514. COMMENT ${CCOMMENT})
  515. elseif(MINGW)
  516. add_custom_target(clang-format
  517. COMMAND find `cygpath -u ${SRCS}` -iname *.h -o -iname *.cpp | xargs `cygpath -u ${CLANG_FORMAT}` -i
  518. COMMENT ${CCOMMENT})
  519. else()
  520. add_custom_target(clang-format
  521. COMMAND find ${SRCS} -iname *.h -o -iname *.cpp | xargs ${CLANG_FORMAT} -i
  522. COMMENT ${CCOMMENT})
  523. endif()
  524. unset(SRCS)
  525. unset(CCOMMENT)
  526. endif()
  527. # Include source code
  528. # ===================
  529. # This function should be passed a list of all files in a target. It will automatically generate
  530. # file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
  531. # one in the filesystem.
  532. function(create_target_directory_groups target_name)
  533. # Place any files that aren't in the source list in a separate group so that they don't get in
  534. # the way.
  535. source_group("Other Files" REGULAR_EXPRESSION ".")
  536. get_target_property(target_sources "${target_name}" SOURCES)
  537. foreach(file_name IN LISTS target_sources)
  538. get_filename_component(dir_name "${file_name}" PATH)
  539. # Group names use '\' as a separator even though the entire rest of CMake uses '/'...
  540. string(REPLACE "/" "\\" group_name "${dir_name}")
  541. source_group("${group_name}" FILES "${file_name}")
  542. endforeach()
  543. endfunction()
  544. # Prevent boost from linking against libs when building
  545. add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY
  546. -DBOOST_SYSTEM_NO_LIB
  547. -DBOOST_DATE_TIME_NO_LIB
  548. -DBOOST_REGEX_NO_LIB
  549. )
  550. # Adjustments for MSVC + Ninja
  551. if (MSVC AND CMAKE_GENERATOR STREQUAL "Ninja")
  552. add_compile_options(
  553. /wd4711 # function 'function' selected for automatic inline expansion
  554. /wd4464 # relative include path contains '..'
  555. /wd4820 # 'identifier1': '4' bytes padding added after data member 'identifier2'
  556. )
  557. endif()
  558. enable_testing()
  559. add_subdirectory(externals)
  560. add_subdirectory(src)
  561. # Set yuzu project or yuzu-cmd project as default StartUp Project in Visual Studio depending on whether QT is enabled or not
  562. if(ENABLE_QT)
  563. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT yuzu)
  564. else()
  565. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT yuzu-cmd)
  566. endif()
  567. # Installation instructions
  568. # =========================
  569. # Install freedesktop.org metadata files, following those specifications:
  570. # https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
  571. # https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
  572. # https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
  573. # https://www.freedesktop.org/software/appstream/docs/
  574. if(ENABLE_QT AND UNIX AND NOT APPLE)
  575. install(FILES "dist/org.yuzu_emu.yuzu.desktop"
  576. DESTINATION "share/applications")
  577. install(FILES "dist/yuzu.svg"
  578. DESTINATION "share/icons/hicolor/scalable/apps"
  579. RENAME "org.yuzu_emu.yuzu.svg")
  580. install(FILES "dist/org.yuzu_emu.yuzu.xml"
  581. DESTINATION "share/mime/packages")
  582. install(FILES "dist/org.yuzu_emu.yuzu.metainfo.xml"
  583. DESTINATION "share/metainfo")
  584. endif()