]> git.jsancho.org Git - lugaru.git/blob - CMakeLists.txt
Cleaned Terrain Decal handling
[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 -Wextra -Wno-parentheses -pedantic --std=gnu++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/Decal.cpp
58     ${SRCDIR}/Graphic/Models.cpp
59     ${SRCDIR}/Graphic/Sprite.cpp
60     ${SRCDIR}/Graphic/Stereo.cpp
61     ${SRCDIR}/Graphic/Text.cpp
62     ${SRCDIR}/Graphic/Texture.cpp
63     ${SRCDIR}/Level/Awards.cpp
64     ${SRCDIR}/Level/Campaign.cpp
65     ${SRCDIR}/Level/Dialog.cpp
66     ${SRCDIR}/Level/Hotspot.cpp
67     ${SRCDIR}/Math/Frustum.cpp
68     ${SRCDIR}/Math/Quaternions.cpp
69     ${SRCDIR}/Menu/Menu.cpp
70     ${SRCDIR}/Objects/Object.cpp
71     ${SRCDIR}/Objects/Person.cpp
72     ${SRCDIR}/Objects/Weapons.cpp
73     ${SRCDIR}/User/Account.cpp
74     ${SRCDIR}/User/Settings.cpp
75     ${SRCDIR}/Utils/Folders.cpp
76     ${SRCDIR}/Utils/ImageIO.cpp
77     ${SRCDIR}/Utils/Input.cpp
78     ${SRCDIR}/Utils/pack.c
79     ${SRCDIR}/Utils/private.c
80     ${SRCDIR}/Utils/unpack.c
81     ${SRCDIR}/Game.cpp
82     ${SRCDIR}/GameDraw.cpp
83     ${SRCDIR}/GameInitDispose.cpp
84     ${SRCDIR}/GameTick.cpp
85     ${SRCDIR}/Globals.cpp
86     ${SRCDIR}/Tutorial.cpp
87
88 )
89
90 set(LUGARU_H
91     ${SRCDIR}/Animation/Animation.hpp
92     ${SRCDIR}/Animation/Joint.hpp
93     ${SRCDIR}/Animation/Muscle.hpp
94     ${SRCDIR}/Animation/Skeleton.hpp
95     ${SRCDIR}/Audio/openal_wrapper.hpp
96     ${SRCDIR}/Audio/Sounds.hpp
97     ${SRCDIR}/Devtools/ConsoleCmds.hpp
98     ${SRCDIR}/Environment/Lights.hpp
99     ${SRCDIR}/Environment/Skybox.hpp
100     ${SRCDIR}/Environment/Terrain.hpp
101     ${SRCDIR}/Graphic/Decal.hpp
102     ${SRCDIR}/Graphic/gamegl.hpp
103     ${SRCDIR}/Graphic/Models.hpp
104     ${SRCDIR}/Graphic/Sprite.hpp
105     ${SRCDIR}/Graphic/Stereo.hpp
106     ${SRCDIR}/Graphic/Text.hpp
107     ${SRCDIR}/Graphic/Texture.hpp
108     ${SRCDIR}/Level/Campaign.hpp
109     ${SRCDIR}/Level/Dialog.hpp
110     ${SRCDIR}/Level/Hotspot.hpp
111     ${SRCDIR}/Math/Frustum.hpp
112     ${SRCDIR}/Math/PhysicsMath.hpp
113     ${SRCDIR}/Math/Quaternions.hpp
114     ${SRCDIR}/Math/Random.hpp
115     ${SRCDIR}/Menu/Menu.hpp
116     ${SRCDIR}/Objects/Object.hpp
117     ${SRCDIR}/Objects/Person.hpp
118     ${SRCDIR}/Objects/Weapons.hpp
119     ${SRCDIR}/Thirdparty/optionparser.h
120     ${SRCDIR}/User/Account.hpp
121     ${SRCDIR}/User/Settings.hpp
122     ${SRCDIR}/Utils/binio.h
123     ${SRCDIR}/Utils/Folders.hpp
124     ${SRCDIR}/Utils/ImageIO.hpp
125     ${SRCDIR}/Utils/Input.hpp
126     ${SRCDIR}/Utils/private.h
127     ${SRCDIR}/Game.hpp
128     ${SRCDIR}/Tutorial.hpp
129
130 )
131
132 if(UNIX)
133     set(LUGARU_SRCS
134         ${LUGARU_SRCS}
135         ${SRCDIR}/MacCompatibility.cpp
136     )
137     set(LUGARU_H
138         ${LUGARU_H}
139         ${SRCDIR}/MacCompatibility.hpp
140     )
141 endif(UNIX)
142
143 if(WIN32)
144     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
145                        COMMAND ${CMAKE_RC_COMPILER}
146                        -I${SRCDIR}/win-res
147                        -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
148                        -i${SRCDIR}/win-res/Lugaru.rc
149                        DEPENDS ${SRCDIR}/win-res/Lugaru.rc
150     )
151
152     # FIXME: get rid of this.
153     set(LUGARU_SRCS
154         ${LUGARU_SRCS}
155         ${SRCDIR}/WinDefs.cpp)
156
157     set(LUGARU_H
158         ${LUGARU_H}
159         ${SRCDIR}/WinDefs.hpp
160         ${SRCDIR}/win-res/resource.hpp)
161 endif(WIN32)
162
163 if(APPLE)
164     set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
165 endif(APPLE)
166
167
168 ### Dependencies
169
170 find_package(OpenGL REQUIRED)
171
172 # Windows is funky about OpenAL detection
173 if(WIN32)
174     pkg_check_modules(OPENAL openal REQUIRED)
175     set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
176 else(WIN32)
177     find_package(OpenAL REQUIRED)
178 endif(WIN32)
179
180 # macOS has problems with using pkgconfig to find SDL2
181 if(APPLE)
182     find_package(sdl2 REQUIRED)
183 else(APPLE)
184     pkg_check_modules(SDL2 sdl2 REQUIRED)
185 endif(APPLE)
186
187 find_package(PNG REQUIRED)
188 find_package(JPEG REQUIRED)
189 find_package(ZLIB REQUIRED)
190 find_package(OggVorbis REQUIRED)
191
192 include_directories(
193     ${OPENAL_INCLUDE_DIR}
194     ${JPEG_INCLUDE_DIR}
195     ${PNG_INCLUDE_DIR}
196     ${ZLIB_INCLUDE_DIR}
197     ${OPENGL_INCLUDE_DIR}
198     ${SDL2_INCLUDE_DIRS}
199     ${VORBISFILE_INCLUDE_DIR}
200     ${OGG_INCLUDE_DIR}
201     ${CMAKE_SOURCE_DIR}/Source
202 )
203
204 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
205
206
207 ### Definitions
208
209 if(WIN32)
210     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj)
211 else(WIN32)
212     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H})
213 endif(WIN32)
214
215 target_link_libraries(lugaru ${LUGARU_LIBS})
216
217 if(WIN32)
218     add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
219     if(MINGW)
220         # An alternative would be to use _WIN32 consistently instead of WIN32
221         add_definitions(-DWIN32)
222     endif(MINGW)
223 else(WIN32)
224     add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
225 endif(WIN32)
226
227
228 ### Installation
229
230 if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
231     set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
232 endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)
233
234 # OS-specific installation paths
235
236 set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX})
237 if(LINUX)
238 endif(LINUX)
239
240 if(APPLE)
241     set(LUGARU_APP_ROOT ${CMAKE_INSTALL_PREFIX}/Lugaru.app)
242     set(LUGARU_BINDIR ${LUGARU_APP_ROOT}/Contents/MacOS)
243     set(LUGARU_RESDIR ${LUGARU_APP_ROOT}/Contents/Resources)
244 endif(APPLE)
245
246 # Actual installation instructions
247
248 if(WIN32)
249     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
250     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
251     if(MINGW)
252         # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows
253         set(LIBGCC_S libgcc_s_sjlj-1.dll)
254         if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
255             set(LIBGCC_S libgcc_s_seh-1.dll)
256         endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
257         # FIXME: Filter out unneeded DLLs when building against some internal deps
258         set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
259         install(FILES ${DLL_ROOT}/${LIBGCC_S}
260                       ${DLL_ROOT}/libjpeg-62.dll
261                       ${DLL_ROOT}/libogg-0.dll
262                       ${DLL_ROOT}/libpng16-16.dll
263                       ${DLL_ROOT}/libstdc++-6.dll
264                       ${DLL_ROOT}/libvorbis-0.dll
265                       ${DLL_ROOT}/libvorbisfile-3.dll
266                       ${DLL_ROOT}/libwinpthread-1.dll
267                       ${DLL_ROOT}/OpenAL32.dll
268                       ${DLL_ROOT}/SDL2.dll
269                       ${DLL_ROOT}/zlib1.dll
270                 DESTINATION ${CMAKE_INSTALL_PREFIX})
271     endif(MINGW)
272 endif(WIN32)
273
274 if(LINUX)
275     if(SYSTEM_INSTALL)
276         add_definitions(-DDATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
277         set(LUGARU_DOCDIR ${CMAKE_INSTALL_DOCDIR})
278         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_BINDIR})
279         # Trailing '/' is significant, it installs and _renames_ Data/ as the destination folder
280         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
281         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/appdata)
282         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
283         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps)
284         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.6 DESTINATION ${CMAKE_INSTALL_MANDIR}/man6)
285     else(SYSTEM_INSTALL)
286         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.")
287         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
288         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
289     endif(SYSTEM_INSTALL)
290 endif(LINUX)
291
292 if(APPLE)
293     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR})
294     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${LUGARU_APP_ROOT})
295     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Lugaru.icns DESTINATION ${LUGARU_RESDIR})
296     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Info.plist DESTINATION ${LUGARU_APP_ROOT}/Contents)
297 endif(APPLE)
298
299 # Documentation
300
301 install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS
302               ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
303               ${CMAKE_SOURCE_DIR}/COPYING.txt
304               ${CMAKE_SOURCE_DIR}/README.md
305               ${CMAKE_SOURCE_DIR}/RELEASE-NOTES.md
306               ${CMAKE_SOURCE_DIR}/Docs/DEVTOOLS.txt
307               ${CMAKE_SOURCE_DIR}/Docs/README.Empire.txt
308               ${CMAKE_SOURCE_DIR}/Docs/README.SevenTasks.txt
309               ${CMAKE_SOURCE_DIR}/Docs/README.Temple.txt
310         DESTINATION ${LUGARU_DOCDIR})