| 1 |
cmake_minimum_required(VERSION 3.25) |
| 2 |
|
| 3 |
if(POLICY CMP0177) |
| 4 |
# Policy CMP0177: install() DESTINATION paths are normalized |
| 5 |
# Introduced in CMake 3.31 |
| 6 |
cmake_policy(SET CMP0177 NEW) |
| 7 |
endif() |
| 8 |
|
| 9 |
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) |
| 10 |
include(identity) |
| 11 |
|
| 12 |
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES C) |
| 13 |
|
| 14 |
option(BUILD_SERVER "Build dedicated server" ON) |
| 15 |
option(BUILD_CLIENT "Build client" ON) |
| 16 |
option(BUILD_RENDERER_GL1 "Build GL1 renderer" ON) |
| 17 |
option(BUILD_RENDERER_GL2 "Build GL2 renderer" ON) |
| 18 |
option(BUILD_GAME_LIBRARIES "Build game module libraries" ON) |
| 19 |
option(BUILD_GAME_QVMS "Build game module qvms" ON) |
| 20 |
option(BUILD_STANDALONE "Build binaries for standalone games" OFF) |
| 21 |
|
| 22 |
option(USE_RENDERER_DLOPEN "Dynamically load the renderer(s)" ON) |
| 23 |
option(USE_OPENAL "OpenAL audio" ON) |
| 24 |
option(USE_OPENAL_DLOPEN "Dynamically load OpenAL" ON) |
| 25 |
option(USE_HTTP "HTTP download support" ON) |
| 26 |
option(USE_CODEC_VORBIS "Ogg Vorbis support" ON) |
| 27 |
option(USE_CODEC_OPUS "Ogg Opus support" ON) |
| 28 |
option(USE_VOIP "Voice chat" ON) |
| 29 |
option(USE_MUMBLE "Mumble support" ON) |
| 30 |
option(USE_FREETYPE "Freetype font rendering" OFF) |
| 31 |
|
| 32 |
option(USE_INTERNAL_LIBS "Use internally packaged libraries" ON) |
| 33 |
option(USE_INTERNAL_SDL "Use internal SDL binary (if available)" ${USE_INTERNAL_LIBS}) |
| 34 |
option(USE_INTERNAL_ZLIB "Use internal copy of zlib" ${USE_INTERNAL_LIBS}) |
| 35 |
option(USE_INTERNAL_JPEG "Use internal copy of libjpeg" ${USE_INTERNAL_LIBS}) |
| 36 |
option(USE_INTERNAL_OGG "Use internal copy of ogg" ${USE_INTERNAL_LIBS}) |
| 37 |
option(USE_INTERNAL_VORBIS "Use internal copy of vorbis" ${USE_INTERNAL_LIBS}) |
| 38 |
option(USE_INTERNAL_OPUS "Use internal copy of opus" ${USE_INTERNAL_LIBS}) |
| 39 |
|
| 40 |
# Release build by default, set externally if you want something else |
| 41 |
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) |
| 42 |
set(CMAKE_BUILD_TYPE Release) |
| 43 |
endif() |
| 44 |
|
| 45 |
# Try to enable LTO by default |
| 46 |
include(CheckIPOSupported) |
| 47 |
check_ipo_supported(RESULT IPO_SUPPORTED) |
| 48 |
if(IPO_SUPPORTED) |
| 49 |
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) |
| 50 |
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE) |
| 51 |
endif() |
| 52 |
|
| 53 |
set(CMAKE_C_STANDARD 99) |
| 54 |
set(CMAKE_C_STANDARD_REQUIRED ON) |
| 55 |
set(CMAKE_SHARED_LIBRARY_PREFIX "") |
| 56 |
|
| 57 |
if(NOT PRODUCT_VERSION) |
| 58 |
set(PRODUCT_VERSION "${CMAKE_PROJECT_VERSION}") |
| 59 |
|
| 60 |
if(EXISTS "${CMAKE_SOURCE_DIR}/.git") |
| 61 |
execute_process( |
| 62 |
COMMAND git describe --tags --exact-match |
| 63 |
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 64 |
OUTPUT_VARIABLE GIT_TAG |
| 65 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 66 |
ERROR_QUIET) |
| 67 |
|
| 68 |
if(NOT GIT_TAG STREQUAL "${PRODUCT_VERSION}") |
| 69 |
execute_process( |
| 70 |
COMMAND git show -s --pretty=format:%h |
| 71 |
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 72 |
OUTPUT_VARIABLE GIT_REV |
| 73 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 74 |
ERROR_QUIET) |
| 75 |
|
| 76 |
if(GIT_REV) |
| 77 |
set(PRODUCT_VERSION "${PRODUCT_VERSION}_g${GIT_REV}") |
| 78 |
endif() |
| 79 |
endif() |
| 80 |
endif() |
| 81 |
endif() |
| 82 |
|
| 83 |
add_compile_definitions(PRODUCT_VERSION="${PRODUCT_VERSION}") |
| 84 |
|
| 85 |
# For CI to read from |
| 86 |
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/version.txt CONTENT ${PRODUCT_VERSION}) |
| 87 |
|
| 88 |
if(DEFINED ENV{SOURCE_DATE_EPOCH}) |
| 89 |
string(TIMESTAMP PRODUCT_DATE "%b %d %Y" UTC) |
| 90 |
add_compile_definitions(PRODUCT_DATE="${PRODUCT_DATE}") |
| 91 |
endif() |
| 92 |
|
| 93 |
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/code) |
| 94 |
|
| 95 |
include(compilers/all) |
| 96 |
include(platforms/all) |
| 97 |
include(libraries/all) |
| 98 |
|
| 99 |
include(server) |
| 100 |
include(renderer_gl1) |
| 101 |
include(renderer_gl2) |
| 102 |
include(client) |
| 103 |
include(basegame) |
| 104 |
include(missionpack) |
| 105 |
|
| 106 |
include(post_configure) |
| 107 |
include(installer) |