Windows: Link debug build against debug wiiuse. Can't keep linking to the release...
[dolphin.git] / CMakeLists.txt
blob711dbadb82822776982f9f455aa95a16b78b83e8
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 include(FindOpenGL REQUIRED)
90 include_directories(${OPENGL_INCLUDE_DIR})
92 include(FindALSA OPTIONAL)
93 if(ALSA_FOUND)
94         add_definitions(-DHAVE_ALSA=1)
95         message("ALSA found, enabling ALSA sound backend")
96 else()
97         add_definitions(-DHAVE_ALSA=0)
98         message("ALSA NOT found, disabling ALSA sound backend")
99 endif(ALSA_FOUND)
101 pkg_search_module(AO ao)
102 if(AO_FOUND)
103         add_definitions(-DHAVE_AO=1)
104         include_directories(${AO_INCLUDE_DIRS})
105         message("ao found, enabling ao sound backend")
106 else()
107         add_definitions(-DHAVE_AO=0)
108         message("ao NOT found, disabling ao sound backend")
109 endif(AO_FOUND)
111 pkg_search_module(BLUEZ bluez)
112 if(BLUEZ_FOUND)
113         add_definitions(-DHAVE_BLUEZ=1)
114         include_directories(${BLUEZ_INCLUDE_DIRS})
115         message("bluez found, enabling bluetooth support")
116 else()
117         add_definitions(-DHAVE_BLUEZ=0)
118         message("bluez NOT found, disabling bluetooth support")
119 endif(BLUEZ_FOUND)
121 pkg_search_module(PULSEAUDIO libpulse)
122 if(PULSEAUDIO_FOUND)
123         add_definitions(-DHAVE_PULSEAUDIO=1)
124         include_directories(${PULSEAUDIO_INCLUDE_DIR})
125         message("PulseAudio found, enabling PulseAudio sound backend")
126 else()
127         add_definitions(-DHAVE_PULSEAUDIO=0)
128         message("PulseAudio NOT found, disabling PulseAudio sound backend")
129 endif(PULSEAUDIO_FOUND)
131 include(FindOpenAL OPTIONAL)
132 if(OPENAL_FOUND)
133         add_definitions(-DHAVE_OPENAL=1)
134         include_directories(${OPENAL_INCLUDE_DIR})
135         message("OpenAL found, enabling OpenAL sound backend")
136 else()
137         add_definitions(-DHAVE_OPENAL=0)
138         message("OpenAL NOT found, disabling OpenAL sound backend")
139 endif(OPENAL_FOUND)
141 # Note: We do not need to explicitly check for X11 as it is done in the cmake
142 # FindOpenGL module on linux.
143 if(UNIX)
144         if(X11_FOUND)
145                 add_definitions(-DHAVE_X11=1)
146                 include_directories(${X11_INCLUDE_DIR})
147                 message("X11 found")
148         else()
149                 message(FATAL_ERROR "X11 is required but not found")
150         endif(X11_FOUND)
151 else()
152         add_definitions(-DHAVE_X11=0)
153 endif(UNIX)
155 pkg_search_module(XRANDR xrandr)
156 if(XRANDR_FOUND)
157         add_definitions(-DHAVE_XRANDR=1)
158         message("Xrandr found")
159 else()
160         add_definitions(-DHAVE_XRANDR=0)
161         message("Xrandr NOT found")
162 endif(XRANDR_FOUND)
164 include(CheckCXXSourceRuns)
165 set(CMAKE_REQUIRED_LIBRARIES portaudio)
166 CHECK_CXX_SOURCE_RUNS(
167         "#include <portaudio.h>
168         int main(int argc, char **argv)
169         { if(Pa_GetVersion() >= 1890) return 0; else return 1; }"
170         PORTAUDIO)
171 if(PORTAUDIO)
172         message("PortAudio found, enabling mic support")
173         add_definitions(-DHAVE_PORTAUDIO=1)
174         set(PORTAUDIO_FOUND TRUE)
175 else()
176         message("PortAudio not found, disabling mic support")
177         add_definitions(-DHAVE_PORTAUDIO=0)
178         set(PORTAUDIO_FOUND FALSE)
179 endif(PORTAUDIO)
182 ########################################
183 # Setup include directories (and make sure they are preferred over the Externals)
185 include_directories(Source/PluginSpecs)
186 include_directories(Source/Core/AudioCommon/Src)
187 include_directories(Source/Core/Common/Src)
188 include_directories(Source/Core/Core/Src)
189 include_directories(Source/Core/DebuggerUICommon/Src)
190 include_directories(Source/Core/DebuggerWX/Src)
191 include_directories(Source/Core/DiscIO/Src)
192 include_directories(Source/Core/DolphinWX/Src)
193 include_directories(Source/Core/DSPCore/Src)
194 include_directories(Source/Core/InputCommon/Src)
195 include_directories(Source/Core/InputUICommon/Src)
196 include_directories(Source/Core/VideoCommon/Src)
199 ########################################
200 # Process externals and setup their include directories
202 # NOTES about adding Externals:
203 #   - add the include directory here
204 #   - make sure to tell cmake to link them statically or dynamically (most
205 #     should be linked statically)
206 #   - place the CMakeLists.txt in the first-level subdirectory, e.g.
207 #     Externals/WiiUse/CMakeLists.txt (that is: NOT in some Src/ subdirectory)
209 add_subdirectory(Externals/Bochs_disasm)
210 include_directories(Externals/Bochs_disasm)
212 # TODO: Try using the native lib first
213 # To use the native lib for Lua the dolphin code will need to be changed.
214 # Currently the file lstate.h is improperly included.
215 add_subdirectory(Externals/Lua)
216 include_directories(Externals/Lua)
218 find_library(LZO lzo2)
219 find_path(LZO_INCLUDE lzo/lzo1x.h)
220 if(LZO AND LZO_INCLUDE)
221         message("Using shared lzo")
222         include_directories(${LZO_INCLUDE})
223 else()
224         message("Shared lzo not found, falling back to the static library")
225         add_subdirectory(Externals/LZO)
226         include_directories(Externals/LZO)
227 endif(LZO AND LZO_INCLUDE)
229 include(FindSDL OPTIONAL)
230 if(SDL_FOUND)
231         message("Using shared SDL")
232         include_directories(${SDL_INCLUDE_DIR})
233 else(SDL_FOUND)
234         # TODO: Use the prebuilt one on Windows
235         message("Shared SDL not found, falling back to the static library")
236         include_directories(Externals/SDL/include)
237         add_subdirectory(Externals/SDL)
238 endif(SDL_FOUND)
240 find_library(SFML_NETWORK sfml-network)
241 find_path(SFML_INCLUDE SFML/Network/Ftp.hpp)
242 if(SFML_NETWORK AND SFML_INCLUDE)
243         message("Using shared sfml-network")
244         include_directories(${SFML_INCLUDE})
245 else()
246         message("Shared sfml-network not found, falling back to the static library")
247         add_subdirectory(Externals/SFML)
248         include_directories(Externals/SFML/include)
249 endif(SFML_NETWORK AND SFML_INCLUDE)
251 find_library(SOIL SOIL)
252 find_path(SOIL_INCLUDE SOIL/SOIL.h)
253 if(SOIL AND SOIL_INCLUDE)
254         message("Using shared SOIL")
255         include_directories(${SOIL_INCLUDE})
256 else()
257         message("Shared SOIL not found, falling back to the static library")
258         add_subdirectory(Externals/SOIL)
259         include_directories(Externals/SOIL)
260 endif(SOIL AND SOIL_INCLUDE)
262 include(FindZLIB OPTIONAL)
263 if(ZLIB_FOUND)
264         message("Using shared zlib")
265         include_directories(${ZLIB_INCLUDE_DIRS})
266 else(ZLIB_FOUND)
267         message("Shared zlib not found, falling back to the static library")
268         add_subdirectory(Externals/zlib)
269         include_directories(Externals/zlib)
270 endif(ZLIB_FOUND)
272 if(UNIX OR APPLE)
273         add_subdirectory(Externals/WiiUse)
274         include_directories(Externals/WiiUse/Src)
275 elseif(WIN32)
276         # use the precompiled ones
277         # TODO: Use the 64 bit lib on 64 bit systems...
278         # TODO: If WDK is installed, we can compile this from source as well
279         find_library(WIIUSE wiiuse PATHS Externals/WiiUse/Win32 NO_DEFAULT_PATH)
280         include_directories(Externals/WiiUse/Src)
281 endif()
283 if(WIN32)
284         find_library(GLEW glew32s PATHS Externals/GLew)
285         include_directories(Externals/GLew/include)
286 else()
287         include(CheckLib)
288         check_lib(GLEW glew TRUE)
289         check_lib(GLU glu TRUE)
290         check_lib(CG Cg TRUE)
291         check_lib(CGGL CgGL TRUE)
292 endif()
294 if(NOT APPLE)
295         include_directories(Externals/CLRun/include)
296         add_subdirectory(Externals/CLRun)
297         add_definitions(-DUSE_CLRUN)
298         add_definitions(-DHAVE_OPENCL=1)
299 endif(NOT APPLE)
301 set(DISABLE_WX FALSE CACHE BOOL "Disable wxWidgets (use CLI interface)")
302 if(NOT DISABLE_WX)
303         include(FindwxWidgets OPTIONAL)
305         if(wxWidgets_FOUND)
306                 add_definitions(-DHAVE_WX=1)
307                 include(${wxWidgets_USE_FILE})
309                 if(UNIX)
310                         check_lib(GTK2 gtk+-2.0 TRUE)
311                         if(GTK2_FOUND)
312                                 include_directories(${GTK2_INCLUDE_DIRS})
313                         endif(GTK2_FOUND)
314                 endif(UNIX)
316                 message("wxWidgets found, enabling GUI build")
317         else(wxWidgets_FOUND)
318                 message("Shared wxWidgets not found, falling back to the static library")
319                 add_definitions(-DHAVE_WX=1)
320                 include_directories(Externals/wxWidgets/include)
321                 add_subdirectory(Externals/wxWidgets)
322         endif(wxWidgets_FOUND)
323 endif(NOT DISABLE_WX)
326 ########################################
327 # Pre-build events: Define configuration variables and write svnrev header
329 file(WRITE ./Source/Core/Common/Src/svnrev.h
330         "#define SVN_REV_STR \"" ${DOLPHIN_WC_REVISION} "-" ${CMAKE_BUILD_TYPE} "\"")
333 ########################################
334 # Start compiling our code
336 add_subdirectory(Source)
339 ########################################
340 # Install shared data files
342 install(DIRECTORY Data/User/ DESTINATION ${datadir}/user PATTERN .svn EXCLUDE)
343 install(DIRECTORY Data/Sys/ DESTINATION ${datadir}/sys PATTERN .svn EXCLUDE)
344 install(FILES Data/license.txt DESTINATION ${datadir})
346 # packaging information
347 set(CPACK_PACKAGE_NAME "dolphin-emu")
348 set(CPACK_PACKAGE_VENDOR "Dolphin Team")
349 set(CPACK_PACKAGE_VERSION_MAJOR "2")
350 set(CPACK_PACKAGE_VERSION_MINOR "0")
352 if(DOLPHIN_IS_STABLE)
353         set(CPACK_PACKAGE_VERSION_PATCH "0")
354 else()
355         set(CPACK_PACKAGE_VERSION_PATCH ${DOLPHIN_WC_REVISION})
356 endif()
358 # TODO: CPACK_PACKAGE_DESCRIPTION_FILE
359 # TODO: CPACK_PACKAGE_DESCRIPTION_SUMMARY
360 # TODO: CPACK_RESOURCE_FILE_README
361 # TODO: CPACK_RESOURCE_FILE_WELCOME
362 # TODO: CPACK_PACKAGE_EXECUTABLES
363 # TODO: CPACK_PACKAGE_ICON
364 # TODO: CPACK_NSIS_*
365 # TODO: Use CPack components for DSPSpy, etc => cpack_add_component
367 # CPack must be included after the CPACK_* variables are set in order for those
368 # variables to take effect.
369 include(CPack)