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