]> git.jsancho.org Git - lugaru.git/blob - CMakeLists.txt
Remove zlib from documentation and CI setup
[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(STATUS "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 ### Version
44
45 # Version for the current (stable) or next (development) release
46 set(LUGARU_VERSION_MAJOR 1)
47 set(LUGARU_VERSION_MINOR 3)
48 set(LUGARU_VERSION_PATCH 0)
49
50 # MAJOR.MINOR, or MAJOR.MINOR.PATCH if PATCH != 0
51 set(LUGARU_VERSION_NUMBER "${LUGARU_VERSION_MAJOR}.${LUGARU_VERSION_MINOR}")
52 if(LUGARU_VERSION_PATCH)
53     set(LUGARU_VERSION_NUMBER "${LUGARU_VERSION_NUMBER}.${LUGARU_VERSION_PATCH}")
54 endif()
55
56 # Set to "" for stable (tagged) builds, "-dev" for dev builds
57 set(LUGARU_VERSION_SUFFIX "-dev")  # development
58 #set(LUGARU_VERSION_SUFFIX "")  # stable
59
60 # Set to 7-char git commit hash if available, otherwise "".
61 # On stable (tagged) builds, this is ignored.
62 set(LUGARU_VERSION_HASH "")
63 if(LUGARU_VERSION_SUFFIX STREQUAL "-dev" AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
64     find_package(Git)
65     if(GIT_FOUND)
66         execute_process(
67             COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
68             WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
69             OUTPUT_VARIABLE "LUGARU_VERSION_HASH"
70             ERROR_QUIET
71             OUTPUT_STRIP_TRAILING_WHITESPACE)
72         message(STATUS "Git commit hash: ${LUGARU_VERSION_HASH}")
73     endif()
74 endif()
75
76 set(LUGARU_VERSION_RELEASE "" CACHE STRING "Optional release string, e.g. for distro packages release number")
77
78 # Final string built from the above constants, following the scheme:
79 # MAJOR.MINOR[.PATCH][-dev] [(git HASH)] [[RELEASE]]
80 set(LUGARU_VERSION_STRING "${LUGARU_VERSION_NUMBER}${LUGARU_VERSION_SUFFIX}")
81 if(NOT LUGARU_VERSION_HASH STREQUAL "")
82     set(LUGARU_VERSION_STRING "${LUGARU_VERSION_STRING} (git ${LUGARU_VERSION_HASH})")
83 endif()
84 if(NOT LUGARU_VERSION_RELEASE STREQUAL "")
85     set(LUGARU_VERSION_STRING "${LUGARU_VERSION_STRING} [${LUGARU_VERSION_RELEASE}]")
86 endif()
87
88 message(STATUS "Version string: ${LUGARU_VERSION_STRING}")
89 configure_file(${SRCDIR}/Version.hpp.in ${SRCDIR}/Version.hpp ESCAPE_QUOTES @ONLY)
90
91
92 ### Sources
93
94 set(LUGARU_SRCS
95     ${SRCDIR}/main.cpp
96     ${SRCDIR}/Animation/Animation.cpp
97     ${SRCDIR}/Animation/Joint.cpp
98     ${SRCDIR}/Animation/Muscle.cpp
99     ${SRCDIR}/Animation/Skeleton.cpp
100     ${SRCDIR}/Audio/openal_wrapper.cpp
101     ${SRCDIR}/Audio/Sounds.cpp
102     ${SRCDIR}/Devtools/ConsoleCmds.cpp
103     ${SRCDIR}/Environment/Lights.cpp
104     ${SRCDIR}/Environment/Skybox.cpp
105     ${SRCDIR}/Environment/Terrain.cpp
106     ${SRCDIR}/Graphic/Decal.cpp
107     ${SRCDIR}/Graphic/Models.cpp
108     ${SRCDIR}/Graphic/Sprite.cpp
109     ${SRCDIR}/Graphic/Stereo.cpp
110     ${SRCDIR}/Graphic/Text.cpp
111     ${SRCDIR}/Graphic/Texture.cpp
112     ${SRCDIR}/Level/Awards.cpp
113     ${SRCDIR}/Level/Campaign.cpp
114     ${SRCDIR}/Level/Dialog.cpp
115     ${SRCDIR}/Level/Hotspot.cpp
116     ${SRCDIR}/Math/Frustum.cpp
117     ${SRCDIR}/Math/XYZ.cpp
118     ${SRCDIR}/Menu/Menu.cpp
119     ${SRCDIR}/Objects/Object.cpp
120     ${SRCDIR}/Objects/Person.cpp
121     ${SRCDIR}/Objects/PersonType.cpp
122     ${SRCDIR}/Objects/Weapons.cpp
123     ${SRCDIR}/Platform/PlatformUnix.cpp
124     ${SRCDIR}/Platform/PlatformWindows.cpp
125     ${SRCDIR}/User/Account.cpp
126     ${SRCDIR}/User/Settings.cpp
127     ${SRCDIR}/Utils/Folders.cpp
128     ${SRCDIR}/Utils/ImageIO.cpp
129     ${SRCDIR}/Utils/Input.cpp
130     ${SRCDIR}/Utils/pack.c
131     ${SRCDIR}/Utils/private.c
132     ${SRCDIR}/Utils/unpack.c
133     ${SRCDIR}/Game.cpp
134     ${SRCDIR}/GameDraw.cpp
135     ${SRCDIR}/GameInitDispose.cpp
136     ${SRCDIR}/GameTick.cpp
137     ${SRCDIR}/Globals.cpp
138     ${SRCDIR}/Tutorial.cpp
139
140 )
141
142 set(LUGARU_H
143     ${SRCDIR}/Animation/Animation.hpp
144     ${SRCDIR}/Animation/Joint.hpp
145     ${SRCDIR}/Animation/Muscle.hpp
146     ${SRCDIR}/Animation/Skeleton.hpp
147     ${SRCDIR}/Audio/openal_wrapper.hpp
148     ${SRCDIR}/Audio/Sounds.hpp
149     ${SRCDIR}/Devtools/ConsoleCmds.hpp
150     ${SRCDIR}/Environment/Lights.hpp
151     ${SRCDIR}/Environment/Skybox.hpp
152     ${SRCDIR}/Environment/Terrain.hpp
153     ${SRCDIR}/Graphic/Decal.hpp
154     ${SRCDIR}/Graphic/gamegl.hpp
155     ${SRCDIR}/Graphic/Models.hpp
156     ${SRCDIR}/Graphic/Sprite.hpp
157     ${SRCDIR}/Graphic/Stereo.hpp
158     ${SRCDIR}/Graphic/Text.hpp
159     ${SRCDIR}/Graphic/Texture.hpp
160     ${SRCDIR}/Level/Campaign.hpp
161     ${SRCDIR}/Level/Dialog.hpp
162     ${SRCDIR}/Level/Hotspot.hpp
163     ${SRCDIR}/Math/Frustum.hpp
164     ${SRCDIR}/Math/XYZ.hpp
165     ${SRCDIR}/Math/Random.hpp
166     ${SRCDIR}/Menu/Menu.hpp
167     ${SRCDIR}/Objects/Object.hpp
168     ${SRCDIR}/Objects/Person.hpp
169     ${SRCDIR}/Objects/PersonType.hpp
170     ${SRCDIR}/Objects/Weapons.hpp
171     ${SRCDIR}/Platform/Platform.hpp
172     ${SRCDIR}/Thirdparty/optionparser.h
173     ${SRCDIR}/User/Account.hpp
174     ${SRCDIR}/User/Settings.hpp
175     ${SRCDIR}/Utils/binio.h
176     ${SRCDIR}/Utils/Folders.hpp
177     ${SRCDIR}/Utils/ImageIO.hpp
178     ${SRCDIR}/Utils/Input.hpp
179     ${SRCDIR}/Utils/private.h
180     ${SRCDIR}/Game.hpp
181     ${SRCDIR}/Tutorial.hpp
182
183 )
184
185 set(LUGARU_OBJS "")
186 if(WIN32)
187     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Lugaru.res
188                        COMMAND ${CMAKE_RC_COMPILER}
189                        -o ${CMAKE_CURRENT_BINARY_DIR}/Lugaru.res
190                        -i${SRCDIR}/Lugaru.rc
191                        DEPENDS ${SRCDIR}/Lugaru.rc
192     )
193     set(LUGARU_OBJS "Lugaru.res")
194 endif(WIN32)
195
196 if(APPLE)
197     set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
198 endif(APPLE)
199
200
201 ### Dependencies
202
203 find_package(OpenGL REQUIRED)
204
205 # Windows is funky about OpenAL detection
206 if(WIN32)
207     pkg_check_modules(OPENAL openal REQUIRED)
208     set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
209 else(WIN32)
210     find_package(OpenAL REQUIRED)
211 endif(WIN32)
212
213 # macOS has problems with using pkgconfig to find SDL2
214 if(APPLE)
215     find_package(sdl2 REQUIRED)
216 else(APPLE)
217     pkg_check_modules(SDL2 sdl2 REQUIRED)
218 endif(APPLE)
219
220 find_package(PNG REQUIRED)
221 find_package(JPEG REQUIRED)
222 find_package(OggVorbis REQUIRED)
223
224 include_directories(
225     ${OPENAL_INCLUDE_DIR}
226     ${JPEG_INCLUDE_DIR}
227     ${PNG_INCLUDE_DIR}
228     ${OPENGL_INCLUDE_DIR}
229     ${SDL2_INCLUDE_DIRS}
230     ${VORBISFILE_INCLUDE_DIR}
231     ${CMAKE_SOURCE_DIR}/Source
232 )
233
234 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${SDL2_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${VORBISFILE_LIBRARY} ${PLATFORM_LIBS})
235
236
237 ### Definitions
238
239 add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} ${LUGARU_OBJS})
240 target_link_libraries(lugaru ${LUGARU_LIBS})
241
242 if(WIN32)
243     add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
244     if(MINGW)
245         # An alternative would be to use _WIN32 consistently instead of WIN32
246         add_definitions(-DWIN32)
247     endif(MINGW)
248 else(WIN32)
249     add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
250 endif(WIN32)
251
252
253 ### Installation
254
255 if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
256     set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
257 endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)
258
259 # OS-specific installation paths
260
261 set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX})
262 if(LINUX)
263 endif(LINUX)
264
265 if(APPLE)
266     set(LUGARU_APP_ROOT ${CMAKE_INSTALL_PREFIX}/Lugaru.app)
267     set(LUGARU_BINDIR ${LUGARU_APP_ROOT}/Contents/MacOS)
268     set(LUGARU_RESDIR ${LUGARU_APP_ROOT}/Contents/Resources)
269 endif(APPLE)
270
271 # Actual installation instructions
272
273 if(WIN32)
274     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
275     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
276     if(MINGW)
277         # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows
278         set(LIBGCC_S libgcc_s_sjlj-1.dll)
279         if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
280             set(LIBGCC_S libgcc_s_seh-1.dll)
281         endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
282         # FIXME: Filter out unneeded DLLs when building against some internal deps
283         set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
284         install(FILES ${DLL_ROOT}/${LIBGCC_S}
285                       ${DLL_ROOT}/libjpeg-62.dll
286                       ${DLL_ROOT}/libogg-0.dll
287                       ${DLL_ROOT}/libpng16-16.dll
288                       ${DLL_ROOT}/libstdc++-6.dll
289                       ${DLL_ROOT}/libvorbis-0.dll
290                       ${DLL_ROOT}/libvorbisfile-3.dll
291                       ${DLL_ROOT}/libwinpthread-1.dll
292                       ${DLL_ROOT}/OpenAL32.dll
293                       ${DLL_ROOT}/SDL2.dll
294                       ${DLL_ROOT}/zlib1.dll
295                 DESTINATION ${CMAKE_INSTALL_PREFIX})
296     endif(MINGW)
297 endif(WIN32)
298
299 if(LINUX)
300     if(SYSTEM_INSTALL)
301         add_definitions(-DDATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
302         set(LUGARU_DOCDIR ${CMAKE_INSTALL_DOCDIR})
303         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_BINDIR})
304         # Trailing '/' is significant, it installs and _renames_ Data/ as the destination folder
305         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
306         install(FILES ${CMAKE_SOURCE_DIR}/Dist/Linux/lugaru.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/appdata)
307         install(FILES ${CMAKE_SOURCE_DIR}/Dist/Linux/lugaru.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
308         install(FILES ${CMAKE_SOURCE_DIR}/Dist/Linux/lugaru.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps)
309         install(FILES ${CMAKE_SOURCE_DIR}/Dist/Linux/lugaru.6 DESTINATION ${CMAKE_INSTALL_MANDIR}/man6)
310     else(SYSTEM_INSTALL)
311         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.")
312         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
313         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
314     endif(SYSTEM_INSTALL)
315 endif(LINUX)
316
317 if(APPLE)
318     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR})
319     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${LUGARU_APP_ROOT})
320     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Lugaru.icns DESTINATION ${LUGARU_RESDIR})
321     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Info.plist DESTINATION ${LUGARU_APP_ROOT}/Contents)
322 endif(APPLE)
323
324 # Documentation
325
326 install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS
327               ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
328               ${CMAKE_SOURCE_DIR}/COPYING.txt
329               ${CMAKE_SOURCE_DIR}/README.md
330               ${CMAKE_SOURCE_DIR}/RELEASE-NOTES.md
331               ${CMAKE_SOURCE_DIR}/Docs/DEVTOOLS.txt
332               ${CMAKE_SOURCE_DIR}/Docs/README.Empire.txt
333               ${CMAKE_SOURCE_DIR}/Docs/README.SevenTasks.txt
334               ${CMAKE_SOURCE_DIR}/Docs/README.Temple.txt
335         DESTINATION ${LUGARU_DOCDIR})