3 cmake_minimum_required(VERSION 3.0)
4 cmake_policy(SET CMP0004 OLD)
7 include(GNUInstallDirs)
12 set(SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/Source")
14 if(UNIX AND NOT APPLE)
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}")
26 set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-parentheses -pedantic --std=gnu++11 ${CMAKE_CXX_FLAGS}")
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.")
37 option(SYSTEM_INSTALL "Enable system-wide installation, with hardcoded data directory defined with CMAKE_INSTALL_DATADIR" OFF)
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)
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}")
54 # Set to "" for stable (tagged) builds, "-dev" for dev builds
55 set(LUGARU_VERSION_SUFFIX "-dev") # development
56 #set(LUGARU_VERSION_SUFFIX "") # stable
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)
65 COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
66 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
67 OUTPUT_VARIABLE "LUGARU_VERSION_HASH"
69 OUTPUT_STRIP_TRAILING_WHITESPACE)
70 message(STATUS "Git commit hash: ${LUGARU_VERSION_HASH}")
74 set(LUGARU_VERSION_RELEASE "" CACHE STRING "Optional release string, e.g. for distro packages release number")
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})")
82 if(NOT LUGARU_VERSION_RELEASE STREQUAL "")
83 set(LUGARU_VERSION_STRING "${LUGARU_VERSION_STRING} [${LUGARU_VERSION_RELEASE}]")
86 message(STATUS "Version string: ${LUGARU_VERSION_STRING}")
87 configure_file(${SRCDIR}/Version.hpp.in ${SRCDIR}/Version.hpp ESCAPE_QUOTES @ONLY)
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
132 ${SRCDIR}/GameDraw.cpp
133 ${SRCDIR}/GameInitDispose.cpp
134 ${SRCDIR}/GameTick.cpp
135 ${SRCDIR}/Globals.cpp
136 ${SRCDIR}/Tutorial.cpp
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
179 ${SRCDIR}/Tutorial.hpp
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
191 set(LUGARU_OBJS "Lugaru.res")
195 set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
201 find_package(OpenGL REQUIRED)
203 # Windows is funky about OpenAL detection
205 pkg_check_modules(OPENAL openal REQUIRED)
206 set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
208 find_package(OpenAL REQUIRED)
211 # macOS has problems with using pkgconfig to find SDL2
213 find_package(sdl2 REQUIRED)
215 pkg_check_modules(SDL2 sdl2 REQUIRED)
218 find_package(PNG REQUIRED)
219 find_package(JPEG REQUIRED)
221 pkg_check_modules(VORBISFILE vorbisfile REQUIRED)
224 ${OPENAL_INCLUDE_DIR}
227 ${OPENGL_INCLUDE_DIR}
229 ${VORBISFILE_INCLUDE_DIR}
230 ${CMAKE_SOURCE_DIR}/Source
233 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${SDL2_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${VORBISFILE_LIBRARIES} ${PLATFORM_LIBS})
238 add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} ${LUGARU_OBJS})
239 target_link_libraries(lugaru ${LUGARU_LIBS})
242 add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
244 # An alternative would be to use _WIN32 consistently instead of WIN32
245 add_definitions(-DWIN32)
248 add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
254 if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
255 set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
256 endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)
258 # OS-specific installation paths
260 set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX})
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)
270 # Actual installation instructions
273 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
274 install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
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
293 ${DLL_ROOT}/zlib1.dll
294 DESTINATION ${CMAKE_INSTALL_PREFIX})
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)
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)
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)
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})