CMakeLists.txt 25 KB

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