CMakeLists.txt 26 KB

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