CMakeLists.txt 11.4 KB
Newer Older
1 2
project(lugaru)

3
cmake_minimum_required(VERSION 3.0)
4
cmake_policy(SET CMP0004 OLD)
5

6
include(FindPkgConfig)
7
include(GNUInstallDirs)
MCMic committed
8

9

10
### Helpers
11

12
set(SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/Source")
13 14 15 16 17 18

if(UNIX AND NOT APPLE)
    set(LINUX TRUE)
endif()


19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
### CMake config

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif(NOT CMAKE_BUILD_TYPE)
message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")

set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-parentheses -pedantic --std=gnu++11 ${CMAKE_CXX_FLAGS}")

if(APPLE)
    set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX")
    set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING
        "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value")
    set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.11.sdk" CACHE PATH
        "The product will be built against the headers and libraries located inside the indicated SDK.")
endif(APPLE)

if(LINUX)
    option(SYSTEM_INSTALL "Enable system-wide installation, with hardcoded data directory defined with CMAKE_INSTALL_DATADIR" OFF)
endif(LINUX)


41 42 43 44
### Version

# Version for the current (stable) or next (development) release
set(LUGARU_VERSION_MAJOR 1)
45
set(LUGARU_VERSION_MINOR 3)
46 47 48 49 50 51 52 53 54
set(LUGARU_VERSION_PATCH 0)

# MAJOR.MINOR, or MAJOR.MINOR.PATCH if PATCH != 0
set(LUGARU_VERSION_NUMBER "${LUGARU_VERSION_MAJOR}.${LUGARU_VERSION_MINOR}")
if(LUGARU_VERSION_PATCH)
    set(LUGARU_VERSION_NUMBER "${LUGARU_VERSION_NUMBER}.${LUGARU_VERSION_PATCH}")
endif()

# Set to "" for stable (tagged) builds, "-dev" for dev builds
55 56
set(LUGARU_VERSION_SUFFIX "-dev")  # development
#set(LUGARU_VERSION_SUFFIX "")  # stable
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

