CMakeLists.txt 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. ########################################
  2. # General setup
  3. #
  4. cmake_minimum_required(VERSION 2.8.8)
  5. project(dolphin-emu)
  6. option(USE_EGL "Enables EGL OpenGL Interface" OFF)
  7. option(TRY_X11 "Enables X11 Support" ON)
  8. option(USE_SHARED_ENET "Use shared libenet if found rather than Dolphin's soon-to-compatibly-diverge version" OFF)
  9. option(USE_UPNP "Enables UPnP port mapping support" ON)
  10. option(DISABLE_WX "Disable wxWidgets (use Qt or CLI interface)" OFF)
  11. option(ENABLE_QT "Enable Qt (use the experimental Qt interface)" OFF)
  12. option(ENABLE_PCH "Use PCH to speed up compilation" ON)
  13. option(ENABLE_LTO "Enables Link Time Optimization" OFF)
  14. option(ENABLE_GENERIC "Enables generic build that should run on any little-endian host" OFF)
  15. # Enable SDL for default on operating systems that aren't OSX, Android, Linux or Windows.
  16. if(NOT APPLE AND NOT ANDROID AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT MSVC)
  17. option(ENABLE_SDL "Enables SDL as a generic controller backend" ON)
  18. else()
  19. option(ENABLE_SDL "Enables SDL as a generic controller backend" OFF)
  20. endif()
  21. if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT ANDROID)
  22. option(ENABLE_EVDEV "Enables the evdev controller backend" ON)
  23. endif()
  24. if(APPLE)
  25. option(OSX_USE_DEFAULT_SEARCH_PATH "Don't prioritize system library paths" OFF)
  26. endif()
  27. option(ENCODE_FRAMEDUMPS "Encode framedumps in AVI format" ON)
  28. option(FASTLOG "Enable all logs" OFF)
  29. option(OPROFILING "Enable profiling" OFF)
  30. option(GDBSTUB "Enable gdb stub for remote debugging." OFF)
  31. if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  32. option(VTUNE "Enable Intel VTune integration for JIT symbols." OFF)
  33. endif()
  34. if(APPLE)
  35. option(SKIP_POSTPROCESS_BUNDLE "Skip postprocessing bundle for redistributability" OFF)
  36. endif()
  37. ########################################
  38. # Optional Targets
  39. # TODO: Add DSPSpy
  40. option(DSPTOOL "Build dsptool" OFF)
  41. # Update compiler before calling project()
  42. if (APPLE)
  43. # Use clang compiler
  44. if (NOT DEFINED CMAKE_CXX_COMPILER)
  45. set(CMAKE_CXX_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++")
  46. if (NOT EXISTS "${CMAKE_CXX_COMPILER}")
  47. set(CMAKE_CXX_COMPILER "clang++")
  48. endif()
  49. endif()
  50. if (NOT DEFINED CMAKE_C_COMPILER)
  51. set(CMAKE_C_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang")
  52. if (NOT EXISTS "${CMAKE_C_COMPILER}")
  53. set(CMAKE_C_COMPILER "clang")
  54. endif()
  55. endif()
  56. endif()
  57. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeTests)
  58. # Libraries to link
  59. set(LIBS)
  60. # Set up paths
  61. if(APPLE)
  62. # The gettext module will install the translations unconditionally.
  63. # Redirect the installation to a build directory where it does no harm.
  64. set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install-dummy)
  65. else()
  66. set(bindir ${CMAKE_INSTALL_PREFIX}/bin CACHE PATH "bindir")
  67. set(datadir ${CMAKE_INSTALL_PREFIX}/share/dolphin-emu CACHE PATH "datadir")
  68. add_definitions(-DDATA_DIR="${datadir}/")
  69. endif()
  70. set(userdir ".dolphin-emu" CACHE STRING "User directory")
  71. add_definitions(-DUSER_DIR="${userdir}")
  72. # Set where the binary files will be built. The program will not execute from
  73. # here. You must run "make install" to install these to the proper location
  74. # as defined above.
  75. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Binaries)
  76. # Precompiled header support for MSVC:
  77. # Call this after setting the source list (and don't add the source file used
  78. # to generate the pch file, this will be done here automatically)
  79. function(enable_precompiled_headers PRECOMPILED_HEADER SOURCE_FILE SOURCE_VARIABLE_NAME)
  80. if(MSVC)
  81. set(files ${${SOURCE_VARIABLE_NAME}})
  82. # Generate precompiled header translation unit
  83. get_filename_component(pch_basename ${PRECOMPILED_HEADER} NAME_WE)
  84. set(pch_abs ${CMAKE_CURRENT_SOURCE_DIR}/${PRECOMPILED_HEADER})
  85. set(pch_unity ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE})
  86. set_source_files_properties(${pch_unity} PROPERTIES COMPILE_FLAGS
  87. "/Yc\"${pch_abs}\"")
  88. # Update properties of source files to use the precompiled header.
  89. # Additionally, force the inclusion of the precompiled header at
  90. # beginning of each source file.
  91. foreach(source_file ${files} )
  92. set_source_files_properties(${source_file} PROPERTIES COMPILE_FLAGS
  93. "/Yu\"${pch_abs}\" /FI\"${pch_abs}\"")
  94. endforeach(source_file)
  95. # Finally, update the source file collection to contain the
  96. # precompiled header translation unit
  97. set(${SOURCE_VARIABLE_NAME} ${pch_unity} ${${SOURCE_VARIABLE_NAME}} PARENT_SCOPE)
  98. endif(MSVC)
  99. endfunction(enable_precompiled_headers)
  100. # for revision info
  101. include(FindGit OPTIONAL)
  102. if(GIT_FOUND AND NOT DOLPHIN_WC_REVISION)
  103. # defines DOLPHIN_WC_REVISION
  104. EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
  105. OUTPUT_VARIABLE DOLPHIN_WC_REVISION
  106. OUTPUT_STRIP_TRAILING_WHITESPACE)
  107. # defines DOLPHIN_WC_DESCRIBE
  108. EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --always --long --dirty
  109. OUTPUT_VARIABLE DOLPHIN_WC_DESCRIBE
  110. OUTPUT_STRIP_TRAILING_WHITESPACE)
  111. # remove hash (and trailing "-0" if needed) from description
  112. STRING(REGEX REPLACE "(-0)?-[^-]+((-dirty)?)$" "\\2" DOLPHIN_WC_DESCRIBE "${DOLPHIN_WC_DESCRIBE}")
  113. # defines DOLPHIN_WC_BRANCH
  114. EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
  115. OUTPUT_VARIABLE DOLPHIN_WC_BRANCH
  116. OUTPUT_STRIP_TRAILING_WHITESPACE)
  117. endif()
  118. # version number
  119. set(DOLPHIN_VERSION_MAJOR "5")
  120. set(DOLPHIN_VERSION_MINOR "0")
  121. if(DOLPHIN_WC_BRANCH STREQUAL "stable")
  122. set(DOLPHIN_VERSION_PATCH "0")
  123. else()
  124. set(DOLPHIN_VERSION_PATCH ${DOLPHIN_WC_REVISION})
  125. endif()
  126. # Architecture detection and arch specific settings
  127. message(${CMAKE_SYSTEM_PROCESSOR})
  128. # Detect 64bit or 32bit
  129. # CMake doesn't provide a simple way to determine 32bit or 64bit
  130. # If we ever support a architecture that is 64bit with 32bit pointers then this'll break
  131. # Of course the chances of that are slim(x32?) so who cares
  132. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  133. set(_ARCH_64 1)
  134. add_definitions(-D_ARCH_64=1)
  135. else()
  136. set(_ARCH_32 1)
  137. add_definitions(-D_ARCH_32=1)
  138. endif()
  139. if(NOT ENABLE_GENERIC)
  140. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86" OR
  141. ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86" OR
  142. ${CMAKE_SYSTEM_PROCESSOR} MATCHES "amd64" OR
  143. APPLE)
  144. if(_ARCH_64)
  145. set(_M_X86 1)
  146. set(_M_X86_64 1)
  147. add_definitions(-D_M_X86=1 -D_M_X86_64=1 -msse2)
  148. else()
  149. message(FATAL_ERROR "x86_32 is an unsupported platform. Enable generic build if you really want a JIT-less binary.")
  150. endif()
  151. elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
  152. message(FATAL_ERROR "ARMv7 is an unsupported platform. Enable generic build if you really want a JIT-less binary.")
  153. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  154. # This option only applies to 64bit ARM
  155. set(_M_ARM 1)
  156. set(_M_ARM_64 1)
  157. add_definitions(-D_M_ARM=1 -D_M_ARM_64=1)
  158. add_definitions(-march=armv8-a+crc)
  159. else()
  160. set(ENABLE_GENERIC 1)
  161. endif()
  162. endif()
  163. if(ENABLE_GENERIC)
  164. message("Warning! Building generic build!")
  165. set(_M_GENERIC 1)
  166. add_definitions(-D_M_GENERIC=1)
  167. endif()
  168. include(CheckCXXCompilerFlag)
  169. macro(check_and_add_flag var flag)
  170. CHECK_CXX_COMPILER_FLAG(${flag} FLAG_${var})
  171. if(FLAG_${var})
  172. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  173. endif()
  174. endmacro()
  175. # Enabling all warnings in MSVC spams too much
  176. if(NOT MSVC)
  177. add_definitions(-Wall)
  178. # TODO: would like these but they produce overwhelming amounts of warnings
  179. #check_and_add_flag(EXTRA -Wextra)
  180. #check_and_add_flag(MISSING_FIELD_INITIALIZERS -Wmissing-field-initializers)
  181. #check_and_add_flag(SWITCH_DEFAULT -Wswitch-default)
  182. #check_and_add_flag(FLOAT_EQUAL -Wfloat-equal)
  183. #check_and_add_flag(CONVERSION -Wconversion)
  184. #check_and_add_flag(ZERO_AS_NULL_POINTER_CONSTANT -Wzero-as-null-pointer-constant)
  185. check_and_add_flag(TYPE_LIMITS -Wtype-limits)
  186. check_and_add_flag(SIGN_COMPARE -Wsign-compare)
  187. check_and_add_flag(IGNORED_QUALIFIERS -Wignored-qualifiers)
  188. check_and_add_flag(UNINITIALIZED -Wuninitialized)
  189. check_and_add_flag(LOGICAL_OP -Wlogical-op)
  190. check_and_add_flag(SHADOW -Wshadow)
  191. check_and_add_flag(INIT_SELF -Winit-self)
  192. check_and_add_flag(MISSING_DECLARATIONS -Wmissing-declarations)
  193. check_and_add_flag(MISSING_VARIABLE_DECLARATIONS -Wmissing-variable-declarations)
  194. endif(NOT MSVC)
  195. # gcc uses some optimizations which might break stuff without this flag
  196. add_definitions(-fno-strict-aliasing -fno-exceptions)
  197. check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-hidden)
  198. if(UNIX AND NOT APPLE)
  199. check_and_add_flag(VISIBILITY_HIDDEN -fvisibility=hidden)
  200. endif()
  201. if(ENABLE_LTO)
  202. check_and_add_flag(LTO -flto)
  203. if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
  204. set(CMAKE_AR gcc-ar)
  205. set(CMAKE_RANLIB gcc-ranlib)
  206. endif()
  207. endif()
  208. if(APPLE)
  209. if(NOT OSX_USE_DEFAULT_SEARCH_PATH)
  210. # Hack up the path to prioritize the path to built-in OS libraries to
  211. # increase the chance of not depending on a bunch of copies of them
  212. # installed by MacPorts, Fink, Homebrew, etc, and ending up copying
  213. # them into the bundle. Since we optionally depend on libraries which
  214. # are not part of OS X (ffmpeg, libusb, etc.), however, don't remove
  215. # the default path entirely as was done in a previous version of this
  216. # file. This is still kinda evil, since it defeats the user's path
  217. # settings...
  218. # See http://www.cmake.org/cmake/help/v3.0/command/find_program.html
  219. set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr")
  220. endif()
  221. # Identify the target system:
  222. # Ask for 64-bit binary.
  223. set(TARGET_FLAGS "-arch x86_64")
  224. # Minimum OS X version.
  225. # This is inserted into the Info.plist as well.
  226. # Note that the SDK determines the maximum version of which optional
  227. # features can be used, not the minimum required version to run.
  228. set(OSX_MIN_VERSION "10.9")
  229. set(TARGET_FLAGS "${TARGET_FLAGS} -mmacosx-version-min=${OSX_MIN_VERSION}")
  230. set(SYSROOT_LEGACY_PATH "/Developer/SDKs/MacOSX10.9.sdk")
  231. set(SYSROOT_PATH "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk")
  232. if(EXISTS "${SYSROOT_PATH}/")
  233. set(TARGET_SYSROOT ${SYSROOT_PATH})
  234. elseif(EXISTS "${SYSROOT_LEGACY_PATH}/")
  235. set(TARGET_SYSROOT ${SYSROOT_LEGACY_PATH})
  236. endif()
  237. if(${TARGET_SYSROOT})
  238. set(TARGET_FLAGS "${TARGET_FLAGS} -isysroot ${TARGET_SYSROOT}")
  239. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-syslibroot,${TARGET_SYSROOT}")
  240. endif()
  241. # Do not warn about frameworks that are not available on all architectures.
  242. # This avoids a warning when linking with QuickTime.
  243. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-no_arch_warnings")
  244. # Specify target CPUs.
  245. set(TARGET_FLAGS "${TARGET_FLAGS} -mssse3")
  246. set(TARGET_FLAGS "${TARGET_FLAGS} -march=core2")
  247. # Target flags apply to both C and C++ compilation.
  248. # CMake passes these to the compiler on the link command line as well.
  249. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}")
  250. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TARGET_FLAGS}")
  251. # Linker flags.
  252. # Drop unreachable code and data.
  253. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip,-dead_strip_dylibs")
  254. # Reserve the minimum size for the zero page.
  255. # Our JIT requires virtual memory space below 2GB, while the default zero
  256. # page on x86_64 is 4GB in size.
  257. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-pagezero_size,0x1000")
  258. find_library(APPKIT_LIBRARY AppKit)
  259. find_library(APPSERV_LIBRARY ApplicationServices)
  260. find_library(ATB_LIBRARY AudioToolbox)
  261. find_library(AU_LIBRARY AudioUnit)
  262. find_library(CARBON_LIBRARY Carbon)
  263. find_library(COCOA_LIBRARY Cocoa)
  264. find_library(COREAUDIO_LIBRARY CoreAudio)
  265. find_library(COREFUND_LIBRARY CoreFoundation)
  266. find_library(CORESERV_LIBRARY CoreServices)
  267. find_library(FOUNDATION_LIBRARY foundation)
  268. find_library(IOB_LIBRARY IOBluetooth)
  269. find_library(IOK_LIBRARY IOKit)
  270. find_library(QUICKTIME_LIBRARY QuickTime)
  271. find_library(WEBKIT_LIBRARY WebKit)
  272. find_library(FORCEFEEDBACK ForceFeedback)
  273. find_library(OPENGL_LIBRARY OpenGL)
  274. endif()
  275. if(WIN32)
  276. add_definitions(-D_SECURE_SCL=0)
  277. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  278. add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  279. endif(WIN32)
  280. # Dolphin requires threads.
  281. # The Apple build may not need an explicit flag because one of the
  282. # frameworks may already provide it.
  283. # But for non-OSX systems, we will use the CMake Threads package.
  284. IF(NOT APPLE)
  285. FIND_PACKAGE(Threads)
  286. ENDIF(NOT APPLE)
  287. if(NOT CMAKE_BUILD_TYPE)
  288. set(CMAKE_BUILD_TYPE "Release" CACHE STRING
  289. "Build type (Release/Debug/RelWithDebInfo/MinSizeRe)" FORCE)
  290. endif(NOT CMAKE_BUILD_TYPE)
  291. if(CMAKE_BUILD_TYPE STREQUAL Debug)
  292. add_definitions(-D_DEBUG -ggdb)
  293. set(wxWidgets_USE_DEBUG ON CACHE BOOL "Use wxWidgets Debugging")
  294. option(ENABLE_GPROF "Enable gprof profiling (must be using Debug build)" OFF)
  295. if(ENABLE_GPROF)
  296. add_definitions(-pg)
  297. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
  298. endif()
  299. endif(CMAKE_BUILD_TYPE STREQUAL Debug)
  300. if(CMAKE_BUILD_TYPE STREQUAL Release AND NOT APPLE)
  301. add_definitions(-fomit-frame-pointer)
  302. endif()
  303. if(FASTLOG)
  304. add_definitions(-DDEBUGFAST)
  305. endif()
  306. if(GDBSTUB)
  307. add_definitions(-DUSE_GDBSTUB)
  308. endif(GDBSTUB)
  309. if(VTUNE)
  310. if(EXISTS "$ENV{VTUNE_AMPLIFIER_XE_2015_DIR}")
  311. set(VTUNE_DIR "$ENV{VTUNE_AMPLIFIER_XE_2015_DIR}")
  312. elseif(EXISTS "$ENV{VTUNE_AMPLIFIER_XE_2013_DIR}")
  313. set(VTUNE_DIR "$ENV{VTUNE_AMPLIFIER_XE_2013_DIR}")
  314. else()
  315. message(ERROR "Could find neither VTUNE_AMPLIFIER_XE_2015_DIR nor VTUNE_AMPLIFIER_XE_2013_DIR.")
  316. endif()
  317. add_definitions(-DUSE_VTUNE)
  318. include_directories("${VTUNE_DIR}/include")
  319. set(VTUNE_LIBRARIES
  320. "${VTUNE_DIR}/lib64/libjitprofiling.a"
  321. "${VTUNE_DIR}/lib64/libittnotify.a"
  322. )
  323. endif(VTUNE)
  324. if(ANDROID)
  325. message("Building for Android")
  326. add_definitions(-DANDROID)
  327. set(USE_X11 0)
  328. set(USE_UPNP 0)
  329. set(USE_EGL 1)
  330. endif()
  331. include_directories(Externals/GL)
  332. add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
  333. ########################################
  334. # Dependency checking
  335. #
  336. # TODO: We should have options for dependencies included in the externals to
  337. # override autodetection of system libraries and force the usage of the
  338. # externals.
  339. include(CheckLib)
  340. include(CheckCXXSourceRuns)
  341. if(NOT ANDROID)
  342. include(FindOpenGL)
  343. include_directories(${OPENGL_INCLUDE_DIR})
  344. include(FindALSA OPTIONAL)
  345. if(ALSA_FOUND)
  346. add_definitions(-DHAVE_ALSA=1)
  347. message("ALSA found, enabling ALSA sound backend")
  348. else()
  349. add_definitions(-DHAVE_ALSA=0)
  350. message("ALSA NOT found, disabling ALSA sound backend")
  351. endif(ALSA_FOUND)
  352. check_lib(AO ao ao QUIET)
  353. if(AO_FOUND)
  354. add_definitions(-DHAVE_AO=1)
  355. message("ao found, enabling ao sound backend")
  356. else()
  357. add_definitions(-DHAVE_AO=0)
  358. message("ao NOT found, disabling ao sound backend")
  359. endif(AO_FOUND)
  360. check_lib(BLUEZ bluez bluez QUIET)
  361. if(BLUEZ_FOUND)
  362. add_definitions(-DHAVE_BLUEZ=1)
  363. message("bluez found, enabling bluetooth support")
  364. else()
  365. add_definitions(-DHAVE_BLUEZ=0)
  366. message("bluez NOT found, disabling bluetooth support")
  367. endif(BLUEZ_FOUND)
  368. check_lib(PULSEAUDIO libpulse pulse QUIET)
  369. if(PULSEAUDIO_FOUND)
  370. add_definitions(-DHAVE_PULSEAUDIO=1)
  371. message("PulseAudio found, enabling PulseAudio sound backend")
  372. else()
  373. add_definitions(-DHAVE_PULSEAUDIO=0)
  374. message("PulseAudio NOT found, disabling PulseAudio sound backend")
  375. endif(PULSEAUDIO_FOUND)
  376. include(FindOpenAL OPTIONAL)
  377. if(OPENAL_FOUND)
  378. add_definitions(-DHAVE_OPENAL=1)
  379. include_directories(${OPENAL_INCLUDE_DIR})
  380. message("OpenAL found, enabling OpenAL sound backend")
  381. else()
  382. add_definitions(-DHAVE_OPENAL=0)
  383. message("OpenAL NOT found, disabling OpenAL sound backend")
  384. endif(OPENAL_FOUND)
  385. include(FindLLVM OPTIONAL)
  386. if (LLVM_FOUND)
  387. add_definitions(-DHAS_LLVM=1)
  388. set(HAS_LLVM 1)
  389. include_directories(${LLVM_INCLUDE_DIRS})
  390. list(APPEND LIBS ${LLVM_LIBRARIES})
  391. message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
  392. endif()
  393. set(USE_X11 0)
  394. if(UNIX AND NOT APPLE)
  395. include(FindX11)
  396. if(TRY_X11 AND X11_FOUND)
  397. set(USE_X11 1)
  398. add_definitions(-DHAVE_X11=1)
  399. include_directories(${X11_INCLUDE_DIR})
  400. message("X11 support enabled")
  401. else()
  402. set(USE_X11 0)
  403. SET(X11_FOUND "")
  404. message("X11 support disabled")
  405. add_definitions(-DHAVE_X11=0)
  406. endif(TRY_X11 AND X11_FOUND)
  407. if (NOT USE_X11)
  408. message(FATAL_ERROR "\n"
  409. "No suitable display platform found\n"
  410. "Requires x11 to run")
  411. endif()
  412. endif()
  413. if(USE_X11)
  414. check_lib(XRANDR xrandr Xrandr)
  415. if(XRANDR_FOUND)
  416. add_definitions(-DHAVE_XRANDR=1)
  417. else()
  418. add_definitions(-DHAVE_XRANDR=0)
  419. endif(XRANDR_FOUND)
  420. pkg_check_modules(XINPUT2 xi>=1.5.0)
  421. if(XINPUT2_FOUND)
  422. add_definitions(-DHAVE_X11_XINPUT2=1)
  423. else()
  424. add_definitions(-DHAVE_X11_XINPUT2=0)
  425. endif(XINPUT2_FOUND)
  426. endif()
  427. if(ENCODE_FRAMEDUMPS)
  428. check_libav()
  429. if(LIBAV_FOUND)
  430. LIST(APPEND LIBS ${LIBAV_LIBRARIES})
  431. endif()
  432. endif()
  433. set(CMAKE_REQUIRED_LIBRARIES portaudio)
  434. CHECK_CXX_SOURCE_RUNS(
  435. "#include <portaudio.h>
  436. int main(int argc, char **argv)
  437. { if(Pa_GetVersion() >= 1890) return 0; else return 1; }"
  438. PORTAUDIO)
  439. unset(CMAKE_REQUIRED_LIBRARIES)
  440. if(PORTAUDIO)
  441. message("PortAudio found, enabling mic support")
  442. add_definitions(-DHAVE_PORTAUDIO=1)
  443. set(PORTAUDIO_FOUND TRUE)
  444. else()
  445. message("PortAudio not found, disabling mic support")
  446. add_definitions(-DHAVE_PORTAUDIO=0)
  447. set(PORTAUDIO_FOUND FALSE)
  448. endif(PORTAUDIO)
  449. if(OPROFILING)
  450. check_lib(OPROFILE "(no .pc for opagent)" opagent opagent.h)
  451. check_lib(BFD "(no .pc for bfd)" bfd bfd.h)
  452. if(OPROFILE_FOUND AND BFD_FOUND)
  453. message("oprofile found, enabling profiling support")
  454. add_definitions(-DUSE_OPROFILE=1)
  455. else()
  456. message(FATAL_ERROR "oprofile or bfd not found. Can't build profiling support.")
  457. endif()
  458. endif()
  459. endif()
  460. if(USE_EGL)
  461. message("EGL OpenGL interface enabled")
  462. add_definitions(-DUSE_EGL=1)
  463. endif()
  464. if(ENABLE_EVDEV)
  465. include(FindLibudev REQUIRED)
  466. include(FindLibevdev REQUIRED)
  467. if(LIBUDEV_FOUND AND LIBEVDEV_FOUND)
  468. message("libevdev/libudev found, enabling evdev controller backend")
  469. add_definitions(-DHAVE_LIBUDEV=1)
  470. add_definitions(-DHAVE_LIBEVDEV=1)
  471. include_directories(${LIBUDEV_INCLUDE_DIR} ${LIBEVDEV_INCLUDE_DIR})
  472. else()
  473. 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")
  474. endif()
  475. endif()
  476. ########################################
  477. # Setup include directories (and make sure they are preferred over the Externals)
  478. #
  479. include_directories(Source/Core)
  480. ########################################
  481. # Process externals and setup their include directories
  482. #
  483. # NOTES about adding Externals:
  484. # - add the include directory here
  485. # - make sure to tell cmake to link them statically or dynamically (most
  486. # should be linked statically)
  487. # - place the CMakeLists.txt in the first-level subdirectory, e.g.
  488. # Externals/zlib/CMakeLists.txt (that is: NOT in some Src/ subdirectory)
  489. #
  490. add_subdirectory(Externals/Bochs_disasm)
  491. include_directories(Externals/Bochs_disasm)
  492. if(NOT ANDROID AND USE_SHARED_ENET)
  493. check_lib(ENET libenet enet enet/enet.h QUIET)
  494. include(CheckSymbolExists)
  495. if (ENET_FOUND)
  496. set(CMAKE_REQUIRED_INCLUDES ${ENET_INCLUDE_DIRS})
  497. # hack: LDFLAGS already contains -lenet but all flags but the first are
  498. # dropped; ugh, cmake
  499. set(CMAKE_REQUIRED_FLAGS ${ENET_LDFLAGS})
  500. set(CMAKE_REQUIRED_LIBRARIES ${ENET_LIBRARIES})
  501. CHECK_SYMBOL_EXISTS(enet_socket_get_address enet/enet.h ENET_HAVE_SGA)
  502. set(CMAKE_REQUIRED_INCLUDES)
  503. set(CMAKE_REQUIRED_FLAGS)
  504. set(CMAKE_REQUIRED_LIBRARIES)
  505. if (NOT ENET_HAVE_SGA)
  506. # enet is too old
  507. set(ENET_FOUND FALSE)
  508. endif()
  509. endif()
  510. endif()
  511. if (ENET_FOUND)
  512. message("Using shared enet")
  513. else()
  514. message("Using static enet from Externals")
  515. include_directories(Externals/enet/include)
  516. add_subdirectory(Externals/enet)
  517. endif()
  518. LIST(APPEND LIBS enet)
  519. if(NOT XXHASH_FOUND)
  520. message("Using static xxhash from Externals")
  521. add_subdirectory(Externals/xxhash)
  522. include_directories(Externals/xxhash)
  523. endif()
  524. LIST(APPEND LIBS xxhash)
  525. # If zlib has already been found on a previous run of cmake don't check again
  526. # as the check seems to take a long time.
  527. if(NOT ZLIB_FOUND)
  528. include(FindZLIB OPTIONAL)
  529. endif()
  530. if(ZLIB_FOUND)
  531. set(ZLIB_FOUND 1 CACHE INTERNAL "")
  532. message("Using shared zlib")
  533. include_directories(${ZLIB_INCLUDE_DIRS})
  534. else(ZLIB_FOUND)
  535. message("Shared zlib not found, falling back to the static library")
  536. add_subdirectory(Externals/zlib)
  537. include_directories(Externals/zlib)
  538. endif(ZLIB_FOUND)
  539. if(NOT APPLE AND NOT ANDROID)
  540. check_lib(LZO "(no .pc for lzo2)" lzo2 lzo/lzo1x.h QUIET)
  541. endif()
  542. if(LZO_FOUND)
  543. message("Using shared lzo")
  544. else()
  545. message("Using static lzo from Externals")
  546. add_subdirectory(Externals/LZO)
  547. include_directories(Externals/LZO)
  548. set(LZO lzo2)
  549. endif()
  550. list(APPEND LIBS ${LZO})
  551. if(NOT APPLE AND NOT ANDROID)
  552. check_lib(PNG libpng png png.h QUIET)
  553. endif()
  554. if (PNG_FOUND)
  555. message("Using shared libpng")
  556. else()
  557. message("Using static libpng from Externals")
  558. add_subdirectory(Externals/libpng)
  559. include_directories(Externals/libpng)
  560. set(PNG png)
  561. endif()
  562. if(OPENAL_FOUND)
  563. if(NOT APPLE)
  564. check_lib(SOUNDTOUCH soundtouch SoundTouch soundtouch/SoundTouch.h QUIET)
  565. endif()
  566. if (SOUNDTOUCH_FOUND)
  567. message("Using shared soundtouch")
  568. else()
  569. message("Using static soundtouch from Externals")
  570. add_subdirectory(Externals/soundtouch)
  571. include_directories(Externals)
  572. endif()
  573. endif()
  574. if(ENABLE_SDL)
  575. include(FindSDL2 OPTIONAL)
  576. if(SDL2_FOUND)
  577. message("Using shared SDL2")
  578. add_definitions(-DHAVE_SDL=1)
  579. include_directories(${SDL2_INCLUDE_DIR})
  580. else(SDL2_FOUND)
  581. # SDL2 not found, try SDL
  582. include(FindSDL OPTIONAL)
  583. if(SDL_FOUND)
  584. message("Using shared SDL")
  585. add_definitions(-DHAVE_SDL=1)
  586. include_directories(${SDL_INCLUDE_DIR})
  587. else(SDL_FOUND)
  588. message("SDL NOT found, disabling SDL input")
  589. endif(SDL_FOUND)
  590. endif(SDL2_FOUND)
  591. endif()
  592. include(FindLibUSB OPTIONAL)
  593. if(LIBUSB_FOUND)
  594. message("Using shared LibUSB")
  595. add_definitions(-D__LIBUSB__)
  596. include_directories(${LIBUSB_INCLUDE_DIR})
  597. endif(LIBUSB_FOUND)
  598. set(SFML_REQD_VERSION 2.1)
  599. if(NOT APPLE AND NOT ANDROID)
  600. find_package(SFML ${SFML_REQD_VERSION} COMPONENTS network system)
  601. endif()
  602. if(SFML_FOUND)
  603. message("Using shared SFML")
  604. else()
  605. message("Using static SFML ${SFML_REQD_VERSION} from Externals")
  606. add_definitions(-DSFML_STATIC)
  607. add_subdirectory(Externals/SFML)
  608. include_directories(BEFORE Externals/SFML/include)
  609. endif()
  610. if(USE_UPNP)
  611. if(NOT APPLE AND NOT ANDROID)
  612. include(FindMiniupnpc)
  613. endif()
  614. if(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER)
  615. message("Using shared miniupnpc")
  616. include_directories(${MINIUPNP_INCLUDE_DIR})
  617. else()
  618. message("Using static miniupnpc from Externals")
  619. add_subdirectory(Externals/miniupnpc)
  620. include_directories(Externals/miniupnpc/src)
  621. endif()
  622. add_definitions(-DUSE_UPNP)
  623. list(APPEND LIBS miniupnpc)
  624. endif()
  625. if(NOT APPLE AND NOT ANDROID)
  626. include(FindPolarSSL)
  627. endif()
  628. if(POLARSSL_FOUND AND POLARSSL_WORKS)
  629. message("Using shared PolarSSL")
  630. include_directories(${POLARSSL_INCLUDE_DIR})
  631. else()
  632. message("Using PolarSSL from Externals")
  633. set(POLARSSL_LIBRARY polarssl)
  634. add_subdirectory(Externals/polarssl/)
  635. include_directories(Externals/polarssl/include)
  636. endif()
  637. if(NOT APPLE AND NOT ANDROID)
  638. check_lib(SOIL "(no .pc for SOIL)" SOIL SOIL/SOIL.h QUIET)
  639. endif()
  640. if(SOIL_FOUND)
  641. message("Using shared SOIL")
  642. else()
  643. message("Using static SOIL from Externals")
  644. add_subdirectory(Externals/SOIL)
  645. include_directories(Externals/SOIL)
  646. endif()
  647. if (ANDROID)
  648. message("Using static iconv from Externals")
  649. include_directories(Externals/libiconv-1.14/include)
  650. add_subdirectory(Externals/libiconv-1.14)
  651. list(APPEND LIBS iconv)
  652. else()
  653. find_library(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c)
  654. find_path(ICONV_INCLUDE_DIR NAMES iconv.h)
  655. list(APPEND LIBS ${ICONV_LIBRARIES})
  656. mark_as_advanced(ICONV_INCLUDE_DIR ICONV_LIBRARIES)
  657. endif()
  658. if(ENABLE_QT)
  659. find_package(Qt5Widgets REQUIRED)
  660. message("Found Qt version ${Qt5Core_VERSION}, enabling the Qt backend")
  661. endif()
  662. if(NOT DISABLE_WX AND NOT ANDROID)
  663. include(FindwxWidgets OPTIONAL)
  664. FIND_PACKAGE(wxWidgets COMPONENTS core aui adv)
  665. if(wxWidgets_FOUND)
  666. EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  667. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
  668. ${wxWidgets_CONFIG_OPTIONS} --version
  669. OUTPUT_VARIABLE wxWidgets_VERSION
  670. OUTPUT_STRIP_TRAILING_WHITESPACE
  671. ERROR_QUIET
  672. )
  673. message("Found wxWidgets version ${wxWidgets_VERSION}")
  674. set(wxMIN_VERSION "3.0.1")
  675. if(${wxWidgets_VERSION} VERSION_LESS ${wxMIN_VERSION})
  676. message("At least ${wxMIN_VERSION} is required; ignoring found version")
  677. unset(wxWidgets_FOUND)
  678. endif()
  679. endif(wxWidgets_FOUND)
  680. if(UNIX AND NOT APPLE)
  681. # There is a bug in the FindGTK module in cmake version 2.8.2 that
  682. # does not find gdk-pixbuf-2.0. On the other hand some 2.8.3
  683. # users have complained that pkg-config does not find
  684. # gdk-pixbuf-2.0. On yet another hand, cmake version 2.8.3 in
  685. # Ubuntu Natty does not find the glib libraries correctly.
  686. # Ugly!!!
  687. execute_process(COMMAND lsb_release -c -s
  688. OUTPUT_VARIABLE DIST_NAME
  689. ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  690. if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}
  691. VERSION_EQUAL 2.8.2 OR "${DIST_NAME}" STREQUAL "natty")
  692. check_lib(GTK2 gtk+-2.0 gtk+-2.0 gtk.h REQUIRED)
  693. else()
  694. include(FindGTK2)
  695. if(GTK2_FOUND)
  696. include_directories(${GTK2_INCLUDE_DIRS})
  697. list(APPEND LIBS ${GTK2_LIBRARIES})
  698. else()
  699. message(FATAL_ERROR "GTK is required to build the WX UI. Please install the GTK development libraries.")
  700. endif()
  701. endif()
  702. endif()
  703. if(wxWidgets_FOUND)
  704. include(${wxWidgets_USE_FILE})
  705. message("wxWidgets found, enabling GUI build")
  706. else(wxWidgets_FOUND)
  707. message("Using static wxWidgets from Externals")
  708. # These definitions and includes are used when building dolphin against wx,
  709. # not when building wx itself (see wxw3 CMakeLists.txt for that)
  710. if(APPLE)
  711. add_definitions(-D__WXOSX_COCOA__)
  712. elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  713. add_definitions(-D__WXGTK__)
  714. # Check for required libs
  715. check_lib(GTHREAD2 gthread-2.0 gthread-2.0 glib/gthread.h REQUIRED)
  716. check_lib(PANGOCAIRO pangocairo pangocairo pango/pangocairo.h REQUIRED)
  717. elseif(WIN32)
  718. add_definitions(-D__WXMSW__)
  719. else()
  720. message(FATAL_ERROR "wxWidgets in Externals is not compatible with your platform")
  721. endif()
  722. include_directories(
  723. Externals/wxWidgets3
  724. Externals/wxWidgets3/include)
  725. add_subdirectory(Externals/wxWidgets3)
  726. set(wxWidgets_FOUND TRUE)
  727. set(wxWidgets_LIBRARIES "wx")
  728. endif(wxWidgets_FOUND)
  729. add_definitions(-DHAVE_WX=1)
  730. endif(NOT DISABLE_WX AND NOT ANDROID)
  731. if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD")
  732. set(LIBS ${LIBS} usbhid)
  733. endif()
  734. if(APPLE)
  735. # Link against OS X system frameworks.
  736. list(APPEND LIBS
  737. ${APPKIT_LIBRARY}
  738. ${AU_LIBRARY}
  739. ${COREAUDIO_LIBRARY}
  740. ${COREFUND_LIBRARY}
  741. ${CORESERV_LIBRARY}
  742. ${IOK_LIBRARY}
  743. ${FORCEFEEDBACK}
  744. )
  745. endif()
  746. ########################################
  747. # Pre-build events: Define configuration variables and write SCM info header
  748. #
  749. if(DOLPHIN_WC_BRANCH STREQUAL "master" OR DOLPHIN_WC_BRANCH STREQUAL "stable")
  750. set(DOLPHIN_WC_IS_STABLE "1")
  751. else()
  752. set(DOLPHIN_WC_IS_STABLE "0")
  753. endif()
  754. file(WRITE ${PROJECT_BINARY_DIR}/Source/Core/Common/scmrev.h
  755. "#define SCM_REV_STR \"" ${DOLPHIN_WC_REVISION} "\"\n"
  756. "#define SCM_DESC_STR \"" ${DOLPHIN_WC_DESCRIBE} "\"\n"
  757. "#define SCM_BRANCH_STR \"" ${DOLPHIN_WC_BRANCH} "\"\n"
  758. "#define SCM_IS_MASTER " ${DOLPHIN_WC_IS_STABLE} "\n"
  759. )
  760. include_directories("${PROJECT_BINARY_DIR}/Source/Core/Common")
  761. ########################################
  762. # Unit testing.
  763. #
  764. include_directories(Externals/gtest/include)
  765. add_subdirectory(Externals/gtest)
  766. enable_testing()
  767. add_custom_target(unittests)
  768. add_custom_command(TARGET unittests POST_BUILD COMMAND ${CMAKE_CTEST_COMMAND})
  769. ########################################
  770. # Start compiling our code
  771. #
  772. add_definitions(-std=gnu++0x)
  773. # These aren't actually needed for C11/C++11
  774. # but some dependencies require them (LLVM, libav).
  775. add_definitions(-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS)
  776. # Do this at the last minute because try_compile ignores linker flags. Yay...
  777. if(APPLE)
  778. # Some of our code contains Objective C constructs.
  779. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x objective-c -stdlib=libc++")
  780. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++ -stdlib=libc++")
  781. # Avoid mistaking an object file for a source file on the link command line.
  782. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -x none")
  783. endif()
  784. add_subdirectory(Source)
  785. ########################################
  786. # Install shared data files
  787. #
  788. if(NOT APPLE)
  789. install(DIRECTORY Data/Sys/ DESTINATION ${datadir}/sys PATTERN)
  790. endif()
  791. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|Darwin")
  792. install(FILES Data/license.txt DESTINATION ${datadir})
  793. endif()
  794. if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  795. # Install the application icon and menu item
  796. install(FILES Installer/dolphin-emu.xpm
  797. DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps)
  798. install(FILES Installer/dolphin-emu.desktop
  799. DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
  800. endif()
  801. # packaging information
  802. set(CPACK_PACKAGE_NAME "dolphin-emu")
  803. set(CPACK_PACKAGE_VENDOR "Dolphin Team")
  804. set(CPACK_PACKAGE_VERSION_MAJOR ${DOLPHIN_VERSION_MAJOR})
  805. set(CPACK_PACKAGE_VERSION_MINOR ${DOLPHIN_VERSION_MINOR})
  806. set(CPACK_PACKAGE_VERSION_PATCH ${DOLPHIN_VERSION_PATCH})
  807. set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/Data/cpack_package_description.txt)
  808. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A GameCube, Wii and Triforce emulator")
  809. set(CPACK_RPM_PACKAGE_GROUP System/Emulators/Other)
  810. set(CPACK_RPM_PACKAGE_LICENSE GPL-2.0)
  811. # TODO: CPACK_RESOURCE_FILE_README
  812. # TODO: CPACK_RESOURCE_FILE_WELCOME
  813. # TODO: CPACK_PACKAGE_ICON
  814. # TODO: CPACK_NSIS_*
  815. # TODO: Use CPack components for DSPSpy, etc => cpack_add_component
  816. set(CPACK_SET_DESTDIR ON)
  817. set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2;ZIP")
  818. set(CPACK_SOURCE_IGNORE_FILES "\\\\.#;/#;.*~;\\\\.swp;/\\\\.git")
  819. list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}")
  820. # CPack must be included after the CPACK_* variables are set in order for those
  821. # variables to take effect.
  822. Include(CPack)