CMakeLists.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. cmake_minimum_required(VERSION 3.15)
  2. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
  3. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules")
  4. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/find-modules")
  5. include(DownloadExternals)
  6. include(CMakeDependentOption)
  7. project(yuzu)
  8. # Set bundled sdl2/qt as dependent options.
  9. # OFF by default, but if ENABLE_SDL2 and MSVC are true then ON
  10. option(ENABLE_SDL2 "Enable the SDL2 frontend" ON)
  11. CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" ON "ENABLE_SDL2;MSVC" OFF)
  12. # On Linux system SDL2 is likely to be lacking HIDAPI support which have drawbacks but is needed for SDL motion
  13. CMAKE_DEPENDENT_OPTION(YUZU_USE_EXTERNAL_SDL2 "Compile external SDL2" ON "ENABLE_SDL2;NOT MSVC" OFF)
  14. option(ENABLE_QT "Enable the Qt frontend" ON)
  15. option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF)
  16. CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" "${MSVC}" "ENABLE_QT" OFF)
  17. option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON)
  18. option(YUZU_USE_BUNDLED_LIBUSB "Compile bundled libusb" OFF)
  19. option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" "${WIN32}")
  20. option(YUZU_USE_QT_WEB_ENGINE "Use QtWebEngine for web applet implementation" OFF)
  21. option(ENABLE_CUBEB "Enables the cubeb audio backend" ON)
  22. option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF)
  23. option(YUZU_USE_BUNDLED_OPUS "Compile bundled opus" ON)
  24. option(YUZU_TESTS "Compile tests" ON)
  25. option(YUZU_USE_BUNDLED_VCPKG "Use vcpkg for yuzu dependencies" OFF)
  26. if (YUZU_USE_BUNDLED_VCPKG)
  27. include(${CMAKE_SOURCE_DIR}/externals/vcpkg/scripts/buildsystems/vcpkg.cmake)
  28. elseif(NOT "$ENV{VCPKG_TOOLCHAIN_FILE}" STREQUAL "")
  29. # Disable manifest mode (use vcpkg classic mode) when using a custom vcpkg installation
  30. option(VCPKG_MANIFEST_MODE "")
  31. include("$ENV{VCPKG_TOOLCHAIN_FILE}")
  32. endif()
  33. # Default to a Release build
  34. get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  35. if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
  36. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
  37. message(STATUS "Defaulting to a Release build")
  38. endif()
  39. if(EXISTS ${PROJECT_SOURCE_DIR}/hooks/pre-commit AND NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/hooks/pre-commit)
  40. if (EXISTS ${PROJECT_SOURCE_DIR}/.git/)
  41. message(STATUS "Copying pre-commit hook")
  42. file(COPY hooks/pre-commit DESTINATION ${PROJECT_SOURCE_DIR}/.git/hooks)
  43. endif()
  44. endif()
  45. # Sanity check : Check that all submodules are present
  46. # =======================================================================
  47. function(check_submodules_present)
  48. file(READ "${PROJECT_SOURCE_DIR}/.gitmodules" gitmodules)
  49. string(REGEX MATCHALL "path *= *[^ \t\r\n]*" gitmodules ${gitmodules})
  50. foreach(module ${gitmodules})
  51. string(REGEX REPLACE "path *= *" "" module ${module})
  52. if (NOT EXISTS "${PROJECT_SOURCE_DIR}/${module}/.git")
  53. message(FATAL_ERROR "Git submodule ${module} not found. "
  54. "Please run: \ngit submodule update --init --recursive")
  55. endif()
  56. endforeach()
  57. endfunction()
  58. if(EXISTS ${PROJECT_SOURCE_DIR}/.gitmodules)
  59. check_submodules_present()
  60. endif()
  61. configure_file(${PROJECT_SOURCE_DIR}/dist/compatibility_list/compatibility_list.qrc
  62. ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.qrc
  63. COPYONLY)
  64. if (ENABLE_COMPATIBILITY_LIST_DOWNLOAD AND NOT EXISTS ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json)
  65. message(STATUS "Downloading compatibility list for yuzu...")
  66. file(DOWNLOAD
  67. https://api.yuzu-emu.org/gamedb/
  68. "${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json" SHOW_PROGRESS)
  69. endif()
  70. if (NOT EXISTS ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json)
  71. file(WRITE ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json "")
  72. endif()
  73. # Detect current compilation architecture and create standard definitions
  74. # =======================================================================
  75. include(CheckSymbolExists)
  76. function(detect_architecture symbol arch)
  77. if (NOT DEFINED ARCHITECTURE)
  78. set(CMAKE_REQUIRED_QUIET 1)
  79. check_symbol_exists("${symbol}" "" ARCHITECTURE_${arch})
  80. unset(CMAKE_REQUIRED_QUIET)
  81. # The output variable needs to be unique across invocations otherwise
  82. # CMake's crazy scope rules will keep it defined
  83. if (ARCHITECTURE_${arch})
  84. set(ARCHITECTURE "${arch}" PARENT_SCOPE)
  85. set(ARCHITECTURE_${arch} 1 PARENT_SCOPE)
  86. add_definitions(-DARCHITECTURE_${arch}=1)
  87. endif()
  88. endif()
  89. endfunction()
  90. if (NOT ENABLE_GENERIC)
  91. if (MSVC)
  92. detect_architecture("_M_AMD64" x86_64)
  93. detect_architecture("_M_IX86" x86)
  94. detect_architecture("_M_ARM" ARM)
  95. detect_architecture("_M_ARM64" ARM64)
  96. else()
  97. detect_architecture("__x86_64__" x86_64)
  98. detect_architecture("__i386__" x86)
  99. detect_architecture("__arm__" ARM)
  100. detect_architecture("__aarch64__" ARM64)
  101. endif()
  102. endif()
  103. if (NOT DEFINED ARCHITECTURE)
  104. set(ARCHITECTURE "GENERIC")
  105. set(ARCHITECTURE_GENERIC 1)
  106. add_definitions(-DARCHITECTURE_GENERIC=1)
  107. endif()
  108. message(STATUS "Target architecture: ${ARCHITECTURE}")
  109. if (UNIX)
  110. add_definitions(-DYUZU_UNIX=1)
  111. endif()
  112. # Configure C++ standard
  113. # ===========================
  114. # boost asio's concept usage doesn't play nicely with some compilers yet.
  115. add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS)
  116. if (MSVC)
  117. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/std:c++latest>)
  118. # boost still makes use of deprecated result_of.
  119. add_definitions(-D_HAS_DEPRECATED_RESULT_OF)
  120. else()
  121. set(CMAKE_CXX_STANDARD 20)
  122. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  123. endif()
  124. # Output binaries to bin/
  125. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
  126. # System imported libraries
  127. # =======================================================================
  128. find_package(fmt 8.0.1 REQUIRED CONFIG)
  129. find_package(lz4 1.8 REQUIRED)
  130. find_package(nlohmann_json 3.8 REQUIRED CONFIG)
  131. find_package(ZLIB 1.2 REQUIRED)
  132. # Search for config-only package first (for vcpkg), then try non-config
  133. find_package(zstd 1.5 CONFIG)
  134. if (NOT zstd_FOUND)
  135. find_package(zstd 1.5 REQUIRED)
  136. endif()
  137. if (YUZU_TESTS)
  138. find_package(Catch2 2.13.7 REQUIRED CONFIG)
  139. endif()
  140. find_package(Boost 1.73.0 COMPONENTS context)
  141. if (Boost_FOUND)
  142. set(Boost_LIBRARIES Boost::boost)
  143. # Conditionally add Boost::context only if the found Boost package provides it
  144. # The old version is missing Boost::context, so we want to avoid adding in that case
  145. # The new version requires adding Boost::context to prevent linking issues
  146. if (TARGET Boost::context)
  147. list(APPEND Boost_LIBRARIES Boost::context)
  148. endif()
  149. else()
  150. message(FATAL_ERROR "Boost 1.73.0 or newer not found")
  151. endif()
  152. # boost:asio has functions that require AcceptEx et al
  153. if (MINGW)
  154. find_library(MSWSOCK_LIBRARY mswsock REQUIRED)
  155. endif()
  156. # Qt5 requires that we find components, so it doesn't fit our pretty little find package function
  157. if(ENABLE_QT)
  158. set(QT_VERSION 5.15)
  159. # Check for system Qt on Linux, fallback to bundled Qt
  160. if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  161. if (NOT YUZU_USE_BUNDLED_QT)
  162. find_package(Qt5 ${QT_VERSION} COMPONENTS Widgets DBus Multimedia)
  163. endif()
  164. if (NOT Qt5_FOUND OR YUZU_USE_BUNDLED_QT)
  165. # Check for dependencies, then enable bundled Qt download
  166. # Check that the system GLIBCXX version is compatible
  167. find_program(OBJDUMP objdump)
  168. if ("${OBJDUMP}" STREQUAL "OBJDUMP-NOTFOUND")
  169. message(FATAL_ERROR "Required program `objdump` not found.")
  170. endif()
  171. find_library(LIBSTDCXX libstdc++.so.6)
  172. execute_process(
  173. COMMAND
  174. ${OBJDUMP} -T ${LIBSTDCXX}
  175. COMMAND
  176. grep GLIBCXX_3.4.28
  177. COMMAND
  178. sed "s/[0-9a-f]*.* //"
  179. COMMAND
  180. sed "s/ .*//"
  181. COMMAND
  182. sort -u
  183. OUTPUT_VARIABLE
  184. GLIBCXX_MET
  185. )
  186. if (NOT GLIBCXX_MET)
  187. message(FATAL_ERROR "Qt too old or not found, and bundled Qt package is not \
  188. compatible with this system. Either install Qt ${QT_VERSION}, or provide the path \
  189. to Qt by setting the variable Qt5_ROOT.")
  190. endif()
  191. # Check for headers
  192. Include(FindPkgConfig REQUIRED)
  193. pkg_check_modules(QT_DEP_GLU QUIET glu>=9.0.0)
  194. if (NOT QT_DEP_GLU_FOUND)
  195. message(FATAL_ERROR "Qt bundled pacakge dependency `glu` not found. \
  196. Perhaps `libglu1-mesa-dev` needs to be installed?")
  197. endif()
  198. pkg_check_modules(QT_DEP_MESA QUIET dri>=20.0.8)
  199. if (NOT QT_DEP_MESA_FOUND)
  200. message(FATAL_ERROR "Qt bundled pacakge dependency `dri` not found. \
  201. Perhaps `mesa-common-dev` needs to be installed?")
  202. endif()
  203. # Check for X libraries
  204. set(BUNDLED_QT_REQUIREMENTS
  205. libxcb-icccm.so.4
  206. libxcb-image.so.0
  207. libxcb-keysyms.so.1
  208. libxcb-randr.so.0
  209. libxcb-render-util.so.0
  210. libxcb-render.so.0
  211. libxcb-shape.so.0
  212. libxcb-shm.so.0
  213. libxcb-sync.so.1
  214. libxcb-xfixes.so.0
  215. libxcb-xinerama.so.0
  216. libxcb-xkb.so.1
  217. libxcb.so.1
  218. libxkbcommon-x11.so.0
  219. libxkbcommon.so.0
  220. )
  221. set(UNRESOLVED_QT_DEPS "")
  222. foreach (REQUIREMENT ${BUNDLED_QT_REQUIREMENTS})
  223. find_library(BUNDLED_QT_${REQUIREMENT} ${REQUIREMENT})
  224. if ("${BUNDLED_QT_${REQUIREMENT}}" STREQUAL "BUNDLED_QT_${REQUIREMENT}-NOTFOUND")
  225. set(UNRESOLVED_QT_DEPS ${UNRESOLVED_QT_DEPS} ${REQUIREMENT})
  226. endif()
  227. unset(BUNDLED_QT_${REQUIREMENT})
  228. endforeach()
  229. unset(BUNDLED_QT_REQUIREMENTS)
  230. if (NOT "${UNRESOLVED_QT_DEPS}" STREQUAL "")
  231. message(FATAL_ERROR "Bundled Qt package missing required dependencies: ${UNRESOLVED_QT_DEPS}")
  232. endif()
  233. set(YUZU_USE_BUNDLED_QT ON CACHE BOOL "Download bundled Qt" FORCE)
  234. endif()
  235. if (YUZU_USE_BUNDLED_QT)
  236. # Binary package currently does not support Qt webengine, so make sure it's disabled
  237. set(YUZU_USE_QT_WEB_ENGINE OFF CACHE BOOL "Use Qt Webengine" FORCE)
  238. endif()
  239. endif()
  240. set(YUZU_QT_NO_CMAKE_SYSTEM_PATH)
  241. if(YUZU_USE_BUNDLED_QT)
  242. if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64)
  243. set(QT_BUILD qt-5.15.2-msvc2019_64)
  244. elseif ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") AND NOT MINGW AND ARCHITECTURE_x86_64)
  245. set(QT_BUILD qt5_5_15_2)
  246. else()
  247. message(FATAL_ERROR "No bundled Qt binaries for your toolchain. Disable YUZU_USE_BUNDLED_QT and provide your own.")
  248. endif()
  249. if (DEFINED QT_BUILD)
  250. download_bundled_external("qt/" ${QT_BUILD} QT_PREFIX)
  251. endif()
  252. set(QT_PREFIX_HINT HINTS "${QT_PREFIX}")
  253. set(YUZU_QT_NO_CMAKE_SYSTEM_PATH "NO_CMAKE_SYSTEM_PATH")
  254. endif()
  255. if ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") AND YUZU_USE_BUNDLED_QT)
  256. find_package(Qt5 ${QT_VERSION} REQUIRED COMPONENTS Widgets Concurrent Multimedia DBus ${QT_PREFIX_HINT} ${YUZU_QT_NO_CMAKE_SYSTEM_PATH})
  257. else()
  258. find_package(Qt5 ${QT_VERSION} REQUIRED COMPONENTS Widgets Concurrent Multimedia ${QT_PREFIX_HINT} ${YUZU_QT_NO_CMAKE_SYSTEM_PATH})
  259. endif()
  260. if (YUZU_USE_QT_WEB_ENGINE)
  261. find_package(Qt5 REQUIRED COMPONENTS WebEngineCore WebEngineWidgets)
  262. endif()
  263. if (ENABLE_QT_TRANSLATION)
  264. find_package(Qt5 REQUIRED COMPONENTS LinguistTools ${QT_PREFIX_HINT})
  265. endif()
  266. endif()
  267. # find SDL2 exports a bunch of variables that are needed, so its easier to do this outside of the yuzu_find_package
  268. if (ENABLE_SDL2)
  269. if (YUZU_USE_BUNDLED_SDL2)
  270. # Detect toolchain and platform
  271. if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64)
  272. set(SDL2_VER "SDL2-2.0.18")
  273. else()
  274. message(FATAL_ERROR "No bundled SDL2 binaries for your toolchain. Disable YUZU_USE_BUNDLED_SDL2 and provide your own.")
  275. endif()
  276. if (DEFINED SDL2_VER)
  277. download_bundled_external("sdl2/" ${SDL2_VER} SDL2_PREFIX)
  278. endif()
  279. set(SDL2_FOUND YES)
  280. set(SDL2_INCLUDE_DIR "${SDL2_PREFIX}/include" CACHE PATH "Path to SDL2 headers")
  281. set(SDL2_LIBRARY "${SDL2_PREFIX}/lib/x64/SDL2.lib" CACHE PATH "Path to SDL2 library")
  282. set(SDL2_DLL_DIR "${SDL2_PREFIX}/lib/x64/" CACHE PATH "Path to SDL2.dll")
  283. add_library(SDL2 INTERFACE)
  284. target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARY}")
  285. target_include_directories(SDL2 INTERFACE "${SDL2_INCLUDE_DIR}")
  286. elseif (YUZU_USE_EXTERNAL_SDL2)
  287. message(STATUS "Using SDL2 from externals.")
  288. else()
  289. find_package(SDL2 2.0.18 REQUIRED)
  290. # Some installations don't set SDL2_LIBRARIES
  291. if("${SDL2_LIBRARIES}" STREQUAL "")
  292. message(WARNING "SDL2_LIBRARIES wasn't set, manually setting to SDL2::SDL2")
  293. set(SDL2_LIBRARIES "SDL2::SDL2")
  294. endif()
  295. include_directories(SYSTEM ${SDL2_INCLUDE_DIRS})
  296. add_library(SDL2 INTERFACE)
  297. target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARIES}")
  298. endif()
  299. endif()
  300. # TODO(lat9nq): Determine what if any of this we still need
  301. #
  302. # Reexport some targets that are named differently when using the upstream CmakeConfig vs the generated Conan config
  303. # In order to ALIAS targets to a new name, they first need to be IMPORTED_GLOBAL
  304. # Dynarmic checks for target `boost` and so we want to make sure it can find it through our system instead of using their external
  305. if (TARGET Boost::Boost)
  306. set_target_properties(Boost::Boost PROPERTIES IMPORTED_GLOBAL TRUE)
  307. add_library(Boost::boost ALIAS Boost::Boost)
  308. add_library(boost ALIAS Boost::Boost)
  309. elseif (TARGET Boost::boost)
  310. set_target_properties(Boost::boost PROPERTIES IMPORTED_GLOBAL TRUE)
  311. add_library(boost ALIAS Boost::boost)
  312. endif()
  313. # Ensure libusb is properly configured (based on dolphin libusb include)
  314. if(NOT APPLE AND NOT YUZU_USE_BUNDLED_LIBUSB)
  315. include(FindPkgConfig)
  316. if (PKG_CONFIG_FOUND AND NOT CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD")
  317. pkg_check_modules(LIBUSB QUIET libusb-1.0>=1.0.24)
  318. else()
  319. find_package(LibUSB)
  320. endif()
  321. if (LIBUSB_FOUND)
  322. add_library(usb INTERFACE)
  323. target_include_directories(usb INTERFACE "${LIBUSB_INCLUDE_DIRS}")
  324. target_link_libraries(usb INTERFACE "${LIBUSB_LIBRARIES}")
  325. else()
  326. message(WARNING "libusb not found, falling back to externals")
  327. set(YUZU_USE_BUNDLED_LIBUSB ON)
  328. endif()
  329. endif()
  330. # List of all FFmpeg components required
  331. set(FFmpeg_COMPONENTS
  332. avcodec
  333. avutil
  334. swscale)
  335. if (UNIX AND NOT APPLE)
  336. Include(FindPkgConfig REQUIRED)
  337. pkg_check_modules(LIBVA libva)
  338. endif()
  339. if (NOT YUZU_USE_BUNDLED_FFMPEG)
  340. # Use system installed FFmpeg
  341. find_package(FFmpeg 4.3 QUIET 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 or too old, falling back to externals")
  353. set(YUZU_USE_BUNDLED_FFMPEG ON)
  354. endif()
  355. endif()
  356. # Prefer the -pthread flag on Linux.
  357. set(THREADS_PREFER_PTHREAD_FLAG ON)
  358. find_package(Threads REQUIRED)
  359. # Platform-specific library requirements
  360. # ======================================
  361. if (APPLE)
  362. # Umbrella framework for everything GUI-related
  363. find_library(COCOA_LIBRARY Cocoa)
  364. set(PLATFORM_LIBRARIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
  365. elseif (WIN32)
  366. # WSAPoll and SHGetKnownFolderPath (AppData/Roaming) didn't exist before WinNT 6.x (Vista)
  367. add_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600)
  368. set(PLATFORM_LIBRARIES winmm ws2_32 iphlpapi)
  369. if (MINGW)
  370. # PSAPI is the Process Status API
  371. set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} psapi imm32 version)
  372. endif()
  373. elseif (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU|SunOS)$")
  374. set(PLATFORM_LIBRARIES rt)
  375. endif()
  376. # Setup a custom clang-format target (if clang-format can be found) that will run
  377. # against all the src files. This should be used before making a pull request.
  378. # =======================================================================
  379. set(CLANG_FORMAT_POSTFIX "-12")
  380. find_program(CLANG_FORMAT
  381. NAMES clang-format${CLANG_FORMAT_POSTFIX}
  382. clang-format
  383. PATHS ${PROJECT_BINARY_DIR}/externals)
  384. # if find_program doesn't find it, try to download from externals
  385. if (NOT CLANG_FORMAT)
  386. if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
  387. message(STATUS "Clang format not found! Downloading...")
  388. set(CLANG_FORMAT "${PROJECT_BINARY_DIR}/externals/clang-format${CLANG_FORMAT_POSTFIX}.exe")
  389. file(DOWNLOAD
  390. https://github.com/yuzu-emu/ext-windows-bin/raw/master/clang-format${CLANG_FORMAT_POSTFIX}.exe
  391. "${CLANG_FORMAT}" SHOW_PROGRESS
  392. STATUS DOWNLOAD_SUCCESS)
  393. if (NOT DOWNLOAD_SUCCESS EQUAL 0)
  394. message(WARNING "Could not download clang format! Disabling the clang format target")
  395. file(REMOVE ${CLANG_FORMAT})
  396. unset(CLANG_FORMAT)
  397. endif()
  398. else()
  399. message(WARNING "Clang format not found! Disabling the clang format target")
  400. endif()
  401. endif()
  402. if (CLANG_FORMAT)
  403. set(SRCS ${PROJECT_SOURCE_DIR}/src)
  404. set(CCOMMENT "Running clang format against all the .h and .cpp files in src/")
  405. if (WIN32)
  406. add_custom_target(clang-format
  407. COMMAND powershell.exe -Command "Get-ChildItem '${SRCS}/*' -Include *.cpp,*.h -Recurse | Foreach {&'${CLANG_FORMAT}' -i $_.fullname}"
  408. COMMENT ${CCOMMENT})
  409. elseif(MINGW)
  410. add_custom_target(clang-format
  411. COMMAND find `cygpath -u ${SRCS}` -iname *.h -o -iname *.cpp | xargs `cygpath -u ${CLANG_FORMAT}` -i
  412. COMMENT ${CCOMMENT})
  413. else()
  414. add_custom_target(clang-format
  415. COMMAND find ${SRCS} -iname *.h -o -iname *.cpp | xargs ${CLANG_FORMAT} -i
  416. COMMENT ${CCOMMENT})
  417. endif()
  418. unset(SRCS)
  419. unset(CCOMMENT)
  420. endif()
  421. # Include source code
  422. # ===================
  423. # This function should be passed a list of all files in a target. It will automatically generate
  424. # file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
  425. # one in the filesystem.
  426. function(create_target_directory_groups target_name)
  427. # Place any files that aren't in the source list in a separate group so that they don't get in
  428. # the way.
  429. source_group("Other Files" REGULAR_EXPRESSION ".")
  430. get_target_property(target_sources "${target_name}" SOURCES)
  431. foreach(file_name IN LISTS target_sources)
  432. get_filename_component(dir_name "${file_name}" PATH)
  433. # Group names use '\' as a separator even though the entire rest of CMake uses '/'...
  434. string(REPLACE "/" "\\" group_name "${dir_name}")
  435. source_group("${group_name}" FILES "${file_name}")
  436. endforeach()
  437. endfunction()
  438. # Prevent boost from linking against libs when building
  439. add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY
  440. -DBOOST_SYSTEM_NO_LIB
  441. -DBOOST_DATE_TIME_NO_LIB
  442. -DBOOST_REGEX_NO_LIB
  443. )
  444. # Adjustments for MSVC + Ninja
  445. if (MSVC AND CMAKE_GENERATOR STREQUAL "Ninja")
  446. add_compile_options(
  447. /wd4711 # function 'function' selected for automatic inline expansion
  448. /wd4464 # relative include path contains '..'
  449. /wd4820 # 'identifier1': '4' bytes padding added after data member 'identifier2'
  450. )
  451. endif()
  452. enable_testing()
  453. add_subdirectory(externals)
  454. add_subdirectory(src)
  455. # Set yuzu project or yuzu-cmd project as default StartUp Project in Visual Studio depending on whether QT is enabled or not
  456. if(ENABLE_QT)
  457. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT yuzu)
  458. else()
  459. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT yuzu-cmd)
  460. endif()
  461. # Installation instructions
  462. # =========================
  463. # Install freedesktop.org metadata files, following those specifications:
  464. # https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
  465. # https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
  466. # https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
  467. # https://www.freedesktop.org/software/appstream/docs/
  468. if(ENABLE_QT AND UNIX AND NOT APPLE)
  469. install(FILES "dist/org.yuzu_emu.yuzu.desktop"
  470. DESTINATION "share/applications")
  471. install(FILES "dist/yuzu.svg"
  472. DESTINATION "share/icons/hicolor/scalable/apps"
  473. RENAME "org.yuzu_emu.yuzu.svg")
  474. install(FILES "dist/org.yuzu_emu.yuzu.xml"
  475. DESTINATION "share/mime/packages")
  476. install(FILES "dist/org.yuzu_emu.yuzu.metainfo.xml"
  477. DESTINATION "share/metainfo")
  478. endif()