CMakeLists.txt 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. ########################################
  2. # General setup
  3. #
  4. cmake_minimum_required(VERSION 3.13)
  5. cmake_policy(SET CMP0079 NEW) # let target_link_libraries() link to a target defined in a different directory
  6. cmake_policy(SET CMP0080 OLD) # allow using BundleUtilities at configure time
  7. if (POLICY CMP0099)
  8. cmake_policy(SET CMP0099 NEW) # Propagate INTERFACE_LINK_OPTIONS from private dependencies, used by MacOS framework builds of SDL
  9. endif()
  10. # Weird chicken-and-egg problem: We can't check the compiler before the project() call, but we have to set the policies before it.
  11. # So we do this in two steps: Set the policies if they exist, then error out afterwards if we end up being MSVC and they don't exist.
  12. if (POLICY CMP0117)
  13. cmake_policy(SET CMP0091 NEW) # MSVC runtime library flags are selected by an abstraction.
  14. cmake_policy(SET CMP0092 NEW) # MSVC warning flags are not in CMAKE_{C,CXX}_FLAGS by default.
  15. cmake_policy(SET CMP0117 NEW) # MSVC RTTI flag will not be added by default.
  16. endif()
  17. if (POLICY CMP0141)
  18. cmake_policy(SET CMP0141 NEW) # MSVC debug information format flags are selected by an abstraction.
  19. endif()
  20. # Minimum OS X version.
  21. # This is inserted into the Info.plist as well.
  22. set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15.0" CACHE STRING "")
  23. set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_CURRENT_SOURCE_DIR}/CMake/FlagsOverride.cmake")
  24. project(dolphin-emu)
  25. if (MSVC)
  26. if (POLICY CMP0117)
  27. # cmake is a weird language. You can't do if(not POLICY)
  28. else()
  29. message(FATAL_ERROR "Please update to CMake 3.20 or higher.")
  30. endif()
  31. set(CMAKE_C_STANDARD 99)
  32. set(CMAKE_CXX_STANDARD 23)
  33. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  34. endif()
  35. set(COMPILER ${CMAKE_CXX_COMPILER_ID})
  36. if (COMPILER STREQUAL "GNU")
  37. set(COMPILER "GCC") # perfer printing GCC instead of GNU
  38. endif()
  39. # Enforce minimum compiler versions that support the c++20 features we use
  40. set (GCC_min_version 11)
  41. set (Clang_min_version 14)
  42. set (AppleClang_min_version 14.0.3)
  43. set (min_xcode_version "14.0") # corresponding xcode version for AppleClang_min_version
  44. set (MSVC_min_version 14.32)
  45. set (min_vs_version "2022 17.2.3") # corresponding Visual Studio version for MSVC_min_version
  46. message(STATUS "Using ${COMPILER} ${CMAKE_CXX_COMPILER_VERSION}")
  47. if ("-" STREQUAL "${${COMPILER}_min_version}-")
  48. message(WARNING "Unknown compiler ${COMPILER}, assuming it is new enough")
  49. else()
  50. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${${COMPILER}_min_version})
  51. message(FATAL_ERROR "Requires GCC ${GCC_min_version}, Clang ${Clang_min_version},"
  52. " AppleClang ${AppleClang_min_version} (Xcode ${min_xcode_version}),"
  53. " or MSVC ${MSVC_min_version} (Visual Studio ${min_vs_version}) or higher")
  54. endif()
  55. endif()
  56. # Name of the Dolphin distributor. If you redistribute Dolphin builds (forks,
  57. # unofficial builds) please consider identifying your distribution with a
  58. # unique name here.
  59. set(DISTRIBUTOR "None" CACHE STRING "Name of the distributor.")
  60. set(DOLPHIN_DEFAULT_UPDATE_TRACK "" CACHE STRING "Name of the default update track. If empty, disables auto-update.")
  61. if(UNIX AND NOT APPLE AND NOT ANDROID)
  62. option(ENABLE_X11 "Enables X11 Support" ON)
  63. endif()
  64. if(NOT WIN32 AND NOT APPLE AND NOT HAIKU)
  65. option(ENABLE_EGL "Enables EGL OpenGL Interface" ON)
  66. endif()
  67. if(NOT ANDROID)
  68. option(ENABLE_CLI_TOOL "Enable dolphin-tool, a CLI-based utility for functions such as managing disc images" ON)
  69. endif()
  70. set(USE_SYSTEM_LIBS "AUTO" CACHE STRING "Use system libraries instead of bundled libraries. ON - Always use system and fail if unavailable, OFF - Always use bundled, AUTO - Use system if available, otherwise use bundled. Default is AUTO")
  71. if(APPROVED_VENDORED_DEPENDENCIES)
  72. message(WARNING "APPROVED_VENDORED_DEPENDENCIES is deprecated. Please migrate to setting USE_SYSTEM_LIBS to ON and setting USE_SYSTEM_<dependency> to either AUTO or OFF to allow bundled libs.")
  73. endif()
  74. option(USE_UPNP "Enables UPnP port mapping support" ON)
  75. option(ENABLE_NOGUI "Enable NoGUI frontend" ON)
  76. option(ENABLE_QT "Enable Qt (Default)" ON)
  77. option(ENABLE_LTO "Enables Link Time Optimization" OFF)
  78. option(ENABLE_GENERIC "Enables generic build that should run on any little-endian host" OFF)
  79. option(ENABLE_HEADLESS "Enables running Dolphin as a headless variant" OFF)
  80. option(ENABLE_ALSA "Enables ALSA sound backend" ON)
  81. option(ENABLE_PULSEAUDIO "Enables PulseAudio sound backend" ON)
  82. option(ENABLE_LLVM "Enables LLVM support, for disassembly" ON)
  83. option(ENABLE_TESTS "Enables building the unit tests" ON)
  84. option(ENABLE_VULKAN "Enables vulkan video backend" ON)
  85. option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence, show the current game on Discord" ON)
  86. option(USE_MGBA "Enables GBA controllers emulation using libmgba" ON)
  87. option(ENABLE_AUTOUPDATE "Enables support for automatic updates" ON)
  88. option(STEAM "Creates a build for Steam" OFF)
  89. option(USE_RETRO_ACHIEVEMENTS "Enables integration with retroachievements.org" ON)
  90. # Maintainers: if you consider blanket disabling this for your users, please
  91. # consider the following points:
  92. # * No data is being sent without explicit user approval (pop up box at first
  93. # launch).
  94. # * The Dolphin team relies on the data in order to understand the behavior
  95. # of our software in the wild.
  96. option(ENABLE_ANALYTICS "Enables opt-in Analytics collection" ON)
  97. option(ENCODE_FRAMEDUMPS "Encode framedumps in AVI format" ON)
  98. option(ENABLE_GPROF "Enable gprof profiling (must be using Debug build)" OFF)
  99. option(FASTLOG "Enable all logs" OFF)
  100. option(OPROFILING "Enable profiling" OFF)
  101. # TODO: Add DSPSpy
  102. option(DSPTOOL "Build dsptool" OFF)
  103. # Enable SDL by default on operating systems that aren't Android.
  104. if(NOT ANDROID)
  105. option(ENABLE_SDL "Enables SDL as a generic controller backend" ON)
  106. else()
  107. option(ENABLE_SDL "Enables SDL as a generic controller backend" OFF)
  108. endif()
  109. if(APPLE)
  110. option(MACOS_USE_DEFAULT_SEARCH_PATH "Don't prioritize system library paths" OFF)
  111. option(SKIP_POSTPROCESS_BUNDLE "Skip postprocessing bundle for redistributability" OFF)
  112. # Enable adhoc code signing by default (otherwise makefile builds on ARM will not work)
  113. option(MACOS_CODE_SIGNING "Enable codesigning" ON)
  114. option(USE_BUNDLED_MOLTENVK "Build MoltenVK from Externals with Dolphin-specific patches" ON)
  115. set(MACOS_CODE_SIGNING_IDENTITY "-" CACHE STRING "The identity used for codesigning.")
  116. set(MACOS_CODE_SIGNING_IDENTITY_UPDATER "-" CACHE STRING "The identity used for codesigning, for the updater.")
  117. endif()
  118. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  119. option(ENABLE_VTUNE "Enable Intel VTune integration for JIT code." OFF)
  120. if(NOT ANDROID)
  121. option(ENABLE_EVDEV "Enables the evdev controller backend" ON)
  122. endif()
  123. endif()
  124. if(UNIX)
  125. # Builds a relocatable binary on Linux.
  126. # The Sys folder will need to be copied to the Binaries folder.
  127. option(LINUX_LOCAL_DEV "Enable relocatable binary" OFF)
  128. endif()
  129. list(APPEND CMAKE_MODULE_PATH
  130. ${CMAKE_CURRENT_SOURCE_DIR}/CMake
  131. )
  132. # Support functions
  133. include(CheckAndAddFlag)
  134. include(CheckCCompilerFlag)
  135. include(DolphinCompileDefinitions)
  136. include(DolphinDisableWarningsMSVC)
  137. include(DolphinLibraryTools)
  138. include(GNUInstallDirs)
  139. include(RemoveCompileFlag)
  140. # Enable folders for IDE
  141. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  142. # Set up paths
  143. set(datadir ${CMAKE_INSTALL_FULL_DATADIR}/dolphin-emu CACHE PATH "datadir")
  144. add_definitions(-DDATA_DIR="${datadir}/")
  145. if(CMAKE_SYSROOT)
  146. # If we should use a sysroot, tell pkg-config to search for packages in there, not on the host
  147. set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")
  148. set(ENV{PKG_CONFIG_SYSROOT_DIR} "${CMAKE_SYSROOT}")
  149. endif()
  150. # Set where the binary files will be built. The program will not execute from
  151. # here. You must run "make install" to install these to the proper location
  152. # as defined above.
  153. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Binaries)
  154. if (WIN32)
  155. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Binary)
  156. if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
  157. string(APPEND CMAKE_RUNTIME_OUTPUT_DIRECTORY /x64)
  158. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  159. string(APPEND CMAKE_RUNTIME_OUTPUT_DIRECTORY /ARM64)
  160. endif()
  161. endif()
  162. # setup CCache
  163. include(CCache)
  164. # Architecture detection and arch specific settings
  165. message(STATUS "Detected architecture: ${CMAKE_SYSTEM_PROCESSOR}")
  166. # Detect 64bit or 32bit
  167. # CMake doesn't provide a simple way to determine 32bit or 64bit
  168. # If we ever support a architecture that is 64bit with 32bit pointers then this'll break
  169. # Of course the chances of that are slim(x32?) so who cares
  170. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  171. set(_ARCH_64 1)
  172. add_definitions(-D_ARCH_64=1)
  173. else()
  174. set(_ARCH_32 1)
  175. add_definitions(-D_ARCH_32=1)
  176. endif()
  177. if(ENABLE_GENERIC)
  178. message(STATUS "Warning! Building generic build!")
  179. set(_M_GENERIC 1)
  180. add_definitions(-D_M_GENERIC=1)
  181. elseif(_ARCH_64 AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
  182. set(_M_X86_64 1)
  183. add_definitions(-D_M_X86_64=1)
  184. check_and_add_flag(HAVE_SSE2 -msse2)
  185. elseif(_ARCH_64 AND CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
  186. set(_M_ARM_64 1)
  187. add_definitions(-D_M_ARM_64=1)
  188. # CRC instruction set is used in the CRC32 hash function
  189. check_and_add_flag(HAVE_ARCH_ARMV8 -march=armv8-a+crc)
  190. else()
  191. message(FATAL_ERROR "You're building on an unsupported platform: "
  192. "'${CMAKE_SYSTEM_PROCESSOR}' with ${CMAKE_SIZEOF_VOID_P}-byte pointers."
  193. " Enable generic build if you really want a JIT-less binary.")
  194. endif()
  195. if(CMAKE_GENERATOR MATCHES "Ninja")
  196. check_and_add_flag(DIAGNOSTICS_COLOR -fdiagnostics-color)
  197. elseif(CMAKE_GENERATOR MATCHES "Visual Studio")
  198. # Only MSBuild needs this, other generators will compile one file at a time
  199. add_compile_options("/MP")
  200. endif()
  201. if(MSVC)
  202. check_and_add_flag(EXCEPTIONS /EHsc)
  203. dolphin_compile_definitions(_DEBUG DEBUG_ONLY)
  204. # Disable RTTI
  205. add_compile_options(/GR-)
  206. # Set warning level 4 (the highest)
  207. add_compile_options(/W4)
  208. # Treat all warnings as errors
  209. add_compile_options(/WX)
  210. # Disable some warnings
  211. add_compile_options(
  212. /wd4201 # nonstandard extension used : nameless struct/union
  213. /wd4127 # conditional expression is constant
  214. /wd4100 # 'identifier' : unreferenced formal parameter
  215. /wd4200 # InputCommon fix temp.
  216. /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
  217. /wd4121 # 'symbol' : alignment of a member was sensitive to packing
  218. /wd4324 # Padding was added at the end of a structure because you specified a __declspec(align) value.
  219. /wd4714 # function 'function' marked as __forceinline not inlined
  220. /wd4351 # new behavior: elements of array 'array' will be default initialized
  221. # TODO: Enable this warning once possible
  222. /wd4245 # conversion from 'type1' to 'type2', signed/unsigned mismatch
  223. # Currently jits use some annoying code patterns which makes this common
  224. )
  225. # Additional warnings
  226. add_compile_options(
  227. /w44263 # Non-virtual member function hides base class virtual function
  228. /w44265 # Class has virtual functions, but destructor is not virtual
  229. /w44946 # Reinterpret cast between related types
  230. )
  231. # All files are encoded as UTF-8
  232. add_compile_options(/utf-8)
  233. # Ignore warnings in external headers
  234. add_compile_options(/external:anglebrackets)
  235. add_compile_options(/external:W0)
  236. add_compile_options(/external:templates-)
  237. # Request deterministic builds
  238. add_compile_options(/experimental:deterministic)
  239. add_link_options(/experimental:deterministic)
  240. # Enable function-level linking
  241. add_compile_options(/Gy)
  242. # Generate intrinsic functions
  243. add_compile_options(/Oi)
  244. # Enable buffer security check on Debug, disable otherwise
  245. add_compile_options($<IF:$<CONFIG:Debug>,/GS,/GS->)
  246. # Remove unreferenced inline functions/data to reduce link time and catch bugs
  247. # Note: In msbuild build, this gets set by msbuild by default
  248. add_compile_options(/Zc:inline)
  249. # Fix various other non-conformant behaviors
  250. add_compile_options(/Zc:__cplusplus,enumTypes,externConstexpr,preprocessor,templateScope,throwingNew)
  251. # Enforce strict volatile semantics as per ISO C++
  252. add_compile_options(/volatile:iso)
  253. # Use 'precise' floating point model
  254. add_compile_options(/fp:precise)
  255. string(APPEND CMAKE_EXE_LINKER_FLAGS " /NXCOMPAT")
  256. # Generate debug data
  257. string(APPEND CMAKE_EXE_LINKER_FLAGS " /DEBUG")
  258. # Eliminate dead code and data
  259. string(APPEND CMAKE_EXE_LINKER_FLAGS " /OPT:REF /OPT:ICF")
  260. else()
  261. add_definitions(-D_DEFAULT_SOURCE)
  262. # gcc uses some optimizations which might break stuff without this flag
  263. check_and_add_flag(NO_STRICT_ALIASING -fno-strict-aliasing)
  264. check_and_add_flag(NO_EXCEPTIONS -fno-exceptions)
  265. check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-hidden)
  266. check_and_add_flag(VISIBILITY_HIDDEN -fvisibility=hidden)
  267. check_and_add_flag(FOMIT_FRAME_POINTER -fomit-frame-pointer NO_DEBINFO_ONLY)
  268. dolphin_compile_definitions(_DEBUG DEBUG_ONLY)
  269. check_and_add_flag(GGDB -ggdb DEBUG_ONLY)
  270. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  271. # GNU ar: Create thin archive files.
  272. # Requires binutils-2.19 or later.
  273. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  274. set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  275. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  276. set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  277. endif()
  278. endif()
  279. if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
  280. if(NOT MACOS_USE_DEFAULT_SEARCH_PATH)
  281. # Hack up the path to prioritize the path to built-in OS libraries to
  282. # increase the chance of not depending on a bunch of copies of them
  283. # installed by MacPorts, Fink, Homebrew, etc, and ending up copying
  284. # them into the bundle. Since we optionally depend on libraries which
  285. # are not part of OS X (ffmpeg, etc.), however, don't remove the default
  286. # path entirely as was done in a previous version of this file. This is
  287. # still kinda evil, since it defeats the user's path settings...
  288. # See http://www.cmake.org/cmake/help/v3.0/command/find_program.html
  289. list(APPEND CMAKE_PREFIX_PATH "/usr")
  290. endif()
  291. # Prevents Xcode from overriding the -fno-strict-aliasing flag
  292. set(CMAKE_XCODE_ATTRIBUTE_GCC_STRICT_ALIASING NO)
  293. # Specify target CPUs.
  294. if(_ARCH_64 AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
  295. check_and_add_flag(HAVE_MSSSE3 -mssse3)
  296. check_and_add_flag(HAVE_ARCH_CORE2 -march=core2)
  297. endif()
  298. # Linker flags.
  299. # Drop unreachable code and data.
  300. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip,-dead_strip_dylibs")
  301. # Set FMT_EXCEPTIONS = 0, for consistency with -fno-exceptions earlier.
  302. # If we set only -fno-exceptions, fmt fails to compile when included from
  303. # Objective-C++ because fmt tries try to use throw because __EXCEPTIONS is defined.
  304. add_definitions(-DFMT_EXCEPTIONS=0)
  305. find_library(APPKIT_LIBRARY AppKit)
  306. find_library(APPSERV_LIBRARY ApplicationServices)
  307. find_library(CARBON_LIBRARY Carbon)
  308. find_library(COCOA_LIBRARY Cocoa)
  309. find_library(COREFOUNDATION_LIBRARY CoreFoundation)
  310. find_library(CORESERV_LIBRARY CoreServices)
  311. find_library(FORCEFEEDBACK_LIBRARY ForceFeedback)
  312. find_library(FOUNDATION_LIBRARY Foundation)
  313. find_library(IOB_LIBRARY IOBluetooth)
  314. find_library(IOK_LIBRARY IOKit)
  315. find_library(OPENGL_LIBRARY OpenGL)
  316. endif()
  317. if(ENABLE_LTO)
  318. if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
  319. add_compile_options(/GL)
  320. string(APPEND CMAKE_EXE_LINKER_FLAGS " /LTCG")
  321. else()
  322. check_and_add_flag(LTO -flto)
  323. if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
  324. set(CMAKE_AR gcc-ar)
  325. set(CMAKE_RANLIB gcc-ranlib)
  326. endif()
  327. endif()
  328. endif()
  329. if(UNIX)
  330. if(LINUX_LOCAL_DEV OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND STEAM))
  331. add_definitions(-DLINUX_LOCAL_DEV)
  332. endif()
  333. endif()
  334. # BSDs put packages in /usr/local instead of /usr, so we need to
  335. # force CMake to look in those directories by default, too.
  336. # All commands and submodule commands also need to see these
  337. # changes, so just setting them in the project scope via
  338. # include_directories and link_directories is not sufficient
  339. if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  340. set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr/local")
  341. set(CMAKE_REQUIRED_INCLUDES "/usr/local/include")
  342. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
  343. if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0)
  344. # Workaround: the llvm libc++ and versions of clang eariler than 14 have a bug with consteval
  345. # so we define FMT_CONSTEVAL to blank to just disable consteval in fmt
  346. add_definitions(-DFMT_CONSTEVAL=)
  347. endif()
  348. endif()
  349. # Dolphin requires threads.
  350. find_package(Threads)
  351. if(NOT CMAKE_BUILD_TYPE)
  352. set(CMAKE_BUILD_TYPE "Release" CACHE STRING
  353. "Build type (Release/Debug/RelWithDebInfo/MinSizeRel)" FORCE)
  354. endif()
  355. if(ENABLE_GPROF)
  356. check_and_add_flag(HAVE_PG -pg)
  357. if(NOT FLAG_C_HAVE_PG)
  358. message(FATAL_ERROR "Compiler option -pg is not supported")
  359. endif()
  360. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
  361. endif()
  362. if(FASTLOG)
  363. add_definitions(-DDEBUGFAST)
  364. endif()
  365. if(ENABLE_VTUNE)
  366. set(VTUNE_DIR "/opt/intel/vtune_amplifier")
  367. add_definitions(-DUSE_VTUNE)
  368. include_directories("${VTUNE_DIR}/include")
  369. set(VTUNE_LIBRARIES
  370. "${VTUNE_DIR}/lib64/libjitprofiling.a"
  371. "${VTUNE_DIR}/lib64/libittnotify.a"
  372. )
  373. endif()
  374. if(ANDROID)
  375. message(STATUS "Building for Android")
  376. if(NOT ENABLE_HEADLESS)
  377. add_definitions(-DANDROID)
  378. if(ENABLE_NOGUI)
  379. message(STATUS "Building Android app, disabling NoGUI frontend.")
  380. set(ENABLE_NOGUI 0)
  381. endif()
  382. else()
  383. # Lie to cmake a bit. We are cross compiling to Android
  384. # but not as a shared library. We want an executable.
  385. set(ANDROID 0)
  386. endif()
  387. set(USE_UPNP 0)
  388. set(ENABLE_QT 0)
  389. set(USE_DISCORD_PRESENCE 0)
  390. # We are cross compiling, search only the toolchain for libraries and includes
  391. SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  392. SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  393. SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  394. SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
  395. endif()
  396. if(ENABLE_HEADLESS)
  397. message(STATUS "Enabling Headless! Disabling GUI.")
  398. set(ENABLE_QT 0)
  399. set(USE_DISCORD_PRESENCE 0)
  400. endif()
  401. # Set file offset size to 64 bits. On modern Unixes, this is typically already the case. Exceptions:
  402. #
  403. # glibc may default to 32 bits. This can be configured by setting _FILE_OFFSET_BITS=64.
  404. #
  405. # bionic (Android) defaults to 32 bits for 32-bit ABIs. Here too we can use _FILE_OFFSET_BITS=64,
  406. # but only on API 25 and up. Since we're currently supporting older API levels and 32-bit Android
  407. # isn't a build configuration we officially support, let's leave this as it is for now.
  408. # More details: https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
  409. if(NOT ANDROID AND NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
  410. add_definitions(-D_FILE_OFFSET_BITS=64)
  411. add_definitions(-D_LARGEFILE_SOURCE)
  412. endif()
  413. ########################################
  414. # Dependency checking
  415. #
  416. # TODO: We should have options for dependencies included in the externals to
  417. # override autodetection of system libraries and force the usage of the
  418. # externals.
  419. include(CheckLib)
  420. include(CheckCXXSourceRuns)
  421. set(OpenGL_GL_PREFERENCE GLVND CACHE STRING "Linux-only: if GLVND, use the vendor-neutral GL libraries (default). If LEGACY, use the legacy ones (might be necessary to have optirun/primusrun work)")
  422. set_property(CACHE OpenGL_GL_PREFERENCE PROPERTY STRINGS GLVND LEGACY)
  423. find_package(OpenGL)
  424. if (OPENGL_GL)
  425. include_directories(${OPENGL_INCLUDE_DIR})
  426. endif()
  427. if(ENABLE_X11)
  428. pkg_check_modules(X11 x11 IMPORTED_TARGET)
  429. if(X11_FOUND)
  430. add_definitions(-DHAVE_X11=1)
  431. pkg_check_modules(XRANDR xrandr IMPORTED_TARGET)
  432. if(XRANDR_FOUND)
  433. add_definitions(-DHAVE_XRANDR=1)
  434. endif()
  435. pkg_check_modules(X11_INPUT REQUIRED xi>=1.5.0 IMPORTED_TARGET)
  436. message(STATUS "X11 support enabled")
  437. else()
  438. message(WARNING "X11 support enabled but not found. This build will not support X11.")
  439. endif()
  440. endif()
  441. if(ENABLE_EGL)
  442. find_package(EGL)
  443. if(EGL_FOUND)
  444. add_definitions(-DHAVE_EGL=1)
  445. message(STATUS "EGL OpenGL interface enabled")
  446. else()
  447. message(WARNING "EGL support enabled but not found. This build will not support EGL.")
  448. endif()
  449. endif()
  450. if(ENCODE_FRAMEDUMPS)
  451. if(WIN32)
  452. if(_M_X86_64)
  453. set(FFMPEG_DIR Externals/FFmpeg-bin/x64)
  454. elseif(_M_ARM_64)
  455. set(FFMPEG_DIR Externals/FFmpeg-bin/ARM64)
  456. endif()
  457. endif()
  458. find_package(FFmpeg COMPONENTS avcodec avformat avutil swresample swscale)
  459. if(FFmpeg_FOUND)
  460. if(APPLE)
  461. find_library(COREMEDIA_LIBRARY CoreMedia)
  462. find_library(VIDEOTOOLBOX_LIBRARY VideoToolbox)
  463. find_library(COREVIDEO_LIBRARY CoreVideo)
  464. find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
  465. endif()
  466. message(STATUS "libav/ffmpeg found, enabling AVI frame dumps")
  467. add_definitions(-DHAVE_FFMPEG)
  468. if(WIN32)
  469. # Our prebuilt binaries depend on Bcrypt
  470. set_property(TARGET FFmpeg::avutil APPEND PROPERTY
  471. INTERFACE_LINK_LIBRARIES "Bcrypt.lib"
  472. )
  473. endif()
  474. else()
  475. message(STATUS "libav/ffmpeg not found, disabling AVI frame dumps")
  476. endif()
  477. endif()
  478. if(OPROFILING)
  479. find_package(OProfile)
  480. if(OPROFILE_FOUND)
  481. message(STATUS "OProfile found, enabling profiling support")
  482. add_definitions(-DUSE_OPROFILE=1)
  483. else()
  484. message(FATAL_ERROR "OProfile not found. Can't build profiling support.")
  485. endif()
  486. endif()
  487. if(ENABLE_EVDEV)
  488. find_package(LIBUDEV REQUIRED)
  489. find_package(LIBEVDEV REQUIRED)
  490. if(LIBUDEV_FOUND AND LIBEVDEV_FOUND)
  491. message(STATUS "libevdev/libudev found, enabling evdev controller backend")
  492. add_definitions(-DHAVE_LIBUDEV=1)
  493. add_definitions(-DHAVE_LIBEVDEV=1)
  494. else()
  495. message(FATAL_ERROR "Couldn't find libevdev and/or libudev. Can't build evdev controller backend.\nDisable ENABLE_EVDEV if you wish to build without controller support")
  496. endif()
  497. endif()
  498. if(UNIX)
  499. message(STATUS "Using named pipes as controller inputs")
  500. add_definitions(-DUSE_PIPES=1)
  501. message(STATUS "Watching game memory for changes")
  502. add_definitions(-DUSE_MEMORYWATCHER=1)
  503. endif()
  504. if(ENABLE_SDL)
  505. dolphin_find_optional_system_library(SDL2 Externals/SDL 2.26.0)
  506. endif()
  507. if(ENABLE_ANALYTICS)
  508. message(STATUS "Enabling analytics collection (subject to end-user opt-in)")
  509. add_definitions(-DUSE_ANALYTICS=1)
  510. endif()
  511. if(ENABLE_AUTOUPDATE)
  512. message(STATUS "Enabling automatic update support")
  513. add_definitions(-DAUTOUPDATE=1)
  514. endif()
  515. ########################################
  516. # Setup include directories (and make sure they are preferred over the Externals)
  517. #
  518. include_directories(Source/Core)
  519. if(ANDROID)
  520. include_directories(Source/Android)
  521. endif()
  522. ########################################
  523. # Process externals and setup their include directories
  524. #
  525. # NOTES about adding Externals:
  526. # - If an external provides a target, or one can be introduced with find_package, consider using it.
  527. # - If a target doesn't exist, consider introducing a target for it with add_library and adding all necessary
  528. # includes, definitions, etc, to that target. This way, only libraries that need those attributes simply
  529. # need to link that target in, as opposed to them being provided to every library
  530. # (which is the case with the directory-based include_directories, add_definitions, etc)
  531. #
  532. # - make sure to tell cmake to link them statically or dynamically (most
  533. # should be linked statically)
  534. # - place the CMakeLists.txt in the first-level subdirectory, e.g.
  535. # Externals/zlib/CMakeLists.txt (that is: NOT in some Src/ subdirectory)
  536. #
  537. if (_M_X86_64)
  538. add_subdirectory(Externals/Bochs_disasm)
  539. endif()
  540. add_subdirectory(Externals/cpp-optparse)
  541. dolphin_find_optional_system_library_pkgconfig(FMT
  542. fmt>=10.1 fmt::fmt Externals/fmt
  543. )
  544. add_subdirectory(Externals/imgui)
  545. add_subdirectory(Externals/implot)
  546. add_subdirectory(Externals/glslang)
  547. # SPIRV-Cross is used on Windows for GLSL to HLSL conversion for the Direct3D 11 and Direct3D 12
  548. # video backends, and on Apple devices for the Metal video backend.
  549. if(WIN32 OR APPLE)
  550. add_subdirectory(Externals/spirv_cross)
  551. endif()
  552. add_subdirectory(Externals/tinygltf)
  553. if(ENABLE_VULKAN)
  554. add_definitions(-DHAS_VULKAN)
  555. if(APPLE AND USE_BUNDLED_MOLTENVK)
  556. add_subdirectory(Externals/MoltenVK)
  557. endif()
  558. if (ANDROID AND _M_ARM_64)
  559. add_subdirectory(Externals/libadrenotools)
  560. endif()
  561. endif()
  562. if(NOT WIN32 OR (NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")))
  563. # OpenGL is available on all platforms except windows-arm64
  564. add_definitions(-DHAS_OPENGL)
  565. endif()
  566. dolphin_find_optional_system_library(pugixml Externals/pugixml)
  567. dolphin_find_optional_system_library_pkgconfig(ENET libenet>=1.3.18 enet::enet Externals/enet)
  568. dolphin_find_optional_system_library_pkgconfig(xxhash libxxhash>=0.8.2 xxhash::xxhash Externals/xxhash)
  569. dolphin_find_optional_system_library(BZip2 Externals/bzip2)
  570. dolphin_find_optional_system_library(LibLZMA Externals/liblzma)
  571. # Imported target added in CMake 3.14
  572. dolphin_make_imported_target_if_missing(LibLZMA::LibLZMA LIBLZMA)
  573. dolphin_find_optional_system_library_pkgconfig(ZSTD libzstd>=1.4.0 zstd::zstd Externals/zstd)
  574. dolphin_find_optional_system_library_pkgconfig(ZLIB zlib-ng ZLIB::ZLIB Externals/zlib-ng)
  575. dolphin_find_optional_system_library_pkgconfig(MINIZIP
  576. "minizip-ng>=4.0.4;minizip>=4.0.4" minizip::minizip Externals/minizip-ng
  577. )
  578. dolphin_find_optional_system_library(LZO Externals/LZO)
  579. dolphin_find_optional_system_library_pkgconfig(lz4 liblz4>=1.8 LZ4::LZ4 Externals/lz4)
  580. dolphin_find_optional_system_library_pkgconfig(SPNG spng spng::spng Externals/libspng)
  581. # Using static FreeSurround from Externals
  582. # There is no system FreeSurround library.
  583. message(STATUS "Using static FreeSurround from Externals")
  584. add_subdirectory(Externals/FreeSurround)
  585. if (APPLE OR WIN32)
  586. message(STATUS "Using ed25519 from Externals")
  587. add_subdirectory(Externals/ed25519)
  588. include_directories(Externals/ed25519)
  589. endif()
  590. # Using static soundtouch from Externals
  591. # Unable to use system soundtouch library: We require shorts, not floats.
  592. add_subdirectory(Externals/soundtouch)
  593. include_directories(Externals/soundtouch)
  594. dolphin_find_optional_system_library(CUBEB Externals/cubeb)
  595. if(NOT ANDROID)
  596. dolphin_find_optional_system_library_pkgconfig(
  597. LibUSB libusb-1.0 LibUSB::LibUSB Externals/libusb
  598. )
  599. add_definitions(-D__LIBUSB__)
  600. endif()
  601. dolphin_find_optional_system_library(SFML Externals/SFML 2.1 COMPONENTS network system)
  602. if(USE_UPNP)
  603. dolphin_find_optional_system_library(MINIUPNPC Externals/miniupnpc 1.6)
  604. add_definitions(-DUSE_UPNP)
  605. endif()
  606. dolphin_find_optional_system_library(MBEDTLS Externals/mbedtls 2.28)
  607. dolphin_find_optional_system_library(CURL Externals/curl)
  608. if(NOT ANDROID)
  609. dolphin_find_optional_system_library(Iconv Externals/libiconv-1.14)
  610. else()
  611. message(STATUS "Using static iconv from Externals")
  612. add_subdirectory(Externals/libiconv-1.14 EXCLUDE_FROM_ALL)
  613. endif()
  614. if(NOT ANDROID)
  615. dolphin_find_optional_system_library(HIDAPI Externals/hidapi)
  616. endif()
  617. if(USE_DISCORD_PRESENCE)
  618. message(STATUS "Using static DiscordRPC from Externals")
  619. add_subdirectory(Externals/discord-rpc EXCLUDE_FROM_ALL)
  620. include_directories(Externals/discord-rpc/include)
  621. endif()
  622. if(NOT ENABLE_QT)
  623. set(USE_MGBA 0)
  624. endif()
  625. if(USE_MGBA)
  626. dolphin_find_optional_system_library(LIBMGBA Externals/mGBA)
  627. endif()
  628. find_package(SYSTEMD)
  629. if(SYSTEMD_FOUND)
  630. message(STATUS "libsystemd found, enabling traversal server watchdog support")
  631. add_definitions(-DHAVE_LIBSYSTEMD)
  632. else()
  633. message(STATUS "libsystemd not found, disabling traversal server watchdog support")
  634. endif()
  635. if(STEAM)
  636. add_definitions(-DSTEAM)
  637. endif()
  638. if (WIN32)
  639. include_directories(Externals/WIL/include)
  640. include_directories(Externals/OpenAL/include)
  641. endif()
  642. include_directories(Externals/picojson)
  643. add_subdirectory(Externals/expr)
  644. add_subdirectory(Externals/rangeset)
  645. add_subdirectory(Externals/FatFs)
  646. if (USE_RETRO_ACHIEVEMENTS)
  647. add_subdirectory(Externals/rcheevos)
  648. endif()
  649. ########################################
  650. # Pre-build events: Define configuration variables and write SCM info header
  651. #
  652. # Remove in-tree revision information generated by Visual Studio
  653. # This is because the compiler will check in-tree first and use this, even if it is outdated
  654. file(REMOVE "${PROJECT_SOURCE_DIR}/Source/Core/Common/scmrev.h")
  655. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/Common)
  656. if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/Common/scmrev.h)
  657. file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/Common/scmrev.h)
  658. endif()
  659. if(APPLE)
  660. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/DolphinQt)
  661. if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/DolphinQt/Info.plist)
  662. file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/DolphinQt/Info.plist)
  663. endif()
  664. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/MacUpdater)
  665. if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/MacUpdater/Info.plist)
  666. file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/MacUpdater/Info.plist)
  667. endif()
  668. endif()
  669. find_package(Git)
  670. if(NOT GIT_FOUND)
  671. set(GIT_EXECUTABLE "")
  672. endif()
  673. add_custom_target(
  674. dolphin_scmrev
  675. ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} -DDISTRIBUTOR=${DISTRIBUTOR} -DDOLPHIN_DEFAULT_UPDATE_TRACK=${DOLPHIN_DEFAULT_UPDATE_TRACK} -DGIT_FOUND=${GIT_FOUND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DDOLPHIN_WC_REVISION=${DOLPHIN_WC_REVISION} -DDOLPHIN_WC_DESCRIBE=${DOLPHIN_WC_DESCRIBE} -DDOLPHIN_WC_BRANCH=${DOLPHIN_WC_BRANCH} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} -P ${CMAKE_CURRENT_SOURCE_DIR}/CMake/ScmRevGen.cmake
  676. BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/Source/Core/Common/scmrev.h" "${CMAKE_CURRENT_BINARY_DIR}/Source/Core/DolphinQt/Info.plist" "${CMAKE_CURRENT_BINARY_DIR}/Source/Core/MacUpdater/Info.plist"
  677. VERBATIM
  678. )
  679. # This is here so #include "Common/scmrev.h" finds the generated header.
  680. include_directories("${PROJECT_BINARY_DIR}/Source/Core")
  681. ########################################
  682. # Unit testing.
  683. #
  684. if(ENABLE_TESTS)
  685. dolphin_find_optional_system_library_pkgconfig(GTEST
  686. gtest gtest::gtest Externals/gtest
  687. )
  688. # dolphin_find_optional_system_library_pkgconfig() doesn't add an alias if it
  689. # uses the bundled libraries, so we add one ourselves.
  690. if (NOT TARGET gtest::gtest)
  691. add_library(gtest::gtest ALIAS gtest)
  692. endif()
  693. # Force gtest to link the C runtime dynamically on Windows in order to avoid
  694. # runtime mismatches.
  695. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  696. else()
  697. message(STATUS "Unit tests are disabled")
  698. endif()
  699. ########################################
  700. # Process Dolphin source now that all setup is complete
  701. #
  702. add_subdirectory(Source)
  703. ########################################
  704. # Install shared data files
  705. #
  706. if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
  707. install(DIRECTORY Data/Sys/ DESTINATION ${datadir}/sys PATTERN)
  708. endif()
  709. if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux|FreeBSD|OpenBSD|Darwin")
  710. install(FILES Data/license.txt DESTINATION ${datadir})
  711. endif()
  712. if(CMAKE_SYSTEM_NAME MATCHES "Linux|FreeBSD|OpenBSD")
  713. # Install the application icon and menu item
  714. install(FILES Data/dolphin-emu.svg
  715. DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps)
  716. install(FILES Data/dolphin-emu.png
  717. DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps)
  718. install(FILES Data/dolphin-emu.desktop
  719. DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
  720. # Install manpages
  721. install(FILES Data/dolphin-emu.6
  722. DESTINATION ${CMAKE_INSTALL_MANDIR}/man6)
  723. install(FILES Data/dolphin-emu-nogui.6
  724. DESTINATION ${CMAKE_INSTALL_MANDIR}/man6)
  725. endif()
  726. # packaging information
  727. set(CPACK_PACKAGE_NAME "dolphin-emu")
  728. set(CPACK_PACKAGE_VENDOR "Dolphin Team")
  729. set(CPACK_PACKAGE_VERSION_MAJOR ${DOLPHIN_VERSION_MAJOR})
  730. set(CPACK_PACKAGE_VERSION_MINOR ${DOLPHIN_VERSION_MINOR})
  731. set(CPACK_PACKAGE_VERSION_PATCH ${DOLPHIN_VERSION_PATCH})
  732. set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/Data/cpack_package_description.txt)
  733. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A GameCube and Wii emulator")
  734. set(CPACK_RPM_PACKAGE_GROUP System/Emulators/Other)
  735. set(CPACK_RPM_PACKAGE_LICENSE GPL-2.0)
  736. # TODO: CPACK_RESOURCE_FILE_README
  737. # TODO: CPACK_RESOURCE_FILE_WELCOME
  738. # TODO: CPACK_PACKAGE_ICON
  739. # TODO: CPACK_NSIS_*
  740. # TODO: Use CPack components for DSPSpy, etc => cpack_add_component
  741. # Debian Specific. Install dpkg-dev for automatic deps generation
  742. set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
  743. set(CPACK_DEBIAN_PACKAGE_SECTION "Games")
  744. set(CPACK_SET_DESTDIR ON)
  745. set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2;ZIP")
  746. set(CPACK_SOURCE_IGNORE_FILES "\\\\.#;/#;.*~;\\\\.swp;/\\\\.git")
  747. list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}")
  748. # CPack must be included after the CPACK_* variables are set in order for those
  749. # variables to take effect.
  750. Include(CPack)