forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
313 lines (273 loc) · 13.1 KB
/
Copy pathCMakeLists.txt
File metadata and controls
313 lines (273 loc) · 13.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
cmake_minimum_required ( VERSION 3.5 )
project ( OpenXcom )
set ( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" )
include(BuildType)
include(GNUInstallDirs)
# For yaml-cpp
set (CMAKE_CXX_STANDARD 11)
# use std=c++11 rather than std=gnu++11
set (CMAKE_CXX_EXTENSIONS OFF)
option ( DEV_BUILD "Development Build. Disable this for release builds" ON )
option ( BUILD_PACKAGE "Prepares build for creation of a package with CPack" ON )
option ( ENABLE_WARNING "Always show warnings (even for release builds)" OFF )
option ( FATAL_WARNING "Treat warnings as errors" OFF )
option ( ENABLE_CLANG_ANALYSIS "When building with clang, enable the static analyzer" OFF )
option ( CHECK_CCACHE "Check if ccache is installed and use it" OFF )
set ( MSVC_WARNING_LEVEL 3 CACHE STRING "Visual Studio warning levels" )
option ( FORCE_INSTALL_DATA_TO_BIN "Force installation of data to binary directory" OFF )
set ( DATADIR "" CACHE STRING "Where to search for datafiles" )
set ( OPENXCOM_VERSION_STRING "" CACHE STRING "Version string (after x.x)" )
if ( CHECK_CCACHE )
find_program( CCACHE_PROGRAM ccache )
if( NOT CCACHE_PROGRAM )
message ( "CCACHE requested but not found on the system." )
else ()
set_property( GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}" )
set_property( GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_PROGRAM}" )
message ( "found CCACHE (${CCACHE_PROGRAM})" )
endif()
endif ()
if ( WIN32 )
set ( default_deps_dir "${CMAKE_SOURCE_DIR}/deps" )
endif ()
if ( APPLE )
# SDL2 handles its own entry point; the SDL 1.2 SDLMain.m is not needed.
# set ( MACOS_SDLMAIN_M_PATH "${CMAKE_SOURCE_DIR}/src/apple/SDLMain.m" CACHE STRING "Path to SDLMain.m file" )
option ( CREATE_BUNDLE "Create a Mac OS application bundle" ON )
endif ()
set ( DEPS_DIR "${default_deps_dir}" CACHE STRING "Dependencies directory" )
# Add check for library (SDL_gfx, yaml-cpp )
if ( EMSCRIPTEN )
# Emscripten provides SDL2 and friends via its ports system.
# Compile and link flags are set together so headers and libs are found automatically.
set ( EMSCRIPTEN_SDL_FLAGS "-sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sUSE_SDL_MIXER=2 -sUSE_SDL_GFX=2" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EMSCRIPTEN_SDL_FLAGS}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EMSCRIPTEN_SDL_FLAGS}" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EMSCRIPTEN_SDL_FLAGS}" )
# SDL library variables: empty because Emscripten links them via flags
set ( SDL_LIBRARY "" )
set ( SDLMIXER_LIBRARY "" )
set ( SDLGFX_LIBRARY "" )
set ( SDLIMAGE_LIBRARY "" )
message ( STATUS "Emscripten: using SDL2 ports (SDL2, SDL2_image, SDL2_mixer, SDL2_gfx)" )
# yaml-cpp: not available as an Emscripten port, build from source via FetchContent
include ( FetchContent )
FetchContent_Declare (
yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG 0.8.0
GIT_SHALLOW ON
SYSTEM
)
# yaml-cpp 0.8.0's cmake_minimum_required is too old for modern CMake
set ( CMAKE_POLICY_VERSION_MINIMUM 3.5 )
set ( YAML_CPP_BUILD_TESTS OFF CACHE BOOL "" FORCE )
set ( YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "" FORCE )
set ( YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "" FORCE )
FetchContent_MakeAvailable ( yaml-cpp )
set ( YAMLCPP_LIBRARY yaml-cpp::yaml-cpp )
set ( YAMLCPP_LIBRARY_DEBUG yaml-cpp::yaml-cpp )
set ( YAMLCPP_INCLUDE_DIR "${yaml-cpp_SOURCE_DIR}/include" )
include_directories ( SYSTEM ${YAMLCPP_INCLUDE_DIR} )
message ( STATUS "Emscripten: building yaml-cpp from source (0.8.0)" )
# Enable C++ exceptions (OpenXcom uses try/catch extensively)
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fexceptions" )
# Preload OpenXcom's own data (common/ + standard/) into a system path.
# /usr/share/openxcom/ is one of the global search paths in findDataFolders().
# The user data path (/home/web_user/.local/share/openxcom/) is kept free
# for IDBFS-backed persistent storage (uploaded UFO data + saves).
set ( WASM_SYSDATA "/usr/share/openxcom" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ${CMAKE_SOURCE_DIR}/bin/common@${WASM_SYSDATA}/common" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ${CMAKE_SOURCE_DIR}/bin/standard@${WASM_SYSDATA}/standard" )
# Optional: preload proprietary UFO game data (for development/testing).
# Production builds should NOT set this — the upload UI handles it.
set ( UFO_DATA_DIR "" CACHE PATH "Path to UFO game data directory for WASM preloading" )
if ( NOT "${UFO_DATA_DIR}" STREQUAL "" )
message ( STATUS "Emscripten: preloading UFO data from ${UFO_DATA_DIR}" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ${UFO_DATA_DIR}@${WASM_SYSDATA}/UFO" )
endif ()
# Allocate 256 MB upfront. This is generous for a 1994 DOS game and avoids
# runtime memory growth, which detaches typed array views and crashes the
# ScriptProcessorNode audio callback (index out of bounds in onaudioprocess).
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sINITIAL_MEMORY=268435456" )
# Link IDBFS for persistent browser storage (game data uploads + saves)
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lidbfs.js" )
# Allow JS to delay main() until data is ready (noInitialRun + callMain)
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sINVOKE_RUN=0" )
# ASYNCIFY: allow the blocking C/C++ main loop to yield to the browser
# event loop so that SDL_Delay, rendering, and input processing all work.
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sASYNCIFY" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sASYNCIFY_STACK_SIZE=65536" )
# Export mouse-input bridge functions so JS can call them
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sEXPORTED_FUNCTIONS=_main,_pushMouseMove,_pushMouseButton,_pushMouseWheel" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sEXPORTED_RUNTIME_METHODS=ccall,callMain,FS" )
elseif ( IS_DIRECTORY ${DEPS_DIR}/include )
include_directories ( SYSTEM ${DEPS_DIR}/include/SDL ${DEPS_DIR}/include/yaml-cpp ${DEPS_DIR}/include )
if ( CMAKE_CL_64 )
link_directories ( ${DEPS_DIR}/lib/x64 )
else ( )
link_directories ( ${DEPS_DIR}/lib/Win32 )
endif()
set( SDL_LIBRARY SDL )
set ( SDLGFX_LIBRARY SDL_gfx )
set ( SDLMIXER_LIBRARY SDL_mixer )
set ( SDLIMAGE_LIBRARY SDL_image )
set ( YAMLCPP_LIBRARY yaml-cpp )
set ( YAMLCPP_LIBRARY_DEBUG yaml-cppd )
add_definitions( -DYAML_CPP_DLL )
else ( )
find_package ( SDL2 COMPONENTS mixer gfx image)
find_package ( Yaml_cpp 0.5.3)
set ( YAMLCPP_LIBRARY_DEBUG ${YAMLCPP_LIBRARY} )
if ( NOT SDL_FOUND )
message ( FATAL_ERROR "Can't find SDL which is required" )
else ()
include_directories ( SYSTEM ${SDL_INCLUDE_DIR} )
message ( "found SDL ${SDL_MAJOR}.${SDL_MINOR}.${SDL_MICRO} (${SDL_LIBRARY_DIRS}:${SDL_INCLUDE_DIR})" )
endif ()
if ( NOT SDLMIXER_FOUND )
message ( FATAL_ERROR "Can't find SDL_mixer which is required" )
else ()
include_directories ( SYSTEM ${SDLMIXER_INCLUDE_DIR} )
message ( "found SDL_mixer ${SDL_MIXER_MAJOR}.${SDL_MIXER_MINOR}.${SDL_MIXER_MICRO} (${SDL_MIXER_LIBRARY_DIRS}:${SDLMIXER_INCLUDE_DIR})" )
endif ()
if ( NOT SDLGFX_FOUND )
message ( FATAL_ERROR "Can't find SDL_gfx which is required" )
else ()
include_directories ( SYSTEM ${SDLGFX_INCLUDE_DIR} )
message ( "found SDL_gfx ${SDL_GFX_MAJOR}.${SDL_GFX_MINOR}.${SDL_GFX_MICRO} (${SDL_GFX_LIBRARY_DIRS}:${SDLGFX_INCLUDE_DIR})" )
endif ()
if ( NOT SDLIMAGE_FOUND )
message ( FATAL_ERROR "Can't find SDL_image which is required" )
else ()
include_directories ( SYSTEM ${SDLIMAGE_INCLUDE_DIR} )
message ( "found SDL_image ${SDL_IMAGE_MAJOR}.${SDL_IMAGE_MINOR}.${SDL_IMAGE_MICRO} (${SDL_IMAGE_LIBRARY_DIRS}:${SDLIMAGE_INCLUDE_DIR})" )
endif ()
if ( NOT YAMLCPP_FOUND )
message ( FATAL_ERROR "Can't find yaml-cpp which is required" )
else ()
include_directories ( SYSTEM ${YAMLCPP_INCLUDE_DIR} )
message ( "found yaml-cpp(${YAMLCPP_LIBRARY_DIRS}:${YAMLCPP_INCLUDE_DIR})" )
endif ( NOT YAMLCPP_FOUND )
endif()
# Find OpenGL
if ( NOT EMSCRIPTEN )
set (OpenGL_GL_PREFERENCE LEGACY)
find_package ( OpenGL )
if ( NOT OPENGL_FOUND )
message ( WARNING "Can't find OpenGL; how does that even happen?\n"
"Continuing building without OpenGL support."
)
add_definitions(-D__NO_OPENGL)
else ()
# On macOS with SDL2, the shader-based OpenGL code needs GL3 functions
# which aren't exposed through SDL_opengl.h's legacy path.
# Disable OpenGL for now; software rendering works fine.
if ( APPLE )
message ( STATUS "macOS + SDL2: disabling OpenGL shaders (software rendering)" )
add_definitions(-D__NO_OPENGL)
else ()
include_directories ( SYSTEM ${OPENGL_INCLUDE_DIR} )
message ( "found openGL (${OPENGL_LIBRARIES})" )
endif ()
endif ()
else ()
add_definitions(-D__NO_OPENGL)
endif ()
# Resolve backtraces
if ( WIN32 )
link_libraries( dbghelp )
endif ()
if ( UNIX )
link_libraries( ${CMAKE_DL_LIBS} )
endif ()
# Read version number
set ( file "${CMAKE_SOURCE_DIR}/src/version.h" )
file ( READ ${file} lines )
string ( REGEX MATCH "[.]*OPENXCOM_VERSION_SHORT \"([0-9]).([0-9])" version_line "${lines}" )
set ( CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1} )
set ( CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2} )
set ( CPACK_PACKAGE_VERSION_PATCH "" )
if ( "${OPENXCOM_VERSION_STRING}" STREQUAL "" )
find_package ( Git )
if ( GIT_FOUND )
message("git found: ${GIT_EXECUTABLE}")
execute_process ( COMMAND ${GIT_EXECUTABLE} describe --dirty
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE git_describe_out
ERROR_VARIABLE git_describe_error
RESULT_VARIABLE git_describe_result
)
string ( REGEX MATCH "([a-z|0-9|.]*)-([0-9]*)-g([a-z|0-9]*)([-|a-z]*)" git_commit "${git_describe_out}" )
set ( git_tag ${CMAKE_MATCH_1} )
set ( git_nb_commit ${CMAKE_MATCH_2} )
set ( git_commit ${CMAKE_MATCH_3} )
set ( git_dirty ${CMAKE_MATCH_4} )
set ( OPENXCOM_VERSION_STRING ".${git_commit}${git_dirty}" )
endif()
endif()
add_definitions( -DGIT_BUILD=1 )
configure_file("${CMAKE_SOURCE_DIR}/src/git_version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/git_version.h" )
include_directories ( "${CMAKE_CURRENT_BINARY_DIR}" )
if ( DEV_BUILD )
# Append the commit to version number
set ( CPACK_PACKAGE_VERSION_PATCH "${git_commit}${git_dirty}" )
set ( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" )
else ()
set ( CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_NSIS_PACKAGE_NAME}" )
set ( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}" )
endif ()
if ( BUILD_PACKAGE )
if ( NOT DEV_BUILD )
string ( LENGTH "${git_dirty}" is_dirty )
if ( ${is_dirty} GREATER 0 )
message ( FATAL_ERROR "Release package must be built from a clean tree" )
endif ()
if ( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
message ( FATAL_ERROR "Release package can't be built from a debug build" )
endif ()
endif ( )
if ( NOT CPACK_GENERATOR )
set ( CPACK_GENERATOR "TXZ" )
endif ()
if ( NOT CPACK_SOURCE_GENERATOR )
set ( CPACK_SOURCE_GENERATOR "TXZ" )
endif ()
set ( CPACK_PACKAGE_VENDOR "The OpenXcom project" )
set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Open-source clone of UFO: Enemy Unknown" )
set ( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/cmake/modules/Description.txt" )
set ( CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md" )
if ( NOT APPLE )
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt" )
endif ()
set ( CPACK_PACKAGE_CONTACT "The OpenXcom project (http://www.openxcom.org)" )
include ( LinuxDEB )
include ( LinuxRPM )
include ( nsis )
include ( apple )
include ( CPack )
message ( "version:${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}"
)
endif()
# Emscripten/WASM: add link flags and skip packaging
if ( EMSCRIPTEN )
# Keep growth enabled as a safety net (some Emscripten/SDL internals assume
# it). With 256 MB initial memory, growth should never actually trigger,
# which avoids the typed-array-detach audio crash.
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sALLOW_MEMORY_GROWTH=1" )
set ( BUILD_PACKAGE OFF CACHE BOOL "WASM build" FORCE )
message ( STATUS "Emscripten build: WASM link flags added" )
endif ()
if ( NOT WIN32 AND NOT EMSCRIPTEN )
install(FILES "${CMAKE_SOURCE_DIR}/res/linux/openxcom.desktop"
DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/applications")
install(FILES "${CMAKE_SOURCE_DIR}/res/linux/icons/openxcom_48x48.png"
DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/48x48/apps" RENAME openxcom.png)
install(FILES "${CMAKE_SOURCE_DIR}/res/linux/icons/openxcom_128x128.png"
DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/128x128/apps" RENAME openxcom.png)
install(FILES "${CMAKE_SOURCE_DIR}/res/linux/icons/openxcom.svg"
DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/scalable/apps")
endif ()
add_subdirectory ( docs )
add_subdirectory ( src )