]> git.jsancho.org Git - lugaru.git/blob - CMakeLists.txt
Moved things related to tutorial in new Tutorial class
[lugaru.git] / CMakeLists.txt
1 project(lugaru)
2
3 cmake_minimum_required(VERSION 3.0)
4 cmake_policy(SET CMP0004 OLD)
5
6 include(FindPkgConfig)
7 include(GNUInstallDirs)
8
9
10 ### Helpers
11
12 set(SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/Source")
13
14 if(UNIX AND NOT APPLE)
15     set(LINUX TRUE)
16 endif()
17
18
19 ### CMake config
20
21 if(NOT CMAKE_BUILD_TYPE)
22     set(CMAKE_BUILD_TYPE RelWithDebInfo)
23 endif(NOT CMAKE_BUILD_TYPE)
24 message("CMake build type: ${CMAKE_BUILD_TYPE}")
25
26 set(CMAKE_CXX_FLAGS "-Wall -Wno-parentheses -pedantic --std=c++11 ${CMAKE_CXX_FLAGS}")
27
28 if(APPLE)
29     set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX")
30     set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING
31         "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value")
32     set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.11.sdk" CACHE PATH
33         "The product will be built against the headers and libraries located inside the indicated SDK.")
34 endif(APPLE)
35
36 if(LINUX)
37     option(SYSTEM_INSTALL "Enable system-wide installation, with hardcoded data directory defined with CMAKE_INSTALL_DATADIR" OFF)
38 endif(LINUX)
39
40 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake/Modules/")
41
42
43 ### Sources
44
45 set(LUGARU_SRCS
46     ${SRCDIR}/main.cpp
47     ${SRCDIR}/Animation/Animation.cpp
48     ${SRCDIR}/Animation/Joint.cpp
49     ${SRCDIR}/Animation/Muscle.cpp
50     ${SRCDIR}/Animation/Skeleton.cpp
51     ${SRCDIR}/Audio/openal_wrapper.cpp
52     ${SRCDIR}/Audio/Sounds.cpp
53     ${SRCDIR}/Devtools/ConsoleCmds.cpp
54     ${SRCDIR}/Environment/Lights.cpp
55     ${SRCDIR}/Environment/Skybox.cpp
56     ${SRCDIR}/Environment/Terrain.cpp
57     ${SRCDIR}/Graphic/Models.cpp
58     ${SRCDIR}/Graphic/Sprite.cpp
59     ${SRCDIR}/Graphic/Stereo.cpp
60     ${SRCDIR}/Graphic/Text.cpp
61     ${SRCDIR}/Graphic/Texture.cpp
62     ${SRCDIR}/Level/Awards.cpp
63     ${SRCDIR}/Level/Campaign.cpp
64     ${SRCDIR}/Level/Dialog.cpp
65     ${SRCDIR}/Level/Hotspot.cpp
66     ${SRCDIR}/Math/Frustum.cpp
67     ${SRCDIR}/Math/Quaternions.cpp
68     ${SRCDIR}/Menu/Menu.cpp
69     ${SRCDIR}/Objects/Object.cpp
70     ${SRCDIR}/Objects/Person.cpp
71     ${SRCDIR}/Objects/Weapons.cpp
72     ${SRCDIR}/User/Account.cpp
73     ${SRCDIR}/User/Settings.cpp
74     ${SRCDIR}/Utils/Folders.cpp
75     ${SRCDIR}/Utils/ImageIO.cpp
76     ${SRCDIR}/Utils/Input.cpp
77     ${SRCDIR}/Utils/pack.c
78     ${SRCDIR}/Utils/private.c
79     ${SRCDIR}/Utils/unpack.c
80     ${SRCDIR}/Game.cpp
81     ${SRCDIR}/GameDraw.cpp
82     ${SRCDIR}/GameInitDispose.cpp
83     ${SRCDIR}/GameTick.cpp
84     ${SRCDIR}/Globals.cpp
85     ${SRCDIR}/Tutorial.cpp
86
87 )
88
89 set(LUGARU_H
90     ${SRCDIR}/Animation/Animation.hpp
91     ${SRCDIR}/Animation/Joint.hpp
92     ${SRCDIR}/Animation/Muscle.hpp
93     ${SRCDIR}/Animation/Skeleton.hpp
94     ${SRCDIR}/Audio/openal_wrapper.hpp
95     ${SRCDIR}/Audio/Sounds.hpp
96     ${SRCDIR}/Devtools/ConsoleCmds.hpp
97     ${SRCDIR}/Environment/Lights.hpp
98     ${SRCDIR}/Environment/Skybox.hpp
99     ${SRCDIR}/Environment/Terrain.hpp
100     ${SRCDIR}/Graphic/gamegl.hpp
101     ${SRCDIR}/Graphic/Models.hpp
102     ${SRCDIR}/Graphic/Sprite.hpp
103     ${SRCDIR}/Graphic/Stereo.hpp
104     ${SRCDIR}/Graphic/Text.hpp
105     ${SRCDIR}/Graphic/Texture.hpp
106     ${SRCDIR}/Level/Campaign.hpp
107     ${SRCDIR}/Level/Dialog.hpp
108     ${SRCDIR}/Level/Hotspot.hpp
109     ${SRCDIR}/Math/Frustum.hpp
110     ${SRCDIR}/Math/PhysicsMath.hpp
111     ${SRCDIR}/Math/Quaternions.hpp
112     ${SRCDIR}/Math/Random.hpp
113     ${SRCDIR}/Menu/Menu.hpp
114     ${SRCDIR}/Objects/Object.hpp
115     ${SRCDIR}/Objects/Person.hpp
116     ${SRCDIR}/Objects/Weapons.hpp
117     ${SRCDIR}/Thirdparty/optionparser.h
118     ${SRCDIR}/User/Account.hpp
119     ${SRCDIR}/User/Settings.hpp
120     ${SRCDIR}/Utils/binio.h
121     ${SRCDIR}/Utils/Folders.hpp
122     ${SRCDIR}/Utils/ImageIO.hpp
123     ${SRCDIR}/Utils/Input.hpp
124     ${SRCDIR}/Utils/private.h
125     ${SRCDIR}/Game.hpp
126     ${SRCDIR}/Tutorial.hpp
127
128 )
129
130 if(UNIX)
131     set(LUGARU_SRCS
132         ${LUGARU_SRCS}
133         ${SRCDIR}/MacCompatibility.cpp
134     )
135     set(LUGARU_H
136         ${LUGARU_H}
137         ${SRCDIR}/MacCompatibility.hpp
138     )
139 endif(UNIX)
140
141 if(WIN32)
142     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
143                        COMMAND ${CMAKE_RC_COMPILER}
144                        -I${SRCDIR}/win-res
145                        -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
146                        -i${SRCDIR}/win-res/Lugaru.rc
147                        DEPENDS ${SRCDIR}/win-res/Lugaru.rc
148     )
149
150     # FIXME: get rid of this.
151     set(LUGARU_SRCS
152         ${LUGARU_SRCS}
153         ${SRCDIR}/WinDefs.cpp)
154
155     set(LUGARU_H
156         ${LUGARU_H}
157         ${SRCDIR}/WinDefs.hpp
158         ${SRCDIR}/win-res/resource.hpp)
159 endif(WIN32)
160
161 if(APPLE)
162     set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
163 endif(APPLE)
164
165
166 ### Dependencies
167
168 find_package(OpenGL REQUIRED)
169
170 # Windows is funky about OpenAL detection
171 if(WIN32)
172     pkg_check_modules(OPENAL openal REQUIRED)
173     set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
174 else(WIN32)
175     find_package(OpenAL REQUIRED)
176 endif(WIN32)
177
178 # macOS has problems with using pkgconfig to find SDL2
179 if(APPLE)
180     find_package(sdl2 REQUIRED)
181 else(APPLE)
182     pkg_check_modules(SDL2 sdl2 REQUIRED)
183 endif(APPLE)
184
185 find_package(PNG REQUIRED)
186 find_package(JPEG REQUIRED)
187 find_package(ZLIB REQUIRED)
188 find_package(OggVorbis REQUIRED)
189
190 include_directories(
191     ${OPENAL_INCLUDE_DIR}
192     ${JPEG_INCLUDE_DIR}
193     ${PNG_INCLUDE_DIR}
194     ${ZLIB_INCLUDE_DIR}
195     ${OPENGL_INCLUDE_DIR}
196     ${SDL2_INCLUDE_DIRS}
197     ${VORBISFILE_INCLUDE_DIR}
198     ${OGG_INCLUDE_DIR}
199     ${CMAKE_SOURCE_DIR}/Source
200 )
201
202 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
203
204
205 ### Definitions
206
207 if(WIN32)
208     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj)
209 else(WIN32)
210     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H})
211 endif(WIN32)
212
213 target_link_libraries(lugaru ${LUGARU_LIBS})
214
215 if(WIN32)
216     add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
217     if(MINGW)
218         # An alternative would be to use _WIN32 consistently instead of WIN32
219         add_definitions(-DWIN32)
220     endif(MINGW)
221 else(WIN32)
222     add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
223 endif(WIN32)
224
225
226 ### Installation
227
228 if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
229     set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
230 endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)
231
232 # OS-specific installation paths
233
234 set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX})
235 if(LINUX)
236 endif(LINUX)
237
238 if(APPLE)
239     set(LUGARU_APP_ROOT ${CMAKE_INSTALL_PREFIX}/Lugaru.app)
240     set(LUGARU_BINDIR ${LUGARU_APP_ROOT}/Contents/MacOS)
241     set(LUGARU_RESDIR ${LUGARU_APP_ROOT}/Contents/Resources)
242 endif(APPLE)
243
244 # Actual installation instructions
245
246 if(WIN32)
247     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
248     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
249     if(MINGW)
250         # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows
251         set(LIBGCC_S libgcc_s_sjlj-1.dll)
252         if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
253             set(LIBGCC_S libgcc_s_seh-1.dll)
254         endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
255         # FIXME: Filter out unneeded DLLs when building against some internal deps
256         set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
257         install(FILES ${DLL_ROOT}/${LIBGCC_S}
258                       ${DLL_ROOT}/libjpeg-62.dll
259                       ${DLL_ROOT}/libogg-0.dll
260                       ${DLL_ROOT}/libpng16-16.dll
261                       ${DLL_ROOT}/libstdc++-6.dll
262                       ${DLL_ROOT}/libvorbis-0.dll
263                       ${DLL_ROOT}/libvorbisfile-3.dll
264                       ${DLL_ROOT}/libwinpthread-1.dll
265                       ${DLL_ROOT}/OpenAL32.dll
266                       ${DLL_ROOT}/SDL2.dll
267                       ${DLL_ROOT}/zlib1.dll
268                 DESTINATION ${CMAKE_INSTALL_PREFIX})
269     endif(MINGW)
270 endif(WIN32)
271
272 if(LINUX)
273     if(SYSTEM_INSTALL)
274         add_definitions(-DDATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
275         set(LUGARU_DOCDIR ${CMAKE_INSTALL_DOCDIR})
276         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_BINDIR})
277         # Trailing '/' is significant, it installs and _renames_ Data/ as the destination folder
278         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
279         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/appdata)
280         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
281         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps)
282         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.6 DESTINATION ${CMAKE_INSTALL_MANDIR}/man6)
283     else(SYSTEM_INSTALL)
284         message("You are building Lugaru without having enabled the SYSTEM_INSTALL option. It will default to looking for the data in the 'Data' directory next to the binary.")
285         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
286         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
287     endif(SYSTEM_INSTALL)
288 endif(LINUX)
289
290 if(APPLE)
291     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR})
292     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${LUGARU_APP_ROOT})
293     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Lugaru.icns DESTINATION ${LUGARU_RESDIR})
294     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Info.plist DESTINATION ${LUGARU_APP_ROOT}/Contents)
295 endif(APPLE)
296
297 # Documentation
298
299 install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS
300               ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
301               ${CMAKE_SOURCE_DIR}/COPYING.txt
302               ${CMAKE_SOURCE_DIR}/README.md
303               ${CMAKE_SOURCE_DIR}/RELEASE-NOTES.md
304               ${CMAKE_SOURCE_DIR}/Docs/DEVTOOLS.txt
305               ${CMAKE_SOURCE_DIR}/Docs/README.Empire.txt
306               ${CMAKE_SOURCE_DIR}/Docs/README.SevenTasks.txt
307               ${CMAKE_SOURCE_DIR}/Docs/README.Temple.txt
308         DESTINATION ${LUGARU_DOCDIR})