# Set to 7-char git commit hash if available, otherwise "".
# On stable (tagged) builds, this is ignored.
set(LUGARU_VERSION_HASH "")
if(LUGARU_VERSION_SUFFIX STREQUAL "-dev" AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
    find_package(Git)
    if(GIT_FOUND)
        execute_process(
            COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
            WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
            OUTPUT_VARIABLE "LUGARU_VERSION_HASH"
            ERROR_QUIET
            OUTPUT_STRIP_TRAILING_WHITESPACE)
        message(STATUS "Git commit hash: ${LUGARU_VERSION_HASH}")
    endif()
endif()

set(LUGARU_VERSION_RELEASE "" CACHE STRING "Optional release string, e.g. for distro packages release number")

# Final string built from the above constants, following the scheme:
# MAJOR.MINOR[.PATCH][-dev] [(git HASH)] [[RELEASE]]
set(LUGARU_VERSION_STRING "${LUGARU_VERSION_NUMBER}${LUGARU_VERSION_SUFFIX}")
if(NOT LUGARU_VERSION_HASH STREQUAL "")
    set(LUGARU_VERSION_STRING "${LUGARU_VERSION_STRING} (git ${LUGARU_VERSION_HASH})")
endif()
if(NOT LUGARU_VERSION_RELEASE STREQUAL "")
    set(LUGARU_VERSION_STRING "${LUGARU_VERSION_STRING} [${LUGARU_VERSION_RELEASE}]")
endif()

message(STATUS "Version string: ${LUGARU_VERSION_STRING}")
configure_file(${SRCDIR}/Version.hpp.in ${SRCDIR}/Version.hpp ESCAPE_QUOTES @ONLY)


90 91
### Sources

92
set(LUGARU_SRCS
93
    ${SRCDIR}/main.cpp
94
    ${SRCDIR}/Animation/Animation.cpp
95 96
    ${SRCDIR}/Animation/Joint.cpp
    ${SRCDIR}/Animation/Muscle.cpp
97
    ${SRCDIR}/Animation/Skeleton.cpp
98 99 100 101 102 103
    ${SRCDIR}/Audio/openal_wrapper.cpp
    ${SRCDIR}/Audio/Sounds.cpp
    ${SRCDIR}/Devtools/ConsoleCmds.cpp
    ${SRCDIR}/Environment/Lights.cpp
    ${SRCDIR}/Environment/Skybox.cpp
    ${SRCDIR}/Environment/Terrain.cpp
MCMic committed
104
    ${SRCDIR}/Graphic/Decal.cpp
105 106 107 108 109 110 111 112 113 114
    ${SRCDIR}/Graphic/Models.cpp
    ${SRCDIR}/Graphic/Sprite.cpp
    ${SRCDIR}/Graphic/Stereo.cpp
    ${SRCDIR}/Graphic/Text.cpp
    ${SRCDIR}/Graphic/Texture.cpp
    ${SRCDIR}/Level/Awards.cpp
    ${SRCDIR}/Level/Campaign.cpp
    ${SRCDIR}/Level/Dialog.cpp
    ${SRCDIR}/Level/Hotspot.cpp
    ${SRCDIR}/Math/Frustum.cpp
115
    ${SRCDIR}/Math/XYZ.cpp
116
    ${SRCDIR}/Menu/Menu.cpp
MCMic committed
117
    ${SRCDIR}/Objects/Object.cpp
118
    ${SRCDIR}/Objects/Person.cpp
119
    ${SRCDIR}/Objects/PersonType.cpp
120
    ${SRCDIR}/Objects/Weapons.cpp
121 122
    ${SRCDIR}/Platform/PlatformUnix.cpp
    ${SRCDIR}/Platform/PlatformWindows.cpp
123 124 125 126 127 128 129 130
    ${SRCDIR}/User/Account.cpp
    ${SRCDIR}/User/Settings.cpp
    ${SRCDIR}/Utils/Folders.cpp
    ${SRCDIR}/Utils/ImageIO.cpp
    ${SRCDIR}/Utils/Input.cpp
    ${SRCDIR}/Utils/pack.c
    ${SRCDIR}/Utils/private.c
    ${SRCDIR}/Utils/unpack.c
MCMic committed
131 132 133 134 135
    ${SRCDIR}/Game.cpp
    ${SRCDIR}/GameDraw.cpp
    ${SRCDIR}/GameInitDispose.cpp
    ${SRCDIR}/GameTick.cpp
    ${SRCDIR}/Globals.cpp
136
    ${SRCDIR}/Tutorial.cpp
137

138 139 140
)

set(LUGARU_H
141 142 143 144 145 146 147 148 149 150
    ${SRCDIR}/Animation/Animation.hpp
    ${SRCDIR}/Animation/Joint.hpp
    ${SRCDIR}/Animation/Muscle.hpp
    ${SRCDIR}/Animation/Skeleton.hpp
    ${SRCDIR}/Audio/openal_wrapper.hpp
    ${SRCDIR}/Audio/Sounds.hpp
    ${SRCDIR}/Devtools/ConsoleCmds.hpp
    ${SRCDIR}/Environment/Lights.hpp
    ${SRCDIR}/Environment/Skybox.hpp
    ${SRCDIR}/Environment/Terrain.hpp
MCMic committed
151
    ${SRCDIR}/Graphic/Decal.hpp
152 153 154 155 156 157 158 159 160 161
    ${SRCDIR}/Graphic/gamegl.hpp
    ${SRCDIR}/Graphic/Models.hpp
    ${SRCDIR}/Graphic/Sprite.hpp
    ${SRCDIR}/Graphic/Stereo.hpp
    ${SRCDIR}/Graphic/Text.hpp
    ${SRCDIR}/Graphic/Texture.hpp
    ${SRCDIR}/Level/Campaign.hpp
    ${SRCDIR}/Level/Dialog.hpp
    ${SRCDIR}/Level/Hotspot.hpp
    ${SRCDIR}/Math/Frustum.hpp
162
    ${SRCDIR}/Math/XYZ.hpp
163 164
    ${SRCDIR}/Math/Random.hpp
    ${SRCDIR}/Menu/Menu.hpp
MCMic committed
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 172
    ${SRCDIR}/User/Account.hpp
    ${SRCDIR}/User/Settings.hpp
173
    ${SRCDIR}/Utils/binio.h
174 175 176
    ${SRCDIR}/Utils/Folders.hpp
    ${SRCDIR}/Utils/ImageIO.hpp
    ${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 189
                       -i${SRCDIR}/Lugaru.rc
                       DEPENDS ${SRCDIR}/Lugaru.rc
190
    )
191
    set(LUGARU_OBJS "Lugaru.res")
192 193
endif(WIN32)

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 206
    pkg_check_modules(OPENAL openal REQUIRED)
    set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
207
else(WIN32)
208
    find_package(OpenAL REQUIRED)
209
endif(WIN32)
210

211 212 213 214 215 216 217
# macOS has problems with using pkgconfig to find SDL2
if(APPLE)
    find_package(sdl2 REQUIRED)
else(APPLE)
    pkg_check_modules(SDL2 sdl2 REQUIRED)
endif(APPLE)

218 219
find_package(PNG REQUIRED)
find_package(JPEG REQUIRED)
220 221

pkg_check_modules(VORBISFILE vorbisfile REQUIRED)
222 223

include_directories(
224 225 226 227
    ${OPENAL_INCLUDE_DIR}
    ${JPEG_INCLUDE_DIR}
    ${PNG_INCLUDE_DIR}
    ${OPENGL_INCLUDE_DIR}
MCMic committed
228
    ${SDL2_INCLUDE_DIRS}
229 230 231
    ${VORBISFILE_INCLUDE_DIR}
    ${CMAKE_SOURCE_DIR}/Source
)
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 237
### Definitions

238
add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} ${LUGARU_OBJS})
239 240 241
target_link_libraries(lugaru ${LUGARU_LIBS})

