-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
334 lines (285 loc) · 14.1 KB
/
CMakeLists.txt
File metadata and controls
334 lines (285 loc) · 14.1 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.3...3.10 FATAL_ERROR)
# Don't hardcode /W3 in default MSVC settings -- we'll add it ourselves if we want it
if(NOT CMAKE_VERSION VERSION_LESS 3.15)
if(POLICY CMP0092)
cmake_policy(SET CMP0092 NEW)
endif()
endif()
# Don't hardcode /GR in default MSVC settings -- this RTTI flag already defaults to ON
# TODO: check if this is true when using clang-cl.exe?
if(NOT CMAKE_VERSION VERSION_LESS 3.20)
if(POLICY CMP0117)
cmake_policy(SET CMP0117 NEW)
endif()
endif()
# Prefer all source files to have their extensions explicitly listed
if(NOT CMAKE_VERSION VERSION_LESS 3.20)
if(POLICY CMP0115)
cmake_policy(SET CMP0115 NEW)
endif()
endif()
# LTO support through CheckIPOSupported -- requires CMake 3.9+
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif()
endif()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No explicit CMAKE_BUILD_TYPE selected, default to RelWithDebInfo")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type: Debug, Release, MinSizeRel, RelWithDebInfo (default)" FORCE)
endif()
option(SCUMMTR_COMPILER_IS_DJGPP "Compiler is DJGPP" OFF)
if(SCUMMTR_COMPILER_IS_DJGPP)
set(CMAKE_SYSTEM_NAME "Generic")
endif()
set(_ENABLE_LTO_DEFAULT OFF)
# XXX: Turn on the following, once LTO's been tested a bit more
#[[if(NOT DEFINED ENABLE_LTO)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
# Exclude DJGPP because of: https://gitlab.kitware.com/cmake/cmake/-/issues/21696
if(NOT SCUMMTR_COMPILER_IS_DJGPP)
set(_ENABLE_LTO_DEFAULT ON)
endif()
else()
set(_ENABLE_LTO_DEFAULT OFF)
endif()
endif()]]
option(ENABLE_LTO "Enable Link Time Optimization (platform must support it)" ${_ENABLE_LTO_DEFAULT})
project("scummtr" CXX)
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
if(SCUMMTR_COMPILER_IS_DJGPP)
set(CMAKE_CXX_EXTENSIONS ON) # for mkdir()
set(CMAKE_EXECUTABLE_SUFFIX ".exe")
endif()
string(TIMESTAMP SCUMMTR_BUILD_DATE "%Y%m%d-WIP%H%M" UTC)
include(CheckCXXCompilerFlag)
# TODO: look at CMP0138 for LTO
if(ENABLE_LTO)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(FATAL_ERROR "LTO support with CMAKE_BUILD_TYPE set to \"Debug\" makes no sense: disable it, or use RelWithDebInfo")
elseif(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
message(WARNING "LTO support was asked, but using without CMAKE_BUILD_TYPE set to \"Release\" is not optimal")
endif()
if(CMAKE_VERSION VERSION_LESS 3.9)
message(WARNING "LTO support: not available (CMake 3.9 or later is required)")
else()
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT LTO_CHECK_OUTPUT)
if(LTO_SUPPORTED)
message(STATUS "LTO support: enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "LTO support: not available (CMake was unable to set it up on your system)")
endif()
endif()
else()
#message(STATUS "LTO support: disabled (set ENABLE_LTO or Release mode if you want it)")
message(STATUS "LTO support: disabled (set ENABLE_LTO to enable it)")
endif()
if(MSVC)
if(MSVC_VERSION LESS 1900)
message(FATAL_ERROR "Refusing to build: Visual Studio 2015 or better is required")
endif()
# MSVC 2017 15.0+:
if(MSVC_VERSION GREATER 1909)
# Disable Microsoft-specific C++ language extensions
add_compile_options(/permissive-)
else()
add_compile_options(-Zc:strictStrings)
endif()
# MSVC 2017 15.7+:
if(MSVC_VERSION GREATER 1913)
# Tell MSVC not to lie about its `__cplusplus` value. (Note that some releases
# of Visual Studio 2017 and earlier don't have this flag. So, current code
# still needs specific MSVC cases when it checks the value of `__cplusplus`.)
add_compile_options(/Zc:__cplusplus)
endif()
# Quoting MSVC docs: without this, "thrown exceptions can result in undestroyed
# objects and resource leaks". CMake will often set it by default, but not in all
# configurations (e.g. clang-cl), and they may change this at some point (see:
# <https://gitlab.kitware.com/cmake/cmake/-/work_items/20610>)
add_compile_options(/EHsc)
# MSVC 2019 16.0+:
if(MSVC_VERSION GREATER 1919)
# Print better diagnosis, like modern GCC/Clang do (XXX: it may have been added
# in some MSVC 2017 update, but good luck finding which one)
add_compile_options(/diagnostics:caret)
endif()
# MSVC 2022 17.0+:
if(MSVC_VERSION GREATER 1930)
# Treat unrecognized compiler options as errors
add_compile_options(/options:strict)
endif()
# Looks like CMake doesn't set up all the proper LTO flags for MSVC (e.g. "Not all
# modules are compiled with -Gy")
# https://discourse.cmake.org/t/cmake-ipo-issue-msvc-ltcg-incremental/826/2
# https://gitlab.kitware.com/cmake/cmake/-/issues/20484
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
add_compile_options(/GL /Gy)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG")
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Report when an uninitialized variable is used -- implies /Od
add_compile_options(/RTC1)
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
# Enhanced debugging information for optimized code
add_compile_options(/Zo)
endif()
add_definitions(/DSCUMMTR_BUILD_DATE=\"${SCUMMTR_BUILD_DATE}\")
add_definitions(/D_CRT_SECURE_NO_WARNINGS /DWIN32_LEAN_AND_MEAN)
# Note: see CMP0092 policy use above, regarding this check
if(NOT CMAKE_VERSION VERSION_LESS 3.15)
add_compile_options(/W3)
endif()
# Some /W4 flags we bring to /W3:
#
# /w34295 (no GCC equivalent?): array is too small to include a terminating null character
# /w34100 (like -Wunused-parameter): unreferenced formal parameter
# /w34189 (like -Wunused-variable): local variable is initialized but not referenced
#
# TODO: anything else?
add_compile_options(/w34295 /w34100 /w34189)
# Too much noise for now:
#
# /w34263: member function does not override any base class virtual member function
# /w34264: no override available for virtual member function
#add_compile_options(/w34263 /w34264)
# Some warnings we don't want:
#
# /wd4244 (like -Wno-conversion): conversion from 'type1' to 'type2', possible loss of data
# /wd4068 (like -Wno-unknown-pragmas): ignore unknown `#pragma` directives
add_compile_options(/wd4244 /wd4068)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
# Enable Security Development Lifecycle checks, which "change security-relevant
# warnings into errors, and set additional secure code-generation features"
add_compile_options(/sdl)
# but don't error on deprecated function use yet
add_compile_options(/wd4995 /wd4996)
endif()
else()
#
# Here, we assume the compiler is GCC-compatible.
#
add_definitions(-DSCUMMTR_BUILD_DATE=\"${SCUMMTR_BUILD_DATE}\")
if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN)
endif()
# GCC 2.95 compatible warnings we always want
add_compile_options(-Wall -pedantic -Wpointer-arith -Wcast-qual -Wcast-align -Wundef -Wmultichar -Wwrite-strings -Wredundant-decls -Wunused -Wsign-compare -Wformat)
# GCC 2.95 compatible warnings we don't want, for very good reasons
add_compile_options(-Wno-unknown-pragmas)
# GCC 2.95 compatible warnings we don't want to fix... yet
add_compile_options(-Wno-conversion -Wno-overloaded-virtual -Wno-old-style-cast)
# GCC 2.95 compatible warnings we don't want to fix but REALLY SHOULD
# TODO: it looks like this one now doesn't find anything anymore?
add_compile_options(-Wno-non-virtual-dtor)
# Flags which are compiler-specific, or only meaningful with a particular compiler
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fcheck-new)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Widiomatic-parentheses -Wparentheses -Wimplicit-int-conversion)
# TODO: fix this, instead of silencing
add_compile_options(-Wno-shorten-64-to-32)
else()
message(WARNING "Assuming that your ${CMAKE_CXX_COMPILER_ID} compiler is GCC-compatible, but this may fail")
endif()
# -O3 has no benefit for us, and it's sometimes buggy
set(default_fallback_opt_flag "-O2")
foreach(cfg Release RelWithDebInfo MinSizeRel Debug)
string(TOUPPER "${cfg}" UCFG)
string(REPLACE "-O3" "${default_fallback_opt_flag}" "CMAKE_CXX_FLAGS_${UCFG}" "${CMAKE_CXX_FLAGS_${UCFG}}")
endforeach()
# On the other hand, some systems have no -O option in their release flags at all
foreach(cfg Release RelWithDebInfo MinSizeRel)
string(TOUPPER "${cfg}" UCFG)
string(REGEX MATCH "-O([0-4]|g|s|z|fast)?" has_opt_flag "${CMAKE_CXX_FLAGS_${UCFG}}")
if(NOT has_opt_flag)
if(cfg STREQUAL "MinSizeRel")
set(default_fallback_opt_flag "-Os")
endif()
message(STATUS "No optimization flag found in default ${cfg} flags; adding ${default_fallback_opt_flag} to them")
set(CMAKE_CXX_FLAGS_${UCFG} "${CMAKE_CXX_FLAGS_${UCFG}} ${default_fallback_opt_flag}" CACHE STRING "Flags used by the compiler during ${cfg} builds." FORCE)
endif()
endforeach()
# Warnings requiring a recent compiler. Do a single test, it's not critical
set(SCUMMTR_MODERN_WARNING_FLAGS "-Wformat=2;-Winit-self;-Wtype-limits;-Wignored-qualifiers") # -Wzero-as-null-pointer-constant for C++11
check_cxx_compiler_flag("${SCUMMTR_MODERN_WARNING_FLAGS}" COMPILER_SUPPORTS_MODERN_WARNING_FLAGS)
if(COMPILER_SUPPORTS_MODERN_WARNING_FLAGS)
# Also add some old flags which only became reliable in more recent versions
add_compile_options("${SCUMMTR_MODERN_WARNING_FLAGS};-Wshadow;-Wuninitialized;-Wctor-dtor-privacy")
# Clang-only, as GCC is said to be too noisy for this
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options("${SCUMMTR_MODERN_WARNING_FLAGS};-Woverloaded-virtual")
endif()
endif()
if(MINGW)
add_definitions(-D__USE_MINGW_ANSI_STDIO)
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD")
# OpenBSD just does its hardening all by itself. However, we need -Wno-system-headers, there
add_compile_options(-Wno-system-headers)
elseif(NOT SCUMMTR_COMPILER_IS_DJGPP)
add_definitions(-D_GLIBCXX_ASSERTIONS)
# Glibc's include/features.h complains if _FORTIFY_SOURCE is used with
# GCC < 4.1, or without optimizations
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0))
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
# Note: not using add_definitions() here is on purpose. Systems like
# Ubuntu need the -U flag before the -D one, but add_definitions() is
# too clever, and ends up switching them on some setups... which would
# disable the feature.
add_compile_options(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2)
endif()
endif()
set(SCUMMTR_HARDENING_FLAGS "-fstack-protector;--param=ssp-buffer-size=4")
check_cxx_compiler_flag("${SCUMMTR_HARDENING_FLAGS}" COMPILER_SUPPORTS_HARDENING_FLAGS)
if(COMPILER_SUPPORTS_HARDENING_FLAGS)
add_compile_options("${SCUMMTR_HARDENING_FLAGS}")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0))
set(SCUMMTR_HARDENING_FLAGS_STACKCLASH_PROT "-fstack-clash-protection")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag("${SCUMMTR_HARDENING_FLAGS_STACKCLASH_PROT} -Werror=unused-command-line-argument" COMPILER_SUPPORTS_HARDENING_FLAGS_STACKCLASH_PROT)
else()
check_cxx_compiler_flag("${SCUMMTR_HARDENING_FLAGS_STACKCLASH_PROT}" COMPILER_SUPPORTS_HARDENING_FLAGS_STACKCLASH_PROT)
endif()
if(COMPILER_SUPPORTS_HARDENING_FLAGS_STACKCLASH_PROT)
add_compile_options("${SCUMMTR_HARDENING_FLAGS_STACKCLASH_PROT}")
endif()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_compile_options(-fPIE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
endif()
endif()
endif()
endif()
if(NOT UNIX)
set(CMAKE_INSTALL_BINDIR ".")
set(CMAKE_INSTALL_DATADIR ".")
endif()
include(GNUInstallDirs)
include_directories("src")
add_subdirectory("src/common")
add_subdirectory("src/FontXY")
add_subdirectory("src/ScummFont")
add_subdirectory("src/ScummRp")
add_subdirectory("src/ScummTr")
if(UNIX)
install(FILES man/FontXY.1 man/scummfont.1 man/scummrp.1 man/scummtr.1 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
install(FILES COPYING NEWS.md DESTINATION "${CMAKE_INSTALL_DOCDIR}")
else()
# When not on Unix-like systems, prefer CRLF line-endings for better compatibility
file(GLOB MAN_TXT_FILES_LIST "man/txt/*.txt")
foreach(txt_file ${MAN_TXT_FILES_LIST})
get_filename_component(filename_only "${txt_file}" NAME)
configure_file("${txt_file}" "${CMAKE_CURRENT_BINARY_DIR}/crlf/manuals/${filename_only}" @ONLY NEWLINE_STYLE DOS)
endforeach()
configure_file("COPYING" "${CMAKE_CURRENT_BINARY_DIR}/crlf/COPYING.txt" @ONLY NEWLINE_STYLE DOS)
configure_file("NEWS.md" "${CMAKE_CURRENT_BINARY_DIR}/crlf/NEWS.txt" @ONLY NEWLINE_STYLE DOS)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/crlf/" DESTINATION "${CMAKE_INSTALL_DATADIR}" FILES_MATCHING PATTERN "*.txt")
endif()