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