CMakeLists.txt 32 KB

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