Setup opencl to work like most of the other externals. Autodetect native shared...
[dolphin.git] / CMakeLists.txt
blobd535e82f14eb2112d808b2aded7267e343d3cb11
1 ########################################
2 # General setup
4 cmake_minimum_required(VERSION 2.6)
5 project(dolphin-emu)
6 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeTests)
8 set(DOLPHIN_IS_STABLE FALSE)
9 set(prefix              ${CMAKE_INSTALL_PREFIX}                                         CACHE PATH "prefix")
10 set(bindir              ${CMAKE_INSTALL_PREFIX}/bin                                     CACHE PATH "bindir")
11 set(libdir              ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}        CACHE PATH "libdir")
12 set(plugindir   ${libdir}/dolphin-emu                                           CACHE PATH "plugindir")
13 set(datadir             ${CMAKE_INSTALL_PREFIX}/share/dolphin-emu       CACHE PATH "datadir")
15 # Set up paths
16 set(userdir ".dolphin-emu" CACHE STRING "User directory")
17 add_definitions(-DUSER_DIR="${userdir}")
18 add_definitions(-DDATA_DIR="${datadir}/")
19 add_definitions(-DLIBS_DIR="${plugindir}/")
21 # These just set where the binary files will be built.  The program will not
22 # execute from here.  You must run "make install" to install these to the
23 # proper location as defined above.
24 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Binaries)
25 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Binaries/plugins)
27 include(FindSubversion OPTIONAL) # for revision info
28 if(Subversion_FOUND)
29         Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} DOLPHIN) # defines DOLPHIN_WC_REVISION
30 endif()
32 # TODO: Make this optional or even implement our own package detection
33 include(FindPkgConfig REQUIRED)
35 # Various compile flags
36 add_definitions(-msse2 -Wall -Wno-unused-result)
38 # gcc uses some optimizations which might break stuff without this flag
39 add_definitions(-fno-strict-aliasing -fno-exceptions)
41 include(CheckCXXCompilerFlag)
42 CHECK_CXX_COMPILER_FLAG(-fvisibility-inlines-hidden VISIBILITY_INLINES_HIDDEN)
43 if(VISIBILITY_INLINES_HIDDEN)
44         set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden)
45 endif(VISIBILITY_INLINES_HIDDEN)
47 CHECK_CXX_COMPILER_FLAG(-fvisibility=hidden VISIBILITY_HIDDEN)
48 if(VISIBILITY_HIDDEN)
49         add_definitions(-fvisibility=hidden)
50 endif(VISIBILITY_HIDDEN)
52 if(WIN32)
53         add_definitions(-D_SECURE_SCL=0)
54         add_definitions(-D_CRT_SECURE_NO_WARNINGS)
55         add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
56 endif(WIN32)
58 add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
60 if(NOT CMAKE_BUILD_TYPE)
61         set(CMAKE_BUILD_TYPE "Release" CACHE STRING
62                 "Build type (Release/Debug/RelWithDebInfo/MinSizeRe)" FORCE)
63 endif(NOT CMAKE_BUILD_TYPE)
65 if(CMAKE_BUILD_TYPE STREQUAL Debug)
66         add_definitions(-D_DEBUG -ggdb)
67         set(wxWidgets_USE_DEBUG ON CACHE BOOL "Use wxWidgets Debugging")
68 endif(CMAKE_BUILD_TYPE STREQUAL Debug)
70 if(CMAKE_BUILD_TYPE STREQUAL Release)
71         add_definitions(-fomit-frame-pointer)
72 endif(CMAKE_BUILD_TYPE STREQUAL Release)
74 ########################################
75 # Dependency checking
77 # NOTES:
78 # There are numerous possible cases:
79 # - dependency may be required or optional
80 # - dependency may be already installed (but optionally the bundled one may be used)
81
82 # TODO: We should have a number of options for optional dependencies (disable,
83 # force bundled, bundled or native, force native).  For example the OpenGL
84 # plugin defaults to force native, so we error out if no GL libs are found.
85 # The user is free to explicitly disable it though.  Stuff which is likely to
86 # be needed by users is optional defaulting to ON, other stuff (like e.g.
87 # sound backends) is completely optional.
89 # TODO: wxWidgets: When building the Debug configuration, we should probably
90 # check if the debug wx libs are available and fall back to the bundled ones
91 # otherwise.
93 include(FindOpenGL REQUIRED)
94 include_directories(${OPENGL_INCLUDE_DIR})
96 include(FindALSA OPTIONAL)
97 if(ALSA_FOUND)
98         add_definitions(-DHAVE_ALSA=1)
99         message("ALSA found, enabling ALSA sound backend")
100 else()
101         add_definitions(-DHAVE_ALSA=0)
102         message("ALSA NOT found, disabling ALSA sound backend")
103 endif(ALSA_FOUND)
105 pkg_search_module(AO ao)
106 if(AO_FOUND)
107         add_definitions(-DHAVE_AO=1)
108         include_directories(${AO_INCLUDE_DIRS})
109         message("ao found, enabling ao sound backend")
110 else()
111         add_definitions(-DHAVE_AO=0)
112         message("ao NOT found, disabling ao sound backend")
113 endif(AO_FOUND)
115 pkg_search_module(BLUEZ bluez)
116 if(BLUEZ_FOUND)
117         add_definitions(-DHAVE_BLUEZ=1)
118         include_directories(${BLUEZ_INCLUDE_DIRS})
119         message("bluez found, enabling bluetooth support")
120 else()
121         add_definitions(-DHAVE_BLUEZ=0)
122         message("bluez NOT found, disabling bluetooth support")
123 endif(BLUEZ_FOUND)
125 pkg_search_module(PULSEAUDIO libpulse)
126 if(PULSEAUDIO_FOUND)
127         add_definitions(-DHAVE_PULSEAUDIO=1)
128         include_directories(${PULSEAUDIO_INCLUDE_DIR})
129         message("PulseAudio found, enabling PulseAudio sound backend")
130 else()
131         add_definitions(-DHAVE_PULSEAUDIO=0)
132         message("PulseAudio NOT found, disabling PulseAudio sound backend")
133 endif(PULSEAUDIO_FOUND)
135 include(FindOpenAL OPTIONAL)
136 if(OPENAL_FOUND)
137         add_definitions(-DHAVE_OPENAL=1)
138         include_directories(${OPENAL_INCLUDE_DIR})
139         message("OpenAL found, enabling OpenAL sound backend")
140 else()
141         add_definitions(-DHAVE_OPENAL=0)
142         message("OpenAL NOT found, disabling OpenAL sound backend")
143 endif(OPENAL_FOUND)
145 # Note: We do not need to explicitly check for X11 as it is done in the cmake
146 # FindOpenGL module on linux.
147 if(UNIX)
148         if(X11_FOUND)
149                 add_definitions(-DHAVE_X11=1)
150                 include_directories(${X11_INCLUDE_DIR})
151                 message("X11 found")
152         else()
153                 message(FATAL_ERROR "X11 is required but not found")
154         endif(X11_FOUND)
155 else()
156         add_definitions(-DHAVE_X11=0)
157 endif(UNIX)
159 pkg_search_module(XRANDR xrandr)
160 if(XRANDR_FOUND)
161         add_definitions(-DHAVE_XRANDR=1)
162         message("Xrandr found")
163 else()
164         add_definitions(-DHAVE_XRANDR=0)
165         message("Xrandr NOT found")
166 endif(XRANDR_FOUND)
168 include(CheckCXXSourceRuns)
169 set(CMAKE_REQUIRED_LIBRARIES portaudio)
170 CHECK_CXX_SOURCE_RUNS(
171         "#include <portaudio.h>
172         int main(int argc, char **argv)
173         { if(Pa_GetVersion() >= 1890) return 0; else return 1; }"
174         PORTAUDIO)
175 if(PORTAUDIO)
176         message("PortAudio found, enabling mic support")
177         add_definitions(-DHAVE_PORTAUDIO=1)
178         set(PORTAUDIO_FOUND TRUE)
179 else()
180         message("PortAudio not found, disabling mic support")
181         add_definitions(-DHAVE_PORTAUDIO=0)
182         set(PORTAUDIO_FOUND FALSE)
183 endif(PORTAUDIO)
186 ########################################
187 # Setup include directories (and make sure they are preferred over the Externals)
189 include_directories(Source/PluginSpecs)
190 include_directories(Source/Core/AudioCommon/Src)
191 include_directories(Source/Core/Common/Src)
192 include_directories(Source/Core/Core/Src)
193 include_directories(Source/Core/DebuggerUICommon/Src)
194 include_directories(Source/Core/DebuggerWX/Src)
195 include_directories(Source/Core/DiscIO/Src)
196 include_directories(Source/Core/DolphinWX/Src)
197 include_directories(Source/Core/DSPCore/Src)
198 include_directories(Source/Core/InputCommon/Src)
199 include_directories(Source/Core/InputUICommon/Src)
200 include_directories(Source/Core/VideoCommon/Src)
203 ########################################
204 # Process externals and setup their include directories
206 # NOTES about adding Externals:
207 #   - add the include directory here
208 #   - make sure to tell cmake to link them statically or dynamically (most
209 #     should be linked statically)
210 #   - place the CMakeLists.txt in the first-level subdirectory, e.g.
211 #     Externals/WiiUse/CMakeLists.txt (that is: NOT in some Src/ subdirectory)
213 add_subdirectory(Externals/Bochs_disasm)
214 include_directories(Externals/Bochs_disasm)
216 # TODO: Try using the native lib first
217 # To use the native lib for Lua the dolphin code will need to be changed.
218 # Currently the file lstate.h is improperly included.
219 add_subdirectory(Externals/Lua)
220 include_directories(Externals/Lua)
222 find_library(LZO lzo2)
223 find_path(LZO_INCLUDE lzo/lzo1x.h)
224 if(LZO AND LZO_INCLUDE)
225         message("Using shared lzo")
226         include_directories(${LZO_INCLUDE})
227 else()
228         message("Shared lzo not found, falling back to the static library")
229         add_subdirectory(Externals/LZO)
230         include_directories(Externals/LZO)
231 endif(LZO AND LZO_INCLUDE)
233 include(FindSDL OPTIONAL)
234 if(SDL_FOUND)
235         message("Using shared SDL")
236         include_directories(${SDL_INCLUDE_DIR})
237 else(SDL_FOUND)
238         # TODO: Use the prebuilt one on Windows
239         message("Shared SDL not found, falling back to the static library")
240         include_directories(Externals/SDL/include)
241         add_subdirectory(Externals/SDL)
242 endif(SDL_FOUND)
244 find_library(SFML_NETWORK sfml-network)
245 find_path(SFML_INCLUDE SFML/Network/Ftp.hpp)
246 if(SFML_NETWORK AND SFML_INCLUDE)
247         message("Using shared sfml-network")
248         include_directories(${SFML_INCLUDE})
249 else()
250         message("Shared sfml-network not found, falling back to the static library")
251         add_subdirectory(Externals/SFML)
252         include_directories(Externals/SFML/include)
253 endif(SFML_NETWORK AND SFML_INCLUDE)
255 find_library(SOIL SOIL)
256 find_path(SOIL_INCLUDE SOIL/SOIL.h)
257 if(SOIL AND SOIL_INCLUDE)
258         message("Using shared SOIL")
259         include_directories(${SOIL_INCLUDE})
260 else()
261         message("Shared SOIL not found, falling back to the static library")
262         add_subdirectory(Externals/SOIL)
263         include_directories(Externals/SOIL)
264 endif(SOIL AND SOIL_INCLUDE)
266 include(FindZLIB OPTIONAL)
267 if(ZLIB_FOUND)
268         message("Using shared zlib")
269         include_directories(${ZLIB_INCLUDE_DIRS})
270 else(ZLIB_FOUND)
271         message("Shared zlib not found, falling back to the static library")
272         add_subdirectory(Externals/zlib)
273         include_directories(Externals/zlib)
274 endif(ZLIB_FOUND)
276 if(UNIX OR APPLE)
277         add_subdirectory(Externals/WiiUse)
278         include_directories(Externals/WiiUse/Src)
279 elseif(WIN32)
280         # use the precompiled ones
281         # TODO: Use the 64 bit lib on 64 bit systems...
282         # TODO: If WDK is installed, we can compile this from source as well
283         find_library(WIIUSE wiiuse PATHS Externals/WiiUse/Win32 NO_DEFAULT_PATH)
284         include_directories(Externals/WiiUse/Src)
285 endif()
287 if(WIN32)
288         find_library(GLEW glew32s PATHS Externals/GLew)
289         include_directories(Externals/GLew/include)
290 endif()
292 find_library(OPENCL OpenCL)
293 find_path(OPENCL_INCLUDE CL/cl.h)
294 if(OPENCL AND OPENCL_INCLUDE)
295         message("OpenCL found")
296         include_directories(${OPENCL_INCLUDE})
297 else()
298         message("OpenCL not found, using CLRun instead")
299         include_directories(Externals/CLRun/include)
300         add_subdirectory(Externals/CLRun)
301 endif(OPENCL AND OPENCL_INCLUDE)
302 if(NOT APPLE)
303         add_definitions(-DHAVE_OPENCL=1)
304 endif()
306 set(DISABLE_WX FALSE CACHE BOOL "Disable wxWidgets (use CLI interface)")
307 if(NOT DISABLE_WX)
308         include(FindwxWidgets OPTIONAL)
310         if(wxWidgets_FOUND)
311                 add_definitions(-DHAVE_WX=1)
312                 include(${wxWidgets_USE_FILE})
314                 if(UNIX)
315                         pkg_search_module(GTK2 REQUIRED gtk+-2.0)
316                         if(GTK2_FOUND)
317                                 include_directories(${GTK2_INCLUDE_DIRS})
318                                 message("GTK 2 found")
319                         else(GTK2_FOUND)
320                                 message("GTK 2 NOT found")
321                         endif(GTK2_FOUND)
322                 endif(UNIX)
324                 message("wxWidgets found, enabling GUI build")
325         else(wxWidgets_FOUND)
326                 message("Shared wxWidgets not found, falling back to the static library")
327                 add_definitions(-DHAVE_WX=1)
328                 include_directories(Externals/wxWidgets/include)
329                 add_subdirectory(Externals/wxWidgets)
330         endif(wxWidgets_FOUND)
331 endif(NOT DISABLE_WX)
334 ########################################
335 # Pre-build events: Define configuration variables and write svnrev header
337 file(WRITE ./Source/Core/Common/Src/svnrev.h
338         "#define SVN_REV_STR \"" ${DOLPHIN_WC_REVISION} "-" ${CMAKE_BUILD_TYPE} "\"")
341 ########################################
342 # Start compiling our code
344 add_subdirectory(Source)
347 ########################################
348 # Install shared data files
350 install(DIRECTORY Data/User/ DESTINATION ${datadir}/user PATTERN .svn EXCLUDE)
351 install(DIRECTORY Data/Sys/ DESTINATION ${datadir}/sys PATTERN .svn EXCLUDE)
352 install(FILES Data/license.txt DESTINATION ${datadir})
354 # packaging information
355 include(CPack)
356 set(CPACK_PACKAGE_NAME "dolphin-emu")
357 set(CPACK_PACKAGE_VENDOR "Dolphin Team")
358 set(CPACK_PACKAGE_VERSION_MAJOR "2")
359 set(CPACK_PACKAGE_VERSION_MINOR "0")
361 if(DOLPHIN_IS_STABLE)
362         set(CPACK_PACKAGE_VERSION_PATCH "0")
363 else()
364         set(CPACK_PACKAGE_VERSION_PATCH ${DOLPHIN_WC_REV})
365 endif()
367 # TODO: CPACK_PACKAGE_DESCRIPTION_FILE
368 # TODO: CPACK_PACKAGE_DESCRIPTION_SUMMARY
369 # TODO: CPACK_RESOURCE_FILE_README
370 # TODO: CPACK_RESOURCE_FILE_WELCOME
371 # TODO: CPACK_PACKAGE_EXECUTABLES
372 # TODO: CPACK_PACKAGE_ICON
373 # TODO: CPACK_NSIS_*
374 # TODO: Use CPack components for DSPSpy, etc => cpack_add_component