-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
242 lines (204 loc) · 8.16 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
cmake_minimum_required(VERSION 3.15...3.26)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# CMP0077 supress some arcane CMake warning when using vcpkg.
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(VCPKG_OVERLAY_TRIPLETS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/triplets)
# Automatically copy dependencies into the output directory for executables when using vcpkg.
set(VCPKG_APPLOCAL_DEPS ON)
# Automatically installs dependencies when using vcpkg.
set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON)
Option(VCPKG_MANIFEST_MODE "Operate in vcpkg manifest mode instead of classic mode" ON)
# Project Name and Version
project("Russian Doom" VERSION 6.3 LANGUAGES C NONE)
set(PACKAGE_ID "io.github.russian_doom.russian_doom")
# Compile modules
Option(RD_COMPILE_DOOM "Compile Doom module" ON)
Option(RD_COMPILE_HERETIC "Compile Heretic module" ON)
Option(RD_COMPILE_HEXEN "Compile Hexen module" ON)
Option(RD_TEST_WITH_GDB "Attach gdb to CTest tests" OFF)
include(CMakeDependentOption)
find_package(Git)
find_package(Python3 COMPONENTS Interpreter)
cmake_dependent_option(RD_BUILD_PORTABLE "Build portable version with Windows like behavior (see COMPILING.MD)" OFF "NOT WIN32" OFF)
# Git info options
cmake_dependent_option(RD_GIT_NO_HASH "For Devs only! Don't run 'revision_check' at all" OFF "GIT_FOUND" ON)
# Package related variables
set(PACKAGE_TARNAME "russian-doom")
set(PACKAGE_COPYRIGHT "Copyright \\xA9 2016-2023 Julian Nechaevsky. Copyright \\xA9 2020-2024 Leonid Murin (Dasperal). Licensed under GNU General Public License, version 2")
# Check target architecture
if(MSVC)
# Shortcut for MSVC since it has explicit option for architecture
if(CMAKE_GENERATOR_PLATFORM STREQUAL Win32)
set(ARCH x86)
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL x64)
set(ARCH x64)
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL ARM)
set(ARCH AArch32)
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL ARM64)
set(ARCH AArch64)
endif()
endif()
if(NOT ARCH)
# Get target architecture from the compiler
include(TargetArch)
target_architecture(ARCH)
# Normalize
if(ARCH STREQUAL i386)
set(ARCH x86)
elseif(ARCH STREQUAL x86_64
OR ARCH STREQUAL ia64)
set(ARCH x64)
elseif(ARCH STREQUAL arm)
set(ARCH AArch32)
elseif(ARCH STREQUAL arm64)
set(ARCH AArch64)
elseif(ARCH STREQUAL unknown)
unset(ARCH)
endif()
endif()
# Enable by default for MinGW (MSYS) environments
# Disabled for vcpkg, because it copies and installs DLLs for dependencies by itself
cmake_dependent_option(RD_USE_SELECTED_DLL_SET
"Use 'Selected DLL set' instead of DLLs provided by build environment" "${MINGW}" "NOT VCPKG_TOOLCHAIN" OFF
)
# Any settings that should apply to all targets in this directory and all subdirectories should go here
set(RD_C_STANDARD 99)
# Enable LTO if available.
include(CheckIPOSupported)
check_ipo_supported(RESULT HAVE_LTO)
cmake_dependent_option(RD_ENABLE_LTO "Use link-time optimisation" ON "HAVE_LTO" OFF)
#MSYS MINGW32 to UCRT32 hack
cmake_dependent_option(RD_UCRT32 "Use MSYS MINGW32 to UCRT32 hack" ON "WIN32;ARCH STREQUAL x86;MINGW;CMAKE_C_COMPILER_ID STREQUAL GNU" OFF)
include(Utils)
# Parameters we want to check for on all compilers
#
# Note that we want to check for these, even on MSVC, because some compilers
# that pretend to be MSVC can take both GCC and MSVC-style parameters at the
# same time, like clang-cl.exe
add_compile_options_checked(
# Extra errors
-Werror=implicit-function-declaration
-Werror=incompatible-pointer-types
-Werror=int-conversion
# Extra warnings
-Wformat=2
-Wredundant-decls
-Wrestrict
# Disable warnings
-Wno-unknown-pragmas
-Wno-unused-result
-Wno-format-nonliteral
-Wno-discarded-qualifiers
-Wno-incompatible-pointer-types-discards-qualifiers
)
if(MSVC)
add_common_compile_definitions(
# Silence the usual warnings for POSIX and standard C functions
_CRT_NONSTDC_NO_DEPRECATE
_CRT_SECURE_NO_WARNINGS
_CRT_SECURE_NO_DEPRECATE
)
add_compile_options_checked(
# Default warning setting for MSVC
/W3
# Extra errors for cl.exe
/we4013 # Implicit function declaration
/we4133 # Incompatible types
/we4477 # Format string mismatch
# Disable warnings for cl.exe
/wd4244 # Disable "possible loss of data" warning
/wd4068 # Disable "unknown pragma" warning
# Disable warnings for clang-cl.exe - prevents warning spam in SDL headers
-Wno-pragma-pack
)
string(REPLACE "/O3" "/O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/O3" "/O2" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
else()
if(RD_UCRT32)
add_compile_definitions(
# Fixes utf-8 text in console
_UCRT
)
endif()
# We only want -Wall on GCC compilers, since /Wall on MSVC is noisy
add_compile_options_checked(-Wall)
string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
endif()
Option(CMAKE_FIND_PACKAGE_PREFER_CONFIG "Prefer dependency search in config mode over find module mode" OFF)
if(VCPKG_TOOLCHAIN)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
endif()
find_package(SDL2 2.0.18 REQUIRED)
find_package(SDL2_mixer 2.0.2 REQUIRED)
find_package(SDL2_net 2.0.0 REQUIRED)
find_package(SampleRate)
find_package(miniz 2.0.0)
find_package(m)
# Use system of user-provided library if it exists
if(NOT miniz_FOUND)
message(STATUS "Using vendored miniz library")
add_subdirectory("lib/thirdparty/miniz")
endif()
# Construct path where to search
if(WIN32 AND (Python3_Interpreter_FOUND OR CMAKE_VERSION VERSION_GREATER_EQUAL 3.16)
AND NOT VCPKG_TOOLCHAIN
AND NOT RD_USE_SELECTED_DLL_SET)
applocal_search_path(APPLOCAL_SEARCH_PATH TARGETS "SDL2::SDL2" "SDL2_mixer::SDL2_mixer" "SDL2_net::SDL2_net" "SampleRate::samplerate" "miniz::miniz")
endif()
include(CheckSymbolExists)
include(CheckIncludeFile)
check_symbol_exists(strcasecmp "strings.h" HAVE_DECL_STRCASECMP)
check_symbol_exists(strncasecmp "strings.h" HAVE_DECL_STRNCASECMP)
check_symbol_exists(sscanf_s "stdio.h" HAVE_DECL_SSCANF_S)
check_symbol_exists(ioperm "sys/io.h" HAVE_IOPERM)
check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP)
check_symbol_exists(i386_iopl "i386/pio.h" HAVE_LIBI386)
check_symbol_exists(amd64_iopl "amd64/pio.h" HAVE_LIBAMD64)
check_include_file("dirent.h" HAVE_DIRENT_H)
check_include_file("dev/isa/spkrio.h" HAVE_DEV_ISA_SPKRIO_H)
check_include_file("dev/speaker/speaker.h" HAVE_DEV_SPEAKER_SPEAKER_H)
check_include_file("linux/kd.h" HAVE_LINUX_KD_H)
string(REPLACE " Doom" "" PACKAGE_PREFIX "${PROJECT_NAME}")
string(REPLACE "doom" "" PROGRAM_PREFIX "${PACKAGE_TARNAME}")
string(REPLACE "." ", " WINDOWS_RC_VERSION ${PROJECT_VERSION})
if(RD_COMPILE_DOOM)
configure_file(src/doom/resource.rc.in src/doom/resource.rc @ONLY)
list(APPEND COMPILE_MODULES "doom")
endif()
if(RD_COMPILE_HERETIC)
configure_file(src/heretic/resource.rc.in src/heretic/resource.rc @ONLY)
list(APPEND COMPILE_MODULES "heretic")
endif()
if(RD_COMPILE_HEXEN)
configure_file(src/hexen/resource.rc.in src/hexen/resource.rc @ONLY)
list(APPEND COMPILE_MODULES "hexen")
endif()
enable_testing()
# Update git_info.h
if(RD_GIT_NO_HASH)
# Use a function to avoid accidentally messing the real variables
configure_empty_git_info("cmake/git_info.h.in" "git_info.h")
else()
add_custom_target(revision_check
COMMAND "${CMAKE_COMMAND}" -P "\"${PROJECT_SOURCE_DIR}/cmake/UpdateRevision.cmake\"" "${GIT_EXECUTABLE}" "\"git_info.h\""
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
endif()
include(GNUInstallDirs)
foreach(SUBDIR lib data src)
add_subdirectory("${SUBDIR}")
endforeach()
# CPack
if(WIN32)
set(CPACK_PACKAGE_NAME ${PACKAGE_TARNAME})
set(CPACK_SYSTEM_NAME "windows-${ARCH}")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_CHECKSUM SHA256)
set(CPACK_GENERATOR ZIP)
# Archive Generator
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_ARCHIVE_COMPONENT_INSTALL OFF)
set(CPACK_ARCHIVE_THREADS 0) # For Cmake 3.18+
include(CPack)
endif()