]> git.jsancho.org Git - lugaru.git/blob - CMakeLists.txt
Dialogs: Fix long lines overflowing the box
[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 ### Version
20
21 # Version for the current (stable) or next (development) release
22 set(LUGARU_VERSION_MAJOR 1)
23 set(LUGARU_VERSION_MINOR 2)
24 set(LUGARU_VERSION_PATCH 0)
25
26 # MAJOR.MINOR, or MAJOR.MINOR.PATCH if PATCH != 0
27 set(LUGARU_VERSION_NUMBER "${LUGARU_VERSION_MAJOR}.${LUGARU_VERSION_MINOR}")
28 if(LUGARU_VERSION_PATCH)
29     set(LUGARU_VERSION_NUMBER "${LUGARU_VERSION_NUMBER}.${LUGARU_VERSION_PATCH}")
30 endif()
31
32 # Set to "" for stable (tagged) builds, "-dev" for dev builds
33 set(LUGARU_VERSION_SUFFIX "-dev")  # development
34 #set(LUGARU_VERSION_SUFFIX "")  # stable
35
36 # Set to 7-char git commit hash if available, otherwise "".
37 # On stable (tagged) builds, this is ignored.
38 set(LUGARU_VERSION_HASH "")
39 if(LUGARU_VERSION_SUFFIX STREQUAL "-dev" AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
40     find_package(Git)
41     if(GIT_FOUND)
42         execute_process(
43             COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
44             WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
45             OUTPUT_VARIABLE "LUGARU_VERSION_HASH"
46             ERROR_QUIET
47             OUTPUT_STRIP_TRAILING_WHITESPACE)
48         message(STATUS "Git commit hash: ${LUGARU_VERSION_HASH}")
49     endif()
50 endif()
51
52 set(LUGARU_VERSION_RELEASE "" CACHE STRING "Optional release string, e.g. for distro packages release number")
53
54 # Final string built from the above constants, following the scheme:
55 # MAJOR.MINOR[.PATCH][-dev] [(git HASH)] [[RELEASE]]
56 set(LUGARU_VERSION_STRING "${LUGARU_VERSION_NUMBER}${LUGARU_VERSION_SUFFIX}")
57 if(NOT LUGARU_VERSION_HASH STREQUAL "")
58     set(LUGARU_VERSION_STRING "${LUGARU_VERSION_STRING} (git ${LUGARU_VERSION_HASH})")
59 endif()
60 if(NOT LUGARU_VERSION_RELEASE STREQUAL "")
61     set(LUGARU_VERSION_STRING "${LUGARU_VERSION_STRING} [${LUGARU_VERSION_RELEASE}]")
62 endif()
63
64 message(STATUS "Version string: ${LUGARU_VERSION_STRING}")
65 configure_file(${SRCDIR}/Version.hpp.in ${SRCDIR}/Version.hpp ESCAPE_QUOTES @ONLY)
66
67
68 ### CMake config
69
70 if(NOT CMAKE_BUILD_TYPE)
71     set(CMAKE_BUILD_TYPE RelWithDebInfo)
72 endif(NOT CMAKE_BUILD_TYPE)
73 message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")
74
75 set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-parentheses -pedantic --std=gnu++11 ${CMAKE_CXX_FLAGS}")
76
77 if(APPLE)
78     set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX")
79     set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING
80         "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value")
81     set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.11.sdk" CACHE PATH
82         "The product will be built against the headers and libraries located inside the indicated SDK.")
83 endif(APPLE)
84
85 if(LINUX)
86     option(SYSTEM_INSTALL "Enable system-wide installation, with hardcoded data directory defined with CMAKE_INSTALL_DATADIR" OFF)
87 endif(LINUX)
88
89 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake/Modules/")
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/Weapons.cpp
122     ${SRCDIR}/User/Account.cpp
123     ${SRCDIR}/User/Settings.cpp
124     ${SRCDIR}/Utils/Folders.cpp
125     ${SRCDIR}/Utils/ImageIO.cpp
126     ${SRCDIR}/Utils/Input.cpp
127     ${SRCDIR}/Utils/pack.c
128     ${SRCDIR}/Utils/private.c
129     ${SRCDIR}/Utils/unpack.c
130     ${SRCDIR}/Game.cpp
131     ${SRCDIR}/GameDraw.cpp
132     ${SRCDIR}/GameInitDispose.cpp
133     ${SRCDIR}/GameTick.cpp
134     ${SRCDIR}/Globals.cpp
135     ${SRCDIR}/Tutorial.cpp
136
137 )
138
139 set(LUGARU_H
140     ${SRCDIR}/Animation/Animation.hpp
141     ${SRCDIR}/Animation/Joint.hpp
142     ${SRCDIR}/Animation/Muscle.hpp
143     ${SRCDIR}/Animation/Skeleton.hpp
144     ${SRCDIR}/Audio/openal_wrapper.hpp
145     ${SRCDIR}/Audio/Sounds.hpp
146     ${SRCDIR}/Devtools/ConsoleCmds.hpp
147     ${SRCDIR}/Environment/Lights.hpp
148     ${SRCDIR}/Environment/Skybox.hpp
149     ${SRCDIR}/Environment/Terrain.hpp
150     ${SRCDIR}/Graphic/Decal.hpp
151     ${SRCDIR}/Graphic/gamegl.hpp
152     ${SRCDIR}/Graphic/Models.hpp
153     ${SRCDIR}/Graphic/Sprite.hpp
154     ${SRCDIR}/Graphic/Stereo.hpp
155     ${SRCDIR}/Graphic/Text.hpp
156     ${SRCDIR}/Graphic/Texture.hpp
157     ${SRCDIR}/Level/Campaign.hpp
158     ${SRCDIR}/Level/Dialog.hpp
159     ${SRCDIR}/Level/Hotspot.hpp
160     ${SRCDIR}/Math/Frustum.hpp
161     ${SRCDIR}/Math/XYZ.hpp
162     ${SRCDIR}/Math/Random.hpp
163     ${SRCDIR}/Menu/Menu.hpp
164     ${SRCDIR}/Objects/Object.hpp
165     ${SRCDIR}/Objects/Person.hpp
166     ${SRCDIR}/Objects/Weapons.hpp
167     ${SRCDIR}/Thirdparty/optionparser.h
168     ${SRCDIR}/User/Account.hpp
169     ${SRCDIR}/User/Settings.hpp
170     ${SRCDIR}/Utils/binio.h
171     ${SRCDIR}/Utils/Folders.hpp
172     ${SRCDIR}/Utils/ImageIO.hpp
173     ${SRCDIR}/Utils/Input.hpp
174     ${SRCDIR}/Utils/private.h
175     ${SRCDIR}/Game.hpp
176     ${SRCDIR}/Tutorial.hpp
177
178 )
179
180 if(UNIX)
181     set(LUGARU_SRCS
182         ${LUGARU_SRCS}
183         ${SRCDIR}/MacCompatibility.cpp
184     )
185     set(LUGARU_H
186         ${LUGARU_H}
187         ${SRCDIR}/MacCompatibility.hpp
188     )
189 endif(UNIX)
190
191 if(WIN32)
192     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
193                        COMMAND ${CMAKE_RC_COMPILER}
194                        -I${SRCDIR}/win-res
195                        -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
196                        -i${SRCDIR}/win-res/Lugaru.rc
197                        DEPENDS ${SRCDIR}/win-res/Lugaru.rc
198     )
199
200     # FIXME: get rid of this.
201     set(LUGARU_SRCS
202         ${LUGARU_SRCS}
203         ${SRCDIR}/WinDefs.cpp)
204
205     set(LUGARU_H
206         ${LUGARU_H}
207         ${SRCDIR}/WinDefs.hpp
208         ${SRCDIR}/win-res/resource.hpp)
209 endif(WIN32)
210
211 if(APPLE)
212     set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
213 endif(APPLE)
214
215
216 ### Dependencies
217
218 find_package(OpenGL REQUIRED)
219
220 # Windows is funky about OpenAL detection
221 if(WIN32)
222     pkg_check_modules(OPENAL openal REQUIRED)
223     set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
224 else(WIN32)
225     find_package(OpenAL REQUIRED)
226 endif(WIN32)
227
228 # macOS has problems with using pkgconfig to find SDL2
229 if(APPLE)
230     find_package(sdl2 REQUIRED)
231 else(APPLE)
232     pkg_check_modules(SDL2 sdl2 REQUIRED)
233 endif(APPLE)
234
235 find_package(PNG REQUIRED)
236 find_package(JPEG REQUIRED)
237 find_package(ZLIB REQUIRED)
238 find_package(OggVorbis REQUIRED)
239
240 include_directories(
241     ${OPENAL_INCLUDE_DIR}
242     ${JPEG_INCLUDE_DIR}
243     ${PNG_INCLUDE_DIR}
244     ${ZLIB_INCLUDE_DIR}
245     ${OPENGL_INCLUDE_DIR}
246     ${SDL2_INCLUDE_DIRS}
247     ${VORBISFILE_INCLUDE_DIR}
248     ${OGG_INCLUDE_DIR}
249     ${CMAKE_SOURCE_DIR}/Source
250 )
251
252 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
253
254
255 ### Definitions
256
257 if(WIN32)
258     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj)
259 else(WIN32)
260     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H})
261 endif(WIN32)
262
263 target_link_libraries(lugaru ${LUGARU_LIBS})
264
265 if(WIN32)
266     add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
267     if(MINGW)
268         # An alternative would be to use _WIN32 consistently instead of WIN32
269         add_definitions(-DWIN32)
270     endif(MINGW)
271 else(WIN32)
272     add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
273 endif(WIN32)
274
275
276 ### Installation
277
278 if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
279     set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
280 endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)
281
282 # OS-specific installation paths
283
284 set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX})
285 if(LINUX)
286 endif(LINUX)
287
288 if(APPLE)
289     set(LUGARU_APP_ROOT ${CMAKE_INSTALL_PREFIX}/Lugaru.app)
290     set(LUGARU_BINDIR ${LUGARU_APP_ROOT}/Contents/MacOS)
291     set(LUGARU_RESDIR ${LUGARU_APP_ROOT}/Contents/Resources)
292 endif(APPLE)
293
294 # Actual installation instructions
295
296 if(WIN32)
297     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
298     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
299     if(MINGW)
300         # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows
301         set(LIBGCC_S libgcc_s_sjlj-1.dll)
302         if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
303             set(LIBGCC_S libgcc_s_seh-1.dll)
304         endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
305         # FIXME: Filter out unneeded DLLs when building against some internal deps
306         set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
307         install(FILES ${DLL_ROOT}/${LIBGCC_S}
308                       ${DLL_ROOT}/libjpeg-62.dll
309                       ${DLL_ROOT}/libogg-0.dll
310                       ${DLL_ROOT}/libpng16-16.dll
311                       ${DLL_ROOT}/libstdc++-6.dll
312                       ${DLL_ROOT}/libvorbis-0.dll
313                       ${DLL_ROOT}/libvorbisfile-3.dll
314                       ${DLL_ROOT}/libwinpthread-1.dll
315                       ${DLL_ROOT}/OpenAL32.dll
316                       ${DLL_ROOT}/SDL2.dll
317                       ${DLL_ROOT}/zlib1.dll
318                 DESTINATION ${CMAKE_INSTALL_PREFIX})
319     endif(MINGW)
320 endif(WIN32)
321
322 if(LINUX)
323     if(SYSTEM_INSTALL)
324         add_definitions(-DDATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
325         set(LUGARU_DOCDIR ${CMAKE_INSTALL_DOCDIR})
326         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_BINDIR})
327         # Trailing '/' is significant, it installs and _renames_ Data/ as the destination folder
328         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
329         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/appdata)
330         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
331         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps)
332         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.6 DESTINATION ${CMAKE_INSTALL_MANDIR}/man6)
333     else(SYSTEM_INSTALL)
334         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.")
335         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
336         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
337     endif(SYSTEM_INSTALL)
338 endif(LINUX)
339
340 if(APPLE)
341     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR})
342     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${LUGARU_APP_ROOT})
343     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Lugaru.icns DESTINATION ${LUGARU_RESDIR})
344     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Info.plist DESTINATION ${LUGARU_APP_ROOT}/Contents)
345 endif(APPLE)
346
347 # Documentation
348
349 install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS
350               ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
351               ${CMAKE_SOURCE_DIR}/COPYING.txt
352               ${CMAKE_SOURCE_DIR}/README.md
353               ${CMAKE_SOURCE_DIR}/RELEASE-NOTES.md
354               ${CMAKE_SOURCE_DIR}/Docs/DEVTOOLS.txt
355               ${CMAKE_SOURCE_DIR}/Docs/README.Empire.txt
356               ${CMAKE_SOURCE_DIR}/Docs/README.SevenTasks.txt
357               ${CMAKE_SOURCE_DIR}/Docs/README.Temple.txt
358         DESTINATION ${LUGARU_DOCDIR})