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

3
cmake_minimum_required(VERSION 3.5)
4

5
include(FindPkgConfig)
6
include(GNUInstallDirs)
MCMic's avatar
MCMic committed
7

8

9
### Helpers
10

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

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


18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
### 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)


40 41 42 43
### Version

# Version for the current (stable) or next (development) release
set(LUGARU_VERSION_MAJOR 1)
44
set(LUGARU_VERSION_MINOR 3)
45 46 47 48 49 50 51 52 53
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
54 55
set(LUGARU_VERSION_SUFFIX "-dev")  # development
#set(LUGARU_VERSION_SUFFIX "")  # stable
56 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

# 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)


89 90
### Sources

91
set(LUGARU_SRCS
92
    ${SRCDIR}/main.cpp
93
    ${SRCDIR}/Animation/Animation.cpp
94 95
    ${SRCDIR}/Animation/Joint.cpp
    ${SRCDIR}/Animation/Muscle.cpp
96
    ${SRCDIR}/Animation/Skeleton.cpp
97 98 99 100 101 102
    ${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's avatar
MCMic committed
103
    ${SRCDIR}/Graphic/Decal.cpp
104 105 106 107 108 109 110 111 112 113
    ${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
114
    ${SRCDIR}/Math/XYZ.cpp
115
    ${SRCDIR}/Menu/Menu.cpp
MCMic's avatar
MCMic committed
116
    ${SRCDIR}/Objects/Object.cpp
117
    ${SRCDIR}/Objects/Person.cpp
118
    ${SRCDIR}/Objects/PersonType.cpp
119
    ${SRCDIR}/Objects/Weapons.cpp
120 121
    ${SRCDIR}/Platform/PlatformUnix.cpp
    ${SRCDIR}/Platform/PlatformWindows.cpp
122 123 124 125 126 127 128 129
    ${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's avatar
MCMic committed
130 131 132 133 134
    ${SRCDIR}/Game.cpp
    ${SRCDIR}/GameDraw.cpp
    ${SRCDIR}/GameInitDispose.cpp
    ${SRCDIR}/GameTick.cpp
    ${SRCDIR}/Globals.cpp
135
    ${SRCDIR}/Tutorial.cpp
136

137 138 139
)

set(LUGARU_H
140 141 142 143 144 145 146 147 148 149
    ${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's avatar
MCMic committed
150
    ${SRCDIR}/Graphic/Decal.hpp
151 152 153 154 155 156 157 158 159 160
    ${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
161
    ${SRCDIR}/Math/XYZ.hpp
162 163
    ${SRCDIR}/Math/Random.hpp
    ${SRCDIR}/Menu/Menu.hpp
MCMic's avatar
MCMic committed
164
    ${SRCDIR}/Objects/Object.hpp
165
    ${SRCDIR}/Objects/Person.hpp
166
    ${SRCDIR}/Objects/PersonType.hpp
167
    ${SRCDIR}/Objects/Weapons.hpp
168
    ${SRCDIR}/Platform/Platform.hpp
169
    ${SRCDIR}/Thirdparty/optionparser.h
170 171
    ${SRCDIR}/User/Account.hpp
    ${SRCDIR}/User/Settings.hpp
172
    ${SRCDIR}/Utils/binio.h
173 174 175
    ${SRCDIR}/Utils/Folders.hpp
    ${SRCDIR}/Utils/ImageIO.hpp
    ${SRCDIR}/Utils/Input.hpp
176
    ${SRCDIR}/Utils/private.h
177
    ${SRCDIR}/Game.hpp
178
    ${SRCDIR}/Tutorial.hpp
179

180 181
)

182
set(LUGARU_OBJS "")
183
if(WIN32)
184
    add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Lugaru.res
185
                       COMMAND ${CMAKE_RC_COMPILER}
186
                       -o ${CMAKE_CURRENT_BINARY_DIR}/Lugaru.res
187 188
                       -i${SRCDIR}/Lugaru.rc
                       DEPENDS ${SRCDIR}/Lugaru.rc
189
    )
190
    set(LUGARU_OBJS "Lugaru.res")
191 192
endif(WIN32)

193
if(APPLE)
194
    set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
195
endif(APPLE)
196

197 198

### Dependencies
199

200
find_package(OpenGL REQUIRED)
201

202
# Windows is funky about OpenAL detection
203
if(WIN32)
204 205
    pkg_check_modules(OPENAL openal REQUIRED)
    set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
206
else(WIN32)
207
    find_package(OpenAL REQUIRED)
208
endif(WIN32)
209

210 211 212 213 214 215 216
# 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)

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

pkg_check_modules(VORBISFILE vorbisfile REQUIRED)
221
pkg_check_modules(JSONCPP jsoncpp REQUIRED)
222 223

include_directories(
224 225 226 227
    ${OPENAL_INCLUDE_DIR}
    ${JPEG_INCLUDE_DIR}
    ${PNG_INCLUDE_DIR}
    ${OPENGL_INCLUDE_DIR}
MCMic's avatar
MCMic committed
228
    ${SDL2_INCLUDE_DIRS}
229
    ${VORBISFILE_INCLUDE_DIR}
230
    ${JSONCPP_INCLUDE_DIRS}
231 232
    ${CMAKE_SOURCE_DIR}/Source
)
233

234
set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${SDL2_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${VORBISFILE_LIBRARIES} ${JSONCPP_LIBRARIES} ${PLATFORM_LIBS})
235

236

237 238
### Definitions

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

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

### Installation

255 256 257 258 259 260 261 262 263 264
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)

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

271 272
# Actual installation instructions

273
if(WIN32)
MCMic's avatar
MCMic committed
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 279 280 281 282 283 284 285
        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
286
                      ${DLL_ROOT}/libjsoncpp.dll
287 288 289 290 291 292
                      ${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
293
                      ${DLL_ROOT}/OpenAL32.dll
294 295 296 297
                      ${DLL_ROOT}/SDL2.dll
                      ${DLL_ROOT}/zlib1.dll
                DESTINATION ${CMAKE_INSTALL_PREFIX})
    endif(MINGW)
298 299
endif(WIN32)

300 301 302 303 304 305 306
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})
307 308 309 310
        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)
311
    else(SYSTEM_INSTALL)
312
        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.")
313 314 315 316
        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)
317 318

if(APPLE)
319 320
    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR})
    install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${LUGARU_APP_ROOT})
321
    install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Lugaru.icns DESTINATION ${LUGARU_RESDIR})
322
    install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Info.plist DESTINATION ${LUGARU_APP_ROOT}/Contents)
323
endif(APPLE)
324 325 326

# Documentation

327
install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS
328
              ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
329 330
              ${CMAKE_SOURCE_DIR}/COPYING.txt
              ${CMAKE_SOURCE_DIR}/README.md
331
              ${CMAKE_SOURCE_DIR}/RELEASE-NOTES.md
332 333
              ${CMAKE_SOURCE_DIR}/Docs/DEVTOOLS.txt
              ${CMAKE_SOURCE_DIR}/Docs/README.Empire.txt
334
              ${CMAKE_SOURCE_DIR}/Docs/README.SevenTasks.txt
335
              ${CMAKE_SOURCE_DIR}/Docs/README.Temple.txt
336
        DESTINATION ${LUGARU_DOCDIR})