Fix some linkage issues with the cmake build system.
[dolphin.git] / CMakeLists.txt
blob31cda9ae9a60fda7935e431056e6509e43c298fd
1 ########################################
2 # General setup
4 cmake_minimum_required (VERSION 2.6)
5 project (dolphin-emu)
7 set(DOLPHIN_IS_STABLE FALSE)
8 set(DOLPHIN_BIN_DIR             ${CMAKE_CURRENT_SOURCE_DIR}/Binary/${CMAKE_HOST_SYSTEM_NAME})
9 set(DOLPHIN_PLUGINS_DIR ${DOLPHIN_BIN_DIR}/plugins)
10 set(DOLPHIN_USER_DIR    ${DOLPHIN_BIN_DIR})
11 set(DOLPHIN_SYS_DIR             ${DOLPHIN_BIN_DIR})
12 set(DOLPHIN_LICENSE_DIR ${DOLPHIN_BIN_DIR})
14 include(FindSubversion OPTIONAL) # for revision info
15 if(Subversion_FOUND)
16         Subversion_WC_INFO(${PROJECT_SOURCE_DIR} DOLPHIN) # defines DOLPHIN_WC_REVISION
17 endif()
19 include(FindPkgConfig REQUIRED) # TODO: Make this optional or even implement our own package detection
21 # setup paths
22 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${DOLPHIN_BIN_DIR})
23 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${DOLPHIN_PLUGINS_DIR})
25 # Various compile flags - TODO: Can these be simplified with a more general CMake variable?
26 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
27 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
29 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
30 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")
32 # gcc uses some optimizations which might break stuff without this flag
33 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
34 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
36 add_definitions(-DFILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
38 if(UNIX)
39     # UNIX needs -fPIC for shared libraries, TODO: Would -fpic be enough as well?
40         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
41         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
42 endif(UNIX)
45 ########################################
46 # Dependency checking
48 # TODO: Use find_library for other stuff?
50 # NOTES:
51 # there are numerous possible cases:
52 # - dependency may be required or optional
53 # - dependency may be already installed (but optionally the bundled one may be used)
54
55 # TODO: We should have a number of options for optional dependencies (disable, force bundled, bundled or native, force native)
56 # e.g. the OpenGL plugin defaults to force native, so we error out if no GL libs are found. The user is free to explicitely disable it though.
57 # Stuff which is likely to be needed by users is made an option with default ON, other stuff (like e.g. sound backends) is made completely optionally.
59 # TODO: wxWidgets: Since _DEBUG gets defined in Debug builds, wxWidgets will enable some debugging functionality as well.
60 #       However, because we still link against release wx libs, which makes compilation fail because of undefined references.
61 #       When building the Debug configuration, we should probably check if the debug wx libs are available and fall back to the bundled ones otherwise.
63 include(FindOpenGL REQUIRED)
65 include(FindALSA OPTIONAL)
66 include(FindOpenAL OPTIONAL)
67 include(FindwxWidgets OPTIONAL)
68 if(UNIX)
69         include(FindX11 REQUIRED)
70 endif(UNIX)
72 pkg_search_module(PULSEAUDIO libpulse)
73 pkg_search_module(AO ao)
74 pkg_search_module(BLUEZ bluez)
76 # TODO: Make some of these optional like explained above
77 if(ALSA_FOUND)
78         add_definitions(-DHAVE_ALSA=1)
79         message("ALSA found, enabling ALSA sound backend")
80 else()
81         add_definitions(-DHAVE_ALSA=0)
82         message("ALSA NOT found, disabling ALSA sound backend")
83 endif(ALSA_FOUND)
85 if(AO_FOUND)
86         add_definitions(-DHAVE_AO=1)
87         include_directories(${AO_INCLUDE_DIRS})
88         message("ao found, enabling ao sound backend")
89 else()
90         add_definitions(-DHAVE_AO=0)
91         message("ao NOT found, disabling ao sound backend")
92 endif(AO_FOUND)
94 if(BLUEZ_FOUND)
95         add_definitions(-DHAVE_BLUEZ=1)
96         include_directories(${BLUEZ_INCLUDE_DIRS})
97         message("bluez found, enabling bluetooth support")
98 else()
99         add_definitions(-DHAVE_BLUEZ=0)
100         message("bluez NOT found, enabling bluetooth support")
101 endif(BLUEZ_FOUND)
103 include_directories(${OPENGL_INCLUDE_DIR})
105 if(PULSEAUDIO_FOUND)
106         add_definitions(-DHAVE_PULSEAUDIO=1)
107         include_directories(${PULSEAUDIO_INCLUDE_DIR})
108         message("PulseAudio found, enabling PulseAudio sound backend")
109 else()
110         add_definitions(-DHAVE_PULSEAUDIO=0)
111         message("PulseAudio NOT found, disabling PulseAudio sound backend")
112 endif(PULSEAUDIO_FOUND)
114 if(OPENAL_FOUND)
115         add_definitions(-DHAVE_OPENAL=1)
116         include_directories(${OPENAL_INCLUDE_DIR})
117         message("OpenAL found, enabling OpenAL sound backend")
118 else()
119         add_definitions(-DHAVE_OPENAL=0)
120         message("OpenAL NOT found, disabling OpenAL sound backend")
121 endif(OPENAL_FOUND)
123 if(wxWidgets_FOUND)
124         add_definitions(-DHAVE_WX=1)
125         include(${wxWidgets_USE_FILE})
127         if(UNIX)
128                 pkg_search_module(GTK2 REQUIRED gtk+-2.0)
129                 if(GTK2_FOUND)
130                         include_directories(${GTK2_INCLUDE_DIRS})
131                         message("GTK 2 found")
132                 else(GTK2_FOUND)
133                         message("GTK 2 NOT found")
134                 endif(GTK2_FOUND)
135         endif(UNIX)
137         message("wxWidgets found, enabling GUI build")
138 else(wxWidgets_FOUND)
139         add_definitions(-DHAVE_WX=0)
140         message("wxWidgets NOT found, disabling GUI build (using CLI interface)")
141 endif(wxWidgets_FOUND)
143 if(X11_FOUND)
144         add_definitions(-DHAVE_X11=1)
145         include_directories(${X11_INCLUDE_DIR})
146         message("X11 found")
147 else()
148         add_definitions(-DHAVE_X11=0)
149         message("X11 NOT found")
150 endif(X11_FOUND)
153 ########################################
154 # Setup include directories (and make sure they are preferred over the Externals)
156 include_directories(Source/PluginSpecs)
157 include_directories(Externals)
158 include_directories(.)  # config.h, TODO: Move to Source? Or just add the corresponding definitions to the compiler flags?
159 include_directories(Source/Core/AudioCommon/Src)
160 include_directories(Source/Core/Common/Src)
161 include_directories(Source/Core/Core/Src)
162 include_directories(Source/Core/DebuggerUICommon/Src)
163 include_directories(Source/Core/DebuggerWX/Src)
164 include_directories(Source/Core/DiscIO/Src)
165 include_directories(Source/Core/DolphinWX/Src)
166 include_directories(Source/Core/DSPCore/Src)
167 include_directories(Source/Core/InputCommon/Src)
168 include_directories(Source/Core/InputUICommon/Src)
169 include_directories(Source/Core/VideoCommon/Src)
172 ########################################
173 # Process externals and setup their include directories
175 # NOTES about adding Externals:
176 #       - add the include directory here
177 #       - make sure to tell cmake to link them statically or dynamically (most should be linked statically)
178 #       - ideally, the nested CMakeLists.txt should only contain a list of sources and an add_library()+target_link_libraries() call pair
179 #       - place the CMakeLists.txt in the first-level subdirectory, e.g. Externals/WiiUse/CMakeLists.txt (that is: NOT in some Src/ subdirectory)
181 add_subdirectory(Externals/Bochs_disasm)
182 include_directories(Externals/Bochs_disasm)
184 # TODO: Try using the native lib first
185 add_subdirectory(Externals/Lua)
186 include_directories(Externals/Lua)
188 # TODO: Try using the native lib first
189 add_subdirectory(Externals/LZO)
190 include_directories(Externals/LZO)
192 include(FindSDL OPTIONAL)
193 if(SDL_FOUND)
194         include_directories(SDL_INCLUDE_DIR)
195 else(SDL_FOUND)
196         # TODO: No CMakeLists.txt there, yet...
197         add_subdirectory(Externals/SDL)
198         include_directories(Externals/SDL/include)
199 endif(SDL_FOUND)
201 # TODO: Try using the native lib first
202 add_subdirectory(Externals/SFML)
203 include_directories(Externals/SFML/include)
205 # TODO: Try using the native lib first
206 add_subdirectory(Externals/SOIL)
207 include_directories(Externals/SOIL) # TODO: Or Externals/SOIL/SOIL?
209 include(FindZLIB OPTIONAL) # TODO: Move to top
210 if(ZLIB_FOUND)
211         include_directories(ZLIB_INCLUDE_DIRS)
212 else(ZLIB_FOUND)
213         # TODO: No CMakeLists.txt there, yet...
214         add_subdirectory(Externals/zlib)
215         include_directories(Externals/zlib)
216 endif(ZLIB_FOUND)
218 add_subdirectory(Externals/WiiUse)
219 include_directories(Externals/WiiUse/Src)
222 ########################################
223 # Pre-build events: Define configuration variables and write svnrev header
225 file(WRITE ./Source/Core/Common/Src/svnrev.h "#define SVN_REV_STR \"" ${DOLPHIN_WC_REVISION} "-" ${CMAKE_BUILD_TYPE} "\"")
226 # TODO: Write config.h here or add the corresponding compile definitions using add_definitions
229 ########################################
230 # Start compiling our code
232 add_subdirectory(Source)
235 ########################################
236 # copy over the Data folder ... TODO: Don't copy .svn dirs!
238 file(COPY Data/User DESTINATION ${DOLPHIN_USER_DIR})
239 file(COPY Data/Sys DESTINATION ${DOLPHIN_SYS_DIR})
240 file(COPY Data/license.txt DESTINATION ${DOLPHIN_LICENSE_DIR})
243 ########################################
244 # Install and CPack information
246 install(DIRECTORY Data/User DESTINATION share/dolphin-emu)
247 install(DIRECTORY Data/Sys DESTINATION share/dolphin-emu)
248 install(FILES Data/license.txt DESTINATION share/dolphin-emu)
249 # TODO: Move childrens's install commands here?
251 # packaging information
252 include(CPack)
253 set(CPACK_PACKAGE_NAME "dolphin-emu")
254 set(CPACK_PACKAGE_VENDOR "Dolphin Team")
255 set(CPACK_PACKAGE_VERSION_MAJOR "2")
256 set(CPACK_PACKAGE_VERSION_MINOR "0")
258 if(DOLPHIN_IS_STABLE)
259         set(CPACK_PACKAGE_VERSION_PATCH "0")
260 else()
261         set(CPACK_PACKAGE_VERSION_PATCH ${DOLPHIN_WC_REV})
262 endif()
264 # TODO: CPACK_PACKAGE_DESCRIPTION_FILE
265 # TODO: CPACK_PACKAGE_DESCRIPTION_SUMMARY
266 # TODO: CPACK_RESOURCE_FILE_README
267 # TODO: CPACK_RESOURCE_FILE_WELCOME
268 # TODO: CPACK_PACKAGE_EXECUTABLES
269 # TODO: CPACK_PACKAGE_ICON
270 # TODO: CPACK_NSIS_*
271 # TODO: Use CPack components for DSPSpy, etc => cpack_add_component