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