CMakeLists.txt 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. ########################################
  2. # General setup
  3. #
  4. cmake_minimum_required(VERSION 2.6)
  5. option(ANDROID "Enables a build for Android" OFF)
  6. option(USE_EGL "Enables EGL OpenGL Interface" OFF)
  7. option(USE_X11 "Enables X11 Support" ON)
  8. option(USE_WAYLAND "Enables Wayland Support" OFF)
  9. option(USE_GLES "Enables GLES2 And EGL, disables OGL" OFF)
  10. option(USE_GLES3 "Enables GLES3 and EGL" OFF)
  11. option(USE_UPNP "Enables UPnP port mapping support" ON)
  12. option(DISABLE_WX "Disable wxWidgets (use CLI interface)" OFF)
  13. option(FASTLOG "Enable all logs" OFF)
  14. option(OPROFILING "Enable profiling" OFF)
  15. option(OPENMP "Enable OpenMP parallelization" ON)
  16. option(ENCODE_FRAMEDUMPS "Encode framedumps in AVI format" ON)
  17. ########################################
  18. # Optional Targets
  19. # TODO: Add DSPSpy and TestSuite.
  20. option(DSPTOOL "Build dsptool" OFF)
  21. option(UNITTESTS "Build unitests" OFF)
  22. # Update compiler before calling project()
  23. if (APPLE)
  24. # Use clang compiler
  25. set(CMAKE_C_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang")
  26. set(CMAKE_CXX_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++")
  27. if (NOT EXISTS "${CMAKE_CXX_COMPILER}")
  28. set(CMAKE_C_COMPILER "clang")
  29. set(CMAKE_CXX_COMPILER "clang++")
  30. endif()
  31. endif()
  32. project(dolphin-emu)
  33. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeTests)
  34. set(DOLPHIN_IS_STABLE TRUE)
  35. # Set up paths
  36. if((${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
  37. # The gettext module will install the translations unconditionally.
  38. # Redirect the installation to a build directory where it does no harm.
  39. set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install-dummy)
  40. else()
  41. set(bindir ${CMAKE_INSTALL_PREFIX}/bin CACHE PATH "bindir")
  42. set(datadir ${CMAKE_INSTALL_PREFIX}/share/dolphin-emu CACHE PATH "datadir")
  43. add_definitions(-DDATA_DIR="${datadir}/")
  44. endif()
  45. set(userdir ".dolphin-emu" CACHE STRING "User directory")
  46. add_definitions(-DUSER_DIR="${userdir}")
  47. # Set where the binary files will be built. The program will not execute from
  48. # here. You must run "make install" to install these to the proper location
  49. # as defined above.
  50. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Binaries)
  51. # Precompiled header support for MSVC:
  52. # Call this after setting the source list (and don't add the source file used
  53. # to generate the pch file, this will be done here automatically)
  54. function(enable_precompiled_headers PRECOMPILED_HEADER SOURCE_FILE SOURCE_VARIABLE_NAME)
  55. if(MSVC)
  56. set(files ${${SOURCE_VARIABLE_NAME}})
  57. # Generate precompiled header translation unit
  58. get_filename_component(pch_basename ${PRECOMPILED_HEADER} NAME_WE)
  59. set(pch_abs ${CMAKE_CURRENT_SOURCE_DIR}/${PRECOMPILED_HEADER})
  60. set(pch_unity ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE})
  61. set_source_files_properties(${pch_unity} PROPERTIES COMPILE_FLAGS
  62. "/Yc\"${pch_abs}\"")
  63. # Update properties of source files to use the precompiled header.
  64. # Additionally, force the inclusion of the precompiled header at
  65. # beginning of each source file.
  66. foreach(source_file ${files} )
  67. set_source_files_properties(${source_file} PROPERTIES COMPILE_FLAGS
  68. "/Yu\"${pch_abs}\" /FI\"${pch_abs}\"")
  69. endforeach(source_file)
  70. # Finally, update the source file collection to contain the
  71. # precompiled header translation unit
  72. set(${SOURCE_VARIABLE_NAME} ${pch_unity} ${${SOURCE_VARIABLE_NAME}} PARENT_SCOPE)
  73. endif(MSVC)
  74. endfunction(enable_precompiled_headers)
  75. # for revision info
  76. include(FindGit OPTIONAL)
  77. if(GIT_FOUND AND NOT DOLPHIN_WC_REVISION)
  78. # defines DOLPHIN_WC_REVISION
  79. EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
  80. OUTPUT_VARIABLE DOLPHIN_WC_REVISION
  81. OUTPUT_STRIP_TRAILING_WHITESPACE)
  82. # defines DOLPHIN_WC_DESCRIBE
  83. EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --always --long --dirty
  84. OUTPUT_VARIABLE DOLPHIN_WC_DESCRIBE
  85. OUTPUT_STRIP_TRAILING_WHITESPACE)
  86. # remove hash (and trailing "-0" if needed) from description
  87. STRING(REGEX REPLACE "(-0)?-[^-]+((-dirty)?)$" "\\2" DOLPHIN_WC_DESCRIBE "${DOLPHIN_WC_DESCRIBE}")
  88. # defines DOLPHIN_WC_BRANCH
  89. EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
  90. OUTPUT_VARIABLE DOLPHIN_WC_BRANCH
  91. OUTPUT_STRIP_TRAILING_WHITESPACE)
  92. endif()
  93. # version number
  94. set(DOLPHIN_VERSION_MAJOR "4")
  95. set(DOLPHIN_VERSION_MINOR "0")
  96. if(DOLPHIN_IS_STABLE)
  97. set(DOLPHIN_VERSION_PATCH "0")
  98. else()
  99. set(DOLPHIN_VERSION_PATCH ${DOLPHIN_WC_REVISION})
  100. endif()
  101. message(${CMAKE_SYSTEM_PROCESSOR})
  102. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
  103. set(_M_GENERIC 1)
  104. set(_M_ARM 1)
  105. add_definitions(-marm -march=armv7-a)
  106. add_definitions(-D_M_ARM=1)
  107. add_definitions(-D_M_GENERIC=1)
  108. # Set generic options so you don't have to pass anything to cmake to build ARM
  109. set(USE_GLES 1)
  110. endif()
  111. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
  112. set(_M_GENERIC 1)
  113. set(_M_MIPS 1)
  114. add_definitions(-D_M_MIPS=1)
  115. add_definitions(-D_M_GENERIC=1)
  116. endif()
  117. # Set these next two lines to test generic
  118. #set(_M_GENERIC 1)
  119. #add_definitions(-D_M_GENERIC=1)
  120. # Various compile flags
  121. if(NOT _M_GENERIC)
  122. add_definitions(-msse2)
  123. endif()
  124. include(CheckCXXCompilerFlag)
  125. macro(check_and_add_flag var flag)
  126. CHECK_CXX_COMPILER_FLAG(${flag} FLAG_${var})
  127. if(FLAG_${var})
  128. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  129. endif()
  130. endmacro()
  131. # Enabling all warnings in MSVC spams too much
  132. if(NOT MSVC)
  133. add_definitions(-Wall)
  134. # TODO: would like these but they produce overwhelming amounts of warnings
  135. #check_and_add_flag(EXTRA -Wextra)
  136. #check_and_add_flag(MISSING_FIELD_INITIALIZERS -Wmissing-field-initializers)
  137. #check_and_add_flag(SWITCH_DEFAULT -Wswitch-default)
  138. #check_and_add_flag(FLOAT_EQUAL -Wfloat-equal)
  139. #check_and_add_flag(CONVERSION -Wconversion)
  140. #check_and_add_flag(ZERO_AS_NULL_POINTER_CONSTANT -Wzero-as-null-pointer-constant)
  141. check_and_add_flag(TYPE_LIMITS -Wtype-limits)
  142. check_and_add_flag(SIGN_COMPARE -Wsign-compare)
  143. check_and_add_flag(IGNORED_QUALIFIERS -Wignored-qualifiers)
  144. check_and_add_flag(UNINITIALIZED -Wuninitialized)
  145. check_and_add_flag(LOGICAL_OP -Wlogical-op)
  146. check_and_add_flag(SHADOW -Wshadow)
  147. check_and_add_flag(INIT_SELF -Winit-self)
  148. endif(NOT MSVC)
  149. # gcc uses some optimizations which might break stuff without this flag
  150. add_definitions(-fno-strict-aliasing -fno-exceptions)
  151. check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-hidden)
  152. if(UNIX AND NOT APPLE)
  153. check_and_add_flag(VISIBILITY_HIDDEN -fvisibility=hidden)
  154. endif()
  155. if(APPLE)
  156. # Ignore MacPorts and Fink and any other locally installed packages that
  157. # might prevent building a distributable binary.
  158. set(CMAKE_SYSTEM_PREFIX_PATH /usr)
  159. set(ENV{PATH} /usr/bin:/bin:/usr/sbin:/sbin)
  160. # Some of our code contains Objective C constructs.
  161. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x objective-c -stdlib=libc++")
  162. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++ -stdlib=libc++")
  163. # Avoid mistaking an object file for a source file on the link command line.
  164. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -x none")
  165. # Identify the target system:
  166. # Ask for 64-bit binary.
  167. set(TARGET_FLAGS "-arch x86_64")
  168. # Minimum OS X version.
  169. # This is inserted into the Info.plist as well.
  170. # Note that the SDK determines the maximum version of which optional
  171. # features can be used, not the minimum required version to run.
  172. set(OSX_MIN_VERSION "10.7")
  173. set(TARGET_FLAGS "${TARGET_FLAGS} -mmacosx-version-min=${OSX_MIN_VERSION}")
  174. set(SYSROOT_LEGACY_PATH "/Developer/SDKs/MacOSX10.7.sdk")
  175. set(SYSROOT_PATH "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk")
  176. if(EXISTS "${SYSROOT_PATH}/")
  177. set(TARGET_SYSROOT ${SYSROOT_PATH})
  178. elseif(EXISTS "${SYSROOT_LEGACY_PATH}/")
  179. set(TARGET_SYSROOT ${SYSROOT_LEGACY_PATH})
  180. endif()
  181. if(${TARGET_SYSROOT})
  182. set(TARGET_FLAGS "${TARGET_FLAGS} -isysroot ${TARGET_SYSROOT}")
  183. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-syslibroot,${TARGET_SYSROOT}")
  184. endif()
  185. # Do not warn about frameworks that are not available on all architectures.
  186. # This avoids a warning when linking with QuickTime.
  187. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-no_arch_warnings")
  188. # Specify target CPUs.
  189. set(TARGET_FLAGS "${TARGET_FLAGS} -mssse3")
  190. set(TARGET_FLAGS "${TARGET_FLAGS} -march=core2")
  191. # Target flags apply to both C and C++ compilation.
  192. # CMake passes these to the compiler on the link command line as well.
  193. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}")
  194. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TARGET_FLAGS}")
  195. # Linker flags.
  196. # Drop unreachable code and data.
  197. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip,-dead_strip_dylibs")
  198. # Reserve the minimum size for the zero page.
  199. # Our JIT requires virtual memory space below 2GB, while the default zero
  200. # page on x86_64 is 4GB in size.
  201. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-pagezero_size,0x1000")
  202. if(NOT DISABLE_WX)
  203. add_definitions(-DUSE_WX -DHAVE_WX)
  204. set(USE_WX TRUE)
  205. endif()
  206. find_library(APPKIT_LIBRARY AppKit)
  207. find_library(APPSERV_LIBRARY ApplicationServices)
  208. find_library(ATB_LIBRARY AudioToolbox)
  209. find_library(AU_LIBRARY AudioUnit)
  210. find_library(CARBON_LIBRARY Carbon)
  211. find_library(COCOA_LIBRARY Cocoa)
  212. find_library(COREAUDIO_LIBRARY CoreAudio)
  213. find_library(COREFUND_LIBRARY CoreFoundation)
  214. find_library(CORESERV_LIBRARY CoreServices)
  215. find_library(IOB_LIBRARY IOBluetooth)
  216. find_library(IOK_LIBRARY IOKit)
  217. find_library(QUICKTIME_LIBRARY QuickTime)
  218. find_library(WEBKIT_LIBRARY WebKit)
  219. endif()
  220. if(WIN32)
  221. add_definitions(-D_SECURE_SCL=0)
  222. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  223. add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  224. endif(WIN32)
  225. if(NOT CMAKE_BUILD_TYPE)
  226. set(CMAKE_BUILD_TYPE "Release" CACHE STRING
  227. "Build type (Release/Debug/RelWithDebInfo/MinSizeRe)" FORCE)
  228. endif(NOT CMAKE_BUILD_TYPE)
  229. if(CMAKE_BUILD_TYPE STREQUAL Debug)
  230. add_definitions(-D_DEBUG -ggdb)
  231. set(wxWidgets_USE_DEBUG ON CACHE BOOL "Use wxWidgets Debugging")
  232. option(ENABLE_GPROF "Enable gprof profiling (must be using Debug build)" OFF)
  233. if(ENABLE_GPROF)
  234. add_definitions(-pg)
  235. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
  236. endif()
  237. endif(CMAKE_BUILD_TYPE STREQUAL Debug)
  238. if(CMAKE_BUILD_TYPE STREQUAL Release AND NOT APPLE)
  239. add_definitions(-fomit-frame-pointer)
  240. endif()
  241. if(FASTLOG)
  242. add_definitions(-DDEBUGFAST)
  243. endif()
  244. option(GDBSTUB "Enable gdb stub for remote debugging." OFF)
  245. if(GDBSTUB)
  246. add_definitions(-DUSE_GDBSTUB)
  247. endif(GDBSTUB)
  248. if(ANDROID)
  249. message("Building for Android")
  250. add_definitions(-DANDROID)
  251. set(USE_X11 0)
  252. set(USE_WAYLAND 0)
  253. set(USE_UPNP 0)
  254. set(USE_GLES3 1)
  255. endif()
  256. # For now GLES and EGL are tied to each other.
  257. # Enabling GLES also disables the OpenGL plugin.
  258. if(USE_GLES3)
  259. message("GLES3 rendering enabled")
  260. add_definitions(-DUSE_GLES=1 -DUSE_EGL=1 -DUSE_GLES3=1)
  261. include_directories(Externals/GLES3)
  262. set(USE_EGL True)
  263. set(USE_GLES True)
  264. else()
  265. if(USE_GLES)
  266. message("GLES2 rendering enabled. OpenGL disabled")
  267. add_definitions(-DUSE_GLES=1)
  268. add_definitions(-DUSE_EGL=1)
  269. set(USE_EGL True)
  270. endif()
  271. endif()
  272. # For now Wayland and EGL are tied to each other.
  273. # The alternative would be an shm path
  274. if(USE_WAYLAND)
  275. add_definitions(-DUSE_EGL)
  276. set(USE_EGL 1)
  277. endif()
  278. if(USE_EGL)
  279. message("EGL OpenGL interface enabled")
  280. add_definitions(-DUSE_EGL=1)
  281. else()
  282. # Using GLX
  283. set(USE_X11 1)
  284. set(USE_WAYLAND 0)
  285. endif()
  286. add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
  287. ########################################
  288. # Dependency checking
  289. #
  290. # TODO: We should have options for dependencies included in the externals to
  291. # override autodetection of system libraries and force the usage of the
  292. # externals.
  293. include(CheckLib)
  294. include(CheckCXXSourceRuns)
  295. if(NOT ANDROID)
  296. include(FindOpenGL)
  297. include_directories(${OPENGL_INCLUDE_DIR})
  298. if(NOT OPENGL_GLU_FOUND)
  299. message(FATAL_ERROR "GLU is required but not found")
  300. endif()
  301. if(OPENMP)
  302. include(FindOpenMP OPTIONAL)
  303. if(OPENMP_FOUND)
  304. message("OpenMP parallelization enabled")
  305. add_definitions("${OpenMP_CXX_FLAGS}")
  306. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}")
  307. endif()
  308. endif()
  309. if(NOT OPENMP_FOUND)
  310. add_definitions(-Wno-unknown-pragmas)
  311. message("OpenMP parallelization disabled")
  312. endif()
  313. include(FindALSA OPTIONAL)
  314. if(ALSA_FOUND)
  315. add_definitions(-DHAVE_ALSA=1)
  316. message("ALSA found, enabling ALSA sound backend")
  317. else()
  318. add_definitions(-DHAVE_ALSA=0)
  319. message("ALSA NOT found, disabling ALSA sound backend")
  320. endif(ALSA_FOUND)
  321. check_lib(AO ao QUIET)
  322. if(AO_FOUND)
  323. add_definitions(-DHAVE_AO=1)
  324. message("ao found, enabling ao sound backend")
  325. else()
  326. add_definitions(-DHAVE_AO=0)
  327. message("ao NOT found, disabling ao sound backend")
  328. endif(AO_FOUND)
  329. check_lib(BLUEZ bluez QUIET)
  330. if(BLUEZ_FOUND)
  331. add_definitions(-DHAVE_BLUEZ=1)
  332. message("bluez found, enabling bluetooth support")
  333. else()
  334. add_definitions(-DHAVE_BLUEZ=0)
  335. message("bluez NOT found, disabling bluetooth support")
  336. endif(BLUEZ_FOUND)
  337. check_lib(PULSEAUDIO libpulse-simple QUIET)
  338. if(PULSEAUDIO_FOUND)
  339. add_definitions(-DHAVE_PULSEAUDIO=1)
  340. message("PulseAudio found, enabling PulseAudio sound backend")
  341. else()
  342. add_definitions(-DHAVE_PULSEAUDIO=0)
  343. message("PulseAudio NOT found, disabling PulseAudio sound backend")
  344. endif(PULSEAUDIO_FOUND)
  345. include(FindOpenAL OPTIONAL)
  346. if(OPENAL_FOUND)
  347. add_definitions(-DHAVE_OPENAL=1)
  348. include_directories(${OPENAL_INCLUDE_DIR})
  349. message("OpenAL found, enabling OpenAL sound backend")
  350. else()
  351. add_definitions(-DHAVE_OPENAL=0)
  352. message("OpenAL NOT found, disabling OpenAL sound backend")
  353. endif(OPENAL_FOUND)
  354. if(UNIX AND NOT APPLE)
  355. # Note: The convention is to check USE_X11 or USE_WAYLAND where needed.
  356. # This is where we detect platforms and set the variables accordingly.
  357. pkg_check_modules(WAYLAND wayland-egl wayland-client wayland-cursor)
  358. if(USE_WAYLAND AND WAYLAND_FOUND)
  359. pkg_check_modules(XKBCOMMON xkbcommon)
  360. if(XKBCOMMON_FOUND)
  361. set(USE_WAYLAND 1)
  362. add_definitions(-DHAVE_WAYLAND)
  363. include_directories(${WAYLAND_INCLUDE_DIR})
  364. message("Wayland support enabled")
  365. endif(XKBCOMMON_FOUND)
  366. else()
  367. set(USE_WAYLAND 0)
  368. message("Wayland support disabled")
  369. add_definitions(-DHAVE_WAYLAND=0)
  370. endif(USE_WAYLAND AND WAYLAND_FOUND)
  371. # Note: We do not need to explicitly check for X11 as it is done in the cmake
  372. # FindOpenGL module on linux.
  373. if(USE_X11 AND X11_FOUND)
  374. set(USE_X11 1)
  375. add_definitions(-DHAVE_X11=1)
  376. include_directories(${X11_INCLUDE_DIR})
  377. message("X11 support enabled")
  378. else()
  379. set(USE_X11 0)
  380. SET(X11_FOUND "")
  381. message("X11 support disabled")
  382. add_definitions(-DHAVE_X11=0)
  383. endif(USE_X11 AND X11_FOUND)
  384. if (NOT USE_WAYLAND AND NOT USE_X11)
  385. message(FATAL_ERROR "\n"
  386. "No suitable display platform found\n"
  387. "Requires wayland or x11 to run")
  388. endif()
  389. endif()
  390. if(USE_X11)
  391. check_lib(XRANDR Xrandr)
  392. if(XRANDR_FOUND)
  393. add_definitions(-DHAVE_XRANDR=1)
  394. else()
  395. add_definitions(-DHAVE_XRANDR=0)
  396. endif(XRANDR_FOUND)
  397. pkg_check_modules(XINPUT2 xi>=1.5.0)
  398. if(XINPUT2_FOUND)
  399. add_definitions(-DHAVE_X11_XINPUT2=1)
  400. else()
  401. add_definitions(-DHAVE_X11_XINPUT2=0)
  402. endif(XINPUT2_FOUND)
  403. endif()
  404. if(ENCODE_FRAMEDUMPS)
  405. check_libav()
  406. endif()
  407. set(CMAKE_REQUIRED_LIBRARIES portaudio)
  408. CHECK_CXX_SOURCE_RUNS(
  409. "#include <portaudio.h>
  410. int main(int argc, char **argv)
  411. { if(Pa_GetVersion() >= 1890) return 0; else return 1; }"
  412. PORTAUDIO)
  413. if(PORTAUDIO)
  414. message("PortAudio found, enabling mic support")
  415. add_definitions(-DHAVE_PORTAUDIO=1)
  416. set(PORTAUDIO_FOUND TRUE)
  417. else()
  418. message("PortAudio not found, disabling mic support")
  419. add_definitions(-DHAVE_PORTAUDIO=0)
  420. set(PORTAUDIO_FOUND FALSE)
  421. endif(PORTAUDIO)
  422. if(OPROFILING)
  423. check_lib(OPROFILE opagent opagent.h)
  424. check_lib(BFD bfd bfd.h)
  425. if(OPROFILE_FOUND AND BFD_FOUND)
  426. message("oprofile found, enabling profiling support")
  427. add_definitions(-DUSE_OPROFILE=1)
  428. else()
  429. message(FATAL_ERROR "oprofile or bfd not found. Can't build profiling support.")
  430. endif()
  431. endif()
  432. endif()
  433. ########################################
  434. # Setup include directories (and make sure they are preferred over the Externals)
  435. #
  436. include_directories(Source/Core/AudioCommon/Src)
  437. include_directories(Source/Core/Common/Src)
  438. include_directories(Source/Core/Core/Src)
  439. include_directories(Source/Core/DebuggerUICommon/Src)
  440. include_directories(Source/Core/DebuggerWX/Src)
  441. include_directories(Source/Core/DiscIO/Src)
  442. include_directories(Source/Core/DolphinWX/Src)
  443. include_directories(Source/Core/InputCommon/Src)
  444. include_directories(Source/Core/VideoCommon/Src)
  445. include_directories(Source/Core/VideoUICommon/Src)
  446. ########################################
  447. # Process externals and setup their include directories
  448. #
  449. # NOTES about adding Externals:
  450. # - add the include directory here
  451. # - make sure to tell cmake to link them statically or dynamically (most
  452. # should be linked statically)
  453. # - place the CMakeLists.txt in the first-level subdirectory, e.g.
  454. # Externals/CLRun/CMakeLists.txt (that is: NOT in some Src/ subdirectory)
  455. #
  456. add_subdirectory(Externals/Bochs_disasm)
  457. include_directories(Externals/Bochs_disasm)
  458. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ANDROID)
  459. check_lib(LZO lzo2 lzo/lzo1x.h QUIET)
  460. endif()
  461. if(LZO_FOUND)
  462. message("Using shared lzo")
  463. else()
  464. message("Using static lzo from Externals")
  465. add_subdirectory(Externals/LZO)
  466. include_directories(Externals/LZO)
  467. set(LZO lzo2)
  468. endif()
  469. if(ANDROID)
  470. message("Using static libpng from Externals")
  471. add_subdirectory(Externals/libpng)
  472. include_directories(Externals/libpng)
  473. set(PNG libpng)
  474. endif()
  475. if(OPENAL_FOUND)
  476. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  477. check_lib(SOUNDTOUCH SoundTouch soundtouch/soundtouch.h QUIET)
  478. endif()
  479. if (SOUNDTOUCH_FOUND)
  480. message("Using shared soundtouch")
  481. else()
  482. message("Using static soundtouch from Externals")
  483. add_subdirectory(Externals/soundtouch)
  484. include_directories(Externals)
  485. endif()
  486. endif()
  487. if(NOT ANDROID)
  488. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  489. include(FindSDL2 OPTIONAL)
  490. endif()
  491. if(SDL2_FOUND)
  492. message("Using shared SDL2")
  493. include_directories(${SDL2_INCLUDE_DIR})
  494. else(SDL2_FOUND)
  495. # SDL2 not found, try SDL
  496. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  497. include(FindSDL OPTIONAL)
  498. endif()
  499. if(SDL_FOUND)
  500. message("Using shared SDL")
  501. include_directories(${SDL_INCLUDE_DIR})
  502. else(SDL_FOUND)
  503. # TODO: Use the prebuilt one on Windows
  504. message("Using static SDL from Externals")
  505. include_directories(Externals/SDL/SDL Externals/SDL Externals/SDL/include)
  506. add_subdirectory(Externals/SDL)
  507. endif(SDL_FOUND)
  508. endif(SDL2_FOUND)
  509. endif()
  510. include(FindLibUSB OPTIONAL)
  511. if(LIBUSB_FOUND)
  512. message("Using shared LibUSB")
  513. add_definitions(-D__LIBUSB__)
  514. include_directories(${LIBUSB_INCLUDE_DIR})
  515. endif(LIBUSB_FOUND)
  516. set(SFML_FIND_VERSION TRUE)
  517. set(SFML_FIND_VERSION_MAJOR 1)
  518. set(SFML_FIND_VERSION_MINOR 5)
  519. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ANDROID)
  520. include(FindSFML OPTIONAL)
  521. endif()
  522. if(SFML_FOUND AND NOT SFML_VERSION_MAJOR) # SFML 1.x doesn't define SFML_VERSION_MAJOR
  523. message("Using shared SFML")
  524. else()
  525. message("Using static SFML ${SFML_FIND_VERSION_MAJOR}.${SFML_FIND_VERSION_MINOR} from Externals")
  526. add_subdirectory(Externals/SFML)
  527. include_directories(Externals/SFML/include)
  528. endif()
  529. if(USE_UPNP)
  530. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ANDROID)
  531. include(FindMiniupnpc)
  532. endif()
  533. if(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER)
  534. message("Using shared miniupnpc")
  535. include_directories(${MINIUPNP_INCLUDE_DIR})
  536. else()
  537. message("Using static miniupnpc from Externals")
  538. add_subdirectory(Externals/miniupnpc)
  539. include_directories(Externals/miniupnpc/src)
  540. endif()
  541. add_definitions(-DUSE_UPNP)
  542. endif()
  543. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ANDROID)
  544. include(FindPolarSSL)
  545. endif()
  546. if(POLARSSL_FOUND AND POLARSSL_WORKS)
  547. message("Using shared PolarSSL")
  548. include_directories(${POLARSSL_INCLUDE_DIR})
  549. else()
  550. message("Using PolarSSL from Externals")
  551. set(POLARSSL_LIBRARY polarssl)
  552. add_subdirectory(Externals/polarssl/)
  553. include_directories(Externals/polarssl/include)
  554. endif()
  555. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ANDROID)
  556. check_lib(SOIL SOIL SOIL/SOIL.h QUIET)
  557. endif()
  558. if(SOIL_FOUND)
  559. message("Using shared SOIL")
  560. else()
  561. message("Using static SOIL from Externals")
  562. add_subdirectory(Externals/SOIL)
  563. include_directories(Externals/SOIL)
  564. endif()
  565. # If zlib has already been found on a previous run of cmake don't check again
  566. # as the check seems to take a long time.
  567. if(NOT ZLIB_FOUND)
  568. include(FindZLIB OPTIONAL)
  569. endif()
  570. if(ZLIB_FOUND)
  571. set(ZLIB_FOUND 1 CACHE INTERNAL "")
  572. message("Using shared zlib")
  573. include_directories(${ZLIB_INCLUDE_DIRS})
  574. else(ZLIB_FOUND)
  575. message("Shared zlib not found, falling back to the static library")
  576. add_subdirectory(Externals/zlib)
  577. include_directories(Externals/zlib)
  578. endif(ZLIB_FOUND)
  579. if(WIN32)
  580. find_library(GLEW glew32s PATHS Externals/GLew)
  581. include_directories(Externals/GLew/include)
  582. else()
  583. if(NOT USE_GLES3)
  584. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  585. include(FindGLEW)
  586. endif()
  587. if(NOT GLEW_FOUND OR NOT GLEW_HAS_1_9_METHODS)
  588. message("Using static GLEW from Externals")
  589. add_subdirectory(Externals/GLew)
  590. include_directories(Externals/GLew/include)
  591. endif()
  592. endif()
  593. endif()
  594. if (ANDROID)
  595. message("Using static iconv from Externals")
  596. include_directories(Externals/libiconv-1.14/include)
  597. add_subdirectory(Externals/libiconv-1.14)
  598. endif()
  599. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ANDROID)
  600. find_library(CL OpenCL)
  601. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-weak_framework,OpenCL")
  602. else()
  603. include_directories(Externals/CLRun/include)
  604. add_subdirectory(Externals/CLRun)
  605. endif()
  606. if(NOT DISABLE_WX AND NOT ANDROID)
  607. include(FindwxWidgets OPTIONAL)
  608. FIND_PACKAGE(wxWidgets COMPONENTS core aui adv)
  609. if(wxWidgets_FOUND)
  610. EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  611. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
  612. ${wxWidgets_CONFIG_OPTIONS} --version
  613. OUTPUT_VARIABLE wxWidgets_VERSION
  614. OUTPUT_STRIP_TRAILING_WHITESPACE
  615. ERROR_QUIET
  616. )
  617. message("Found wxWidgets version ${wxWidgets_VERSION}")
  618. if(UNIX AND NOT APPLE)
  619. set(wxMIN_VERSION "2.9.3")
  620. else()
  621. set(wxMIN_VERSION "2.9.4")
  622. endif()
  623. if(${wxWidgets_VERSION} VERSION_LESS ${wxMIN_VERSION})
  624. message("At least ${wxMIN_VERSION} is required; ignoring found version")
  625. unset(wxWidgets_FOUND)
  626. endif()
  627. endif(wxWidgets_FOUND)
  628. if(UNIX AND NOT APPLE)
  629. # There is a bug in the FindGTK module in cmake version 2.8.2 that
  630. # does not find gdk-pixbuf-2.0. On the other hand some 2.8.3
  631. # users have complained that pkg-config does not find
  632. # gdk-pixbuf-2.0. On yet another hand, cmake version 2.8.3 in
  633. # Ubuntu Natty does not find the glib libraries correctly.
  634. # Ugly!!!
  635. execute_process(COMMAND lsb_release -c -s
  636. OUTPUT_VARIABLE DIST_NAME
  637. ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  638. if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}
  639. VERSION_EQUAL 2.8.2 OR "${DIST_NAME}" STREQUAL "natty")
  640. check_lib(GTK2 gtk+-2.0 gtk.h REQUIRED)
  641. else()
  642. include(FindGTK2)
  643. if(GTK2_FOUND)
  644. include_directories(${GTK2_INCLUDE_DIRS})
  645. endif()
  646. endif()
  647. endif()
  648. if(wxWidgets_FOUND)
  649. include(${wxWidgets_USE_FILE})
  650. message("wxWidgets found, enabling GUI build")
  651. else(wxWidgets_FOUND)
  652. message("Using static wxWidgets from Externals")
  653. # These definitions and includes are used when building dolphin against wx,
  654. # not when building wx itself (see wxw3 CMakeLists.txt for that)
  655. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  656. add_definitions(-D__WXOSX_COCOA__)
  657. elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  658. add_definitions(-D__WXGTK__)
  659. # Check for required libs
  660. check_lib(GTHREAD2 gthread-2.0 glib/gthread.h REQUIRED)
  661. check_lib(PANGOCAIRO pangocairo pango/pangocairo.h REQUIRED)
  662. elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  663. add_definitions(-D__WXMSW__)
  664. else()
  665. message(FATAL_ERROR "wxWidgets in Externals is not compatible with your platform")
  666. endif()
  667. include_directories(
  668. Externals/wxWidgets3
  669. Externals/wxWidgets3/include)
  670. add_subdirectory(Externals/wxWidgets3)
  671. set(wxWidgets_FOUND TRUE)
  672. set(wxWidgets_LIBRARIES "wx")
  673. endif(wxWidgets_FOUND)
  674. add_definitions(-DHAVE_WX=1)
  675. endif(NOT DISABLE_WX AND NOT ANDROID)
  676. ########################################
  677. # Pre-build events: Define configuration variables and write SCM info header
  678. #
  679. if(DOLPHIN_WC_BRANCH STREQUAL "master" OR DOLPHIN_WC_BRANCH STREQUAL "stable")
  680. set(DOLPHIN_WC_IS_STABLE "1")
  681. else()
  682. set(DOLPHIN_WC_IS_STABLE "0")
  683. endif()
  684. file(WRITE ${PROJECT_BINARY_DIR}/Source/Core/Common/Src/scmrev.h
  685. "#define SCM_REV_STR \"" ${DOLPHIN_WC_REVISION} "\"\n"
  686. "#define SCM_DESC_STR \"" ${DOLPHIN_WC_DESCRIBE} "\"\n"
  687. "#define SCM_BRANCH_STR \"" ${DOLPHIN_WC_BRANCH} "\"\n"
  688. "#define SCM_IS_MASTER " ${DOLPHIN_WC_IS_STABLE} "\n"
  689. )
  690. include_directories("${PROJECT_BINARY_DIR}/Source/Core/Common/Src")
  691. ########################################
  692. # Start compiling our code
  693. #
  694. add_definitions(-std=gnu++0x)
  695. add_subdirectory(Source)
  696. ########################################
  697. # Install shared data files
  698. #
  699. if((NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
  700. install(DIRECTORY Data/Sys/ DESTINATION ${datadir}/sys PATTERN)
  701. endif()
  702. if((NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|Darwin"))
  703. install(FILES Data/license.txt DESTINATION ${datadir})
  704. endif()
  705. if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  706. # Install the application icon and menu item
  707. install(FILES Source/Core/DolphinWX/resources/Dolphin.xpm
  708. DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps RENAME dolphin-emu.xpm)
  709. install(FILES Source/Core/DolphinWX/resources/dolphin-emu.desktop
  710. DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
  711. endif()
  712. # packaging information
  713. set(CPACK_PACKAGE_NAME "dolphin-emu")
  714. set(CPACK_PACKAGE_VENDOR "Dolphin Team")
  715. set(CPACK_PACKAGE_VERSION_MAJOR ${DOLPHIN_VERSION_MAJOR})
  716. set(CPACK_PACKAGE_VERSION_MINOR ${DOLPHIN_VERSION_MINOR})
  717. set(CPACK_PACKAGE_VERSION_PATCH ${DOLPHIN_VERSION_PATCH})
  718. set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/Data/cpack_package_description.txt)
  719. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A Gamecube, Wii and Triforce emulator")
  720. set(CPACK_RPM_PACKAGE_GROUP System/Emulators/Other)
  721. set(CPACK_RPM_PACKAGE_LICENSE GPL-2.0)
  722. # TODO: CPACK_RESOURCE_FILE_README
  723. # TODO: CPACK_RESOURCE_FILE_WELCOME
  724. # TODO: CPACK_PACKAGE_ICON
  725. # TODO: CPACK_NSIS_*
  726. # TODO: Use CPack components for DSPSpy, etc => cpack_add_component
  727. set(CPACK_SET_DESTDIR ON)
  728. set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2;ZIP")
  729. set(CPACK_SOURCE_IGNORE_FILES "\\\\.#;/#;.*~;\\\\.swp;/\\\\.git")
  730. list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}")
  731. # CPack must be included after the CPACK_* variables are set in order for those
  732. # variables to take effect.
  733. Include(CPack)