CMakeLists.txt 32 KB

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