CMakeLists.txt 23 KB

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