if(WIN32)
242
    add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
MCMic committed
243
    if(MINGW)
244
        # An alternative would be to use _WIN32 consistently instead of WIN32
MCMic committed
245 246
        add_definitions(-DWIN32)
    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 253

### Installation

254 255 256 257 258 259 260 261 262 263
if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
    set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)

# OS-specific installation paths

set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX})
if(LINUX)
endif(LINUX)

264
if(APPLE)
265 266
    set(LUGARU_APP_ROOT ${CMAKE_INSTALL_PREFIX}/Lugaru.app)
    set(LUGARU_BINDIR ${LUGARU_APP_ROOT}/Contents/MacOS)
267
    set(LUGARU_RESDIR ${LUGARU_APP_ROOT}/Contents/Resources)
268 269
endif(APPLE)

270 271
# Actual installation instructions

272
if(WIN32)
MCMic committed
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 278 279 280 281 282 283 284 285 286 287 288 289 290
        set(LIBGCC_S libgcc_s_sjlj-1.dll)
        if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
            set(LIBGCC_S libgcc_s_seh-1.dll)
        endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
        # FIXME: Filter out unneeded DLLs when building against some internal deps
        set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
        install(FILES ${DLL_ROOT}/${LIBGCC_S}
                      ${DLL_ROOT}/libjpeg-62.dll
                      ${DLL_ROOT}/libogg-0.dll
                      ${DLL_ROOT}/libpng16-16.dll
                      ${DLL_ROOT}/libstdc++-6.dll
                      ${DLL_ROOT}/libvorbis-0.dll
                      ${DLL_ROOT}/libvorbisfile-3.dll
                      ${DLL_ROOT}/libwinpthread-1.dll
291
                      ${DLL_ROOT}/OpenAL32.dll
292 293 294 295
                      ${DLL_ROOT}/SDL2.dll
                      ${DLL_ROOT}/zlib1.dll
                DESTINATION ${CMAKE_INSTALL_PREFIX})
    endif(MINGW)
296 297
endif(WIN32)

298 299 300 301 302 303 304
if(LINUX)
    if(SYSTEM_INSTALL)
        add_definitions(-DDATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
        set(LUGARU_DOCDIR ${CMAKE_INSTALL_DOCDIR})
        install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_BINDIR})
        # Trailing '/' is significant, it installs and _renames_ Data/ as the destination folder
        install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
305 306 307 308
        install(FILES ${CMAKE_SOURCE_DIR}/Dist/Linux/lugaru.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/appdata)
        install(FILES ${CMAKE_SOURCE_DIR}/Dist/Linux/lugaru.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
        install(FILES ${CMAKE_SOURCE_DIR}/Dist/Linux/lugaru.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps)
        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 312 313 314
        install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
        install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
    endif(SYSTEM_INSTALL)
endif(LINUX)
315 316

if(APPLE)
317 318
    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR})
    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 324

# Documentation

325
install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS
326
              ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
327 328
              ${CMAKE_SOURCE_DIR}/COPYING.txt
              ${CMAKE_SOURCE_DIR}/README.md
329
              ${CMAKE_SOURCE_DIR}/RELEASE-NOTES.md
330 331
              ${CMAKE_SOURCE_DIR}/Docs/DEVTOOLS.txt
              ${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})