CMakeLists.txt 24 KB

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