forked from ja2-stracciatella/ja2-stracciatella
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
549 lines (478 loc) · 19.2 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# \file CMakeLists.txt
cmake_minimum_required (VERSION 3.18.1)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
## Some macros
macro(add_custom_templated_target NAME)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/target-${NAME}.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/target-${NAME}.cmake"
IMMEDIATE @ONLY)
add_custom_target(${NAME}
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake/target-${NAME}.cmake)
endmacro()
## Project Setup
# compiler caching
find_program(SCCACHE_PROGRAM "sccache")
set(USE_SCCACHE ON CACHE BOOL "Set to OFF to not cache compiler outputs")
if(SCCACHE_PROGRAM AND USE_SCCACHE)
message(STATUS "Using sccache found at ${SCCACHE_PROGRAM} for caching build results")
set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}" CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}" CACHE STRING "" FORCE)
endif()
project(ja2-stracciatella)
set(JA2_BINARY "ja2")
set(LAUNCHER_BINARY "ja2-launcher")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## Semantic Versioning
# @see https://semver.org/
#
# The version must be set to:
# * "0.<next minor>.0-dev" in the master branch
# * "0.<minor>.<patch>" in release tags
# * "0.<minor>.<next patch>-dev" in the "0.<minor>.x" branches
#
# TODO when releasing 1.0.0 we must decide what is a breaking change.
# The master branch version will be "<major>.<next minor>.0-dev" before a
# breaking change and "<next major>.0.0-dev" with a breaking change.
file(READ "version" BASE_SEMVER_VERSION)
# Trim leading and trailing whitespace / newlines
string(STRIP "${BASE_SEMVER_VERSION}" BASE_SEMVER_VERSION)
include(semver-functions)
semver_set(ja2-stracciatella_VERSION "${BASE_SEMVER_VERSION}-git")
if (VERSION_TAG)
semver_set_prerelease(ja2-stracciatella_VERSION_PRERELEASE "-${VERSION_TAG}")
endif()
find_package(Git)
if (GIT_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE failed
OUTPUT_VARIABLE hash
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT failed)
list(APPEND ja2-stracciatella_VERSION_BUILDMETADATA "${hash}")
endif()
endif()
semver_rebuild(ja2-stracciatella_VERSION)
message(STATUS "ja2-stracciatella version: ${ja2-stracciatella_VERSION}")
## Meta Information
set(CONTACT "JA2 Stracciatella Team <[email protected]>")
set(DESCRIPTION "An improved, cross-platform, stable Jagged Alliance 2 runtime.")
## Options
# Default CMAKE_BUILD_TYPE to RelWithDebInfo
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug RelWithDebInfo." FORCE)
endif()
set(VERSION_TAG "" CACHE STRING "Build date for nightly versioning")
set(EXTRA_DATA_DIR "" CACHE STRING "Directory for externalized data")
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(LOCAL_SDL_LIB "" CACHE STRING "Use local SDL library from this directory")
# @see CARGO_BUILD_TARGET in dependencies/lib-stracciatella/CMakeLists.txt
option(BUILD_SDL_LIB "Build SDL from source" OFF)
option(LOCAL_FLTK_LIB "Build with fltk lib" OFF)
option(LOCAL_GTEST_LIB "Build with local gtest lib" ON)
# @see LOCAL_STRING_THEORY_LIB in dependencies/lib-string_theory/CMakeLists.txt
option(WITH_UNITTESTS "Build with unittests" ON)
option(WITH_FIXMES "Build with fixme messages" OFF)
option(WITH_MAEMO "Build with right click mapped to F4 (menu button)" OFF)
option(WITH_MAGICENUM "Build with magic_enum library" ON)
option(BUILD_LAUNCHER "Build the ja2 launcher application" ON)
option(WITH_EDITOR_SLF "Include the latest free editor.slf" OFF)
option(WITH_RUST_BINARIES "Include rust binaries in build" ON)
option(WITH_ASAN "Build with address sanitizer" OFF)
option(ENABLE_PCH "Use precompiled standard library headers during compilation" OFF)
# @see LOCAL_LUA_LIB in dependencies/lib-lua/CMakeLists.txt
# @see LOCAL_SOL_LIB in dependencies/lib-sol2/CMakeLists.txt
# @see LOCAL_MINIAUDIO_LIB in dependencies/lib-miniaudio/CMakeLists.txt
set(WITH_CUSTOM_LOCALE "" CACHE STRING "Set a custom locale at the start, leave empty to disable")
if(MSVC)
foreach(_var
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO
)
# force /Z7 instead of /ZI to include debug information in obj file
string(REGEX REPLACE "/Zi|/ZI" "/Z7" _value "${_value}")
if(NOT ${_var} STREQUAL _value)
set_property(CACHE "${_var}" PROPERTY VALUE "${_value}")
endif()
endforeach()
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "ja2")
endif()
## Build
# The main target
if(ANDROID)
add_library(${JA2_BINARY} SHARED)
else()
add_executable(${JA2_BINARY})
endif()
if(MSVC)
# set the source and execution charset
add_compile_options("/utf-8")
# suppress the min and max macro definitions
target_compile_definitions(ja2 PRIVATE NOMINMAX)
endif()
if(NOT "${WITH_CUSTOM_LOCALE}" STREQUAL "")
add_definitions("-DWITH_CUSTOM_LOCALE=\"${WITH_CUSTOM_LOCALE}\"")
endif()
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
set(GAME_VERSION "v${ja2-stracciatella_VERSION}")
message(STATUS "Setting directory for libraries to: ${INSTALL_LIB_DIR}")
add_definitions(-DINSTALL_LIB_DIR="${INSTALL_LIB_DIR}")
if (WITH_FIXMES)
message(STATUS "Building with fixme messages" )
target_compile_definitions(ja2 PRIVATE WITH_FIXMES)
endif()
if (WITH_MAEMO)
message(STATUS "Building with right click mapped to F4 (menu button)" )
target_compile_definitions(ja2 PRIVATE WITH_MAEMO)
endif()
if(BUILD_SDL_LIB)
set(SDL2_LIBRARY "")
set(SDL2_INCLUDE_DIR "")
add_subdirectory("dependencies/lib-sdl2")
else()
if (NOT (LOCAL_SDL_LIB STREQUAL ""))
message(STATUS "Using local SDL from " "${CMAKE_CURRENT_SOURCE_DIR}/${LOCAL_SDL_LIB}")
set(ENV{SDL2DIR} "${CMAKE_CURRENT_SOURCE_DIR}/${LOCAL_SDL_LIB}")
endif()
find_package(SDL2 REQUIRED)
endif()
message(STATUS "SDL2 Libraries: ${SDL2_LIBRARY}; SDL2 Include Dir: ${SDL2_INCLUDE_DIR}")
if (NOT WITH_MAGICENUM)
message(STATUS "Compiling without magic_enum. This build will not have enum-gen functionalities")
target_compile_definitions(ja2 PRIVATE NO_MAGICENUM_LIB)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR ENABLE_ASSERTS)
target_compile_definitions(ja2 PRIVATE ENABLE_ASSERTS)
endif()
if(BUILD_LAUNCHER)
if (NOT LOCAL_FLTK_LIB)
find_package(FLTK)
if(NOT FLTK_FOUND)
message(STATUS "FLTK not found. Disabling launcher.")
set(BUILD_LAUNCHER OFF)
endif()
else()
set(FLTK_LIBRARIES "")
set(FLTK_INCLUDE_DIR "")
add_subdirectory("dependencies/lib-fltk")
endif()
endif()
message(STATUS "Fltk Libraries: ${FLTK_LIBRARIES}")
set(JA2_INCLUDES "")
set(JA2_SOURCES "")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/externalized")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/game")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/sgp")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-lua")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-sol2")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-smacker")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-stracciatella")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-string_theory")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-miniaudio")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-magic_enum")
if (MINGW)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-mingw-std-threads")
endif()
if(BUILD_LAUNCHER)
set(LAUNCHER_INCLUDES ${FLTK_INCLUDE_DIR} ${SDL2_INCLUDE_DIR})
set(LAUNCHER_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/sgp/FileMan.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/sgp/SGPFile.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/sgp/SGPStrings.cc"
)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/launcher")
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src
${JA2_INCLUDES}
${SDL2_INCLUDE_DIR}
${SOL_INCLUDE_DIR}
${LUA_INCLUDE_DIRS}
${MINIAUDIO_INCLUDE_DIRS}
${MAGICENUM_INCLUDE_DIR}
)
if(BUILD_LAUNCHER)
include_directories(
${LAUNCHER_INCLUDES}
)
endif()
foreach(FILE ${JA2_SOURCES})
get_filename_component(PARENT_DIR "${FILE}" PATH)
file(RELATIVE_PATH GROUP "${CMAKE_CURRENT_SOURCE_DIR}" "${PARENT_DIR}")
string(REPLACE "/" "\\" GROUP "${GROUP}")
source_group("${GROUP}" FILES "${FILE}")
endforeach()
if (WITH_UNITTESTS)
message(STATUS "Compiling with unittests" )
if (NOT LOCAL_GTEST_LIB)
find_package(GTest REQUIRED)
else()
message(STATUS "Compiling with local GTest libraries from ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-gtest")
add_subdirectory("dependencies/lib-gtest")
endif()
message(STATUS "GTest Libraries: ${GTEST_LIBRARIES}")
target_include_directories(ja2 PRIVATE ${GTEST_INCLUDE_DIRS})
target_compile_definitions(ja2 PRIVATE WITH_UNITTESTS)
endif()
set(
JA2_LIBRARIES
${SDL2_LIBRARY}
${GTEST_LIBRARIES}
smacker
${STRACCIATELLA_LIBRARIES}
string_theory-internal
lua
)
set(
LAUNCHER_LIBRARIES
${SDL2_LIBRARY}
string_theory-internal
)
if (MINGW)
LIST(APPEND JA2_LIBRARIES mingw_stdthreads)
endif()
if (ANDROID)
LIST(APPEND JA2_LIBRARIES android log)
endif()
target_sources(ja2 PRIVATE ${JA2_SOURCES})
target_link_libraries(${JA2_BINARY} ${JA2_LIBRARIES})
# target_compile_features(ja2 PRIVATE cxx_std_20) # not yet...
if (WITH_ASAN)
target_compile_options(${JA2_BINARY} PRIVATE -fsanitize=address)
target_link_options(${JA2_BINARY} PRIVATE -fsanitize=address)
endif()
add_dependencies(${JA2_BINARY} stracciatella)
set_property(SOURCE ${CMAKE_SOURCE_DIR}/src/game/GameVersion.cc APPEND PROPERTY COMPILE_DEFINITIONS "GAME_VERSION=v${ja2-stracciatella_VERSION}")
function(add_warnings target)
if (NOT MSVC)
target_compile_options(${target} PRIVATE -Wall -Wtype-limits -Wignored-qualifiers)
else()
target_compile_options(${target} PRIVATE /W3 /wd4018 /wd4101 /wd4200 /wd4244 /wd4996)
# 4018 : example: signed/unsigned mismatch
# 4101 : example: unreferenced local variable
# 4200 : example: nonstandard extension used : zero-sized array in struct/union
# 4244 : example: conversion from 'int' to 'real', possible loss of data
# 4996 : example: This function or variable may be unsafe (sscanf)
endif()
endfunction()
add_warnings(${JA2_BINARY})
if(ENABLE_PCH)
target_precompile_headers(ja2 PRIVATE
<algorithm>
<array>
<chrono>
<cmath>
<functional>
<map>
<memory>
<numeric>
<optional>
<random>
<set>
<stdexcept>
<stdint.h>
<stdlib.h>
<type_traits>
<utility>
<vector>
)
endif()
if(BUILD_LAUNCHER)
add_executable(${LAUNCHER_BINARY} ${LAUNCHER_SOURCES})
target_link_libraries(${LAUNCHER_BINARY} ${FLTK_LIBRARIES} ${STRACCIATELLA_LIBRARIES} ${LAUNCHER_LIBRARIES})
add_dependencies(${LAUNCHER_BINARY} stracciatella)
add_warnings(${LAUNCHER_BINARY})
if (MSVC)
target_compile_definitions(${LAUNCHER_BINARY} PRIVATE NOMINMAX)
endif()
endif()
macro(copy_assets_dir_to_ja2_binary_after_build DIR)
add_custom_command(TARGET ${JA2_BINARY} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/assets/${DIR} "$<TARGET_FILE_DIR:${JA2_BINARY}>/${DIR}")
endmacro()
copy_assets_dir_to_ja2_binary_after_build("externalized")
copy_assets_dir_to_ja2_binary_after_build("unittests")
copy_assets_dir_to_ja2_binary_after_build("mods")
if(WITH_EDITOR_SLF)
set(EDITORSLF_FILE "${CMAKE_CURRENT_BINARY_DIR}/externalized/editor.slf")
find_package(EditorSlf REQUIRED)
add_custom_templated_target(download-editor-slf)
add_dependencies(${JA2_BINARY} download-editor-slf)
endif()
if (MSVC)
string(REPLACE "SDL2main.lib" "SDL2.dll" SDL_DLL ${SDL2MAIN_LIBRARY})
add_custom_command(TARGET ${JA2_BINARY} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${SDL_DLL} "$<TARGET_FILE_DIR:${JA2_BINARY}>")
endif()
if (APPLE)
add_custom_command(TARGET ${JA2_BINARY}
POST_BUILD COMMAND
${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path"
"$<TARGET_FILE:${JA2_BINARY}>")
add_custom_command(TARGET ${LAUNCHER_BINARY}
POST_BUILD COMMAND
${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path"
"$<TARGET_FILE:${LAUNCHER_BINARY}>")
endif()
## Auxiliary targets
add_custom_target(run-${JA2_BINARY}
COMMAND "$<TARGET_FILE:${JA2_BINARY}>"
WORKING_DIRECTORY "$<TARGET_FILE_DIR:${JA2_BINARY}>"
DEPENDS "${JA2_BINARY}"
)
add_custom_target(run-${JA2_BINARY}-editor
COMMAND "$<TARGET_FILE:${JA2_BINARY}>" -editor
WORKING_DIRECTORY "$<TARGET_FILE_DIR:${JA2_BINARY}>"
DEPENDS "${JA2_BINARY}"
)
add_custom_target(run-${JA2_BINARY}-unittests
COMMAND "$<TARGET_FILE:${JA2_BINARY}>" -unittests
WORKING_DIRECTORY "$<TARGET_FILE_DIR:${JA2_BINARY}>"
DEPENDS "${JA2_BINARY}"
)
if (TARGET "${LAUNCHER_BINARY}")
add_custom_target(run-${LAUNCHER_BINARY}
COMMAND "$<TARGET_FILE:${LAUNCHER_BINARY}>"
WORKING_DIRECTORY "$<TARGET_FILE_DIR:${LAUNCHER_BINARY}>"
DEPENDS "${LAUNCHER_BINARY}"
)
endif()
## Installing and Packaging
set(CPACK_PACKAGE_VERSION_MAJOR ${ja2-stracciatella_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${ja2-stracciatella_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${ja2-stracciatella_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${ja2-stracciatella_VERSION})
set(CPACK_PACKAGE_CONTACT ${CONTACT})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${DESCRIPTION})
set(CPACK_PACKAGE_DESCRIPTION ${DESCRIPTION})
set(CPACK_PACKAGE_INSTALL_DIRECTORY "JA2 Stracciatella")
set(CPACK_DEBIAN_PACKAGE_SECTION "games")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://ja2-stracciatella.github.io/")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl2-2.0-0, libstdc++6, libgcc1, libc6, libfltk1.3-dev, libfltk-images1.3")
set(CPACK_BUNDLE_NAME "JA2 Stracciatella")
set(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/assets/icons/logo.icns")
set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/assets/distr-files-mac/BundleInfo.plist")
set(CPACK_BUNDLE_STARTUP_COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/assets/distr-files-mac/ja2-startup.sh")
set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortcut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\JA2 Stracciatella.lnk' '$INSTDIR\\\\ja2-launcher.exe' '' '$INSTDIR\\\\logo.ico'")
set(CPACK_NSIS_EXECUTABLES_DIRECTORY ".")
set(CPACK_NSIS_MUI_FINISHPAGE_RUN "ja2-launcher.exe")
set(CPACK_NSIS_DISPLAY_NAME "JA2 Stracciatella")
set(CPACK_NSIS_PACKAGE_NAME "JA2 Stracciatella")
set(CPACK_NSIS_URL_INFO_ABOUT "https://ja2-stracciatella.github.io/")
if(UNIX AND NOT MINGW AND NOT APPLE)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PACKAGE_ARCH "x86-64")
else()
set(PACKAGE_ARCH "i386")
endif()
elseif(MINGW)
set(PACKAGE_ARCH "win-mingw")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PACKAGE_ARCH "${PACKAGE_ARCH}64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(PACKAGE_ARCH "${PACKAGE_ARCH}32")
endif()
# build environment:
if(MSYS)
set(PACKAGE_ARCH "${PACKAGE_ARCH}-msys2") # MSYS Makefiles, assuming msys2 shell
elseif(CMAKE_HOST_UNIX)
set(PACKAGE_ARCH "${PACKAGE_ARCH}-cross") # cross compiling
endif()
elseif(MSVC)
set(PACKAGE_ARCH "win-msvc")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PACKAGE_ARCH "${PACKAGE_ARCH}64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(PACKAGE_ARCH "${PACKAGE_ARCH}32")
endif()
set(PACKAGE_ARCH "${PACKAGE_ARCH}-${MSVC_TOOLSET_VERSION}")
elseif(APPLE)
set(PACKAGE_ARCH "macos")
else()
set(PACKAGE_ARCH "unknown")
endif()
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}_${CPACK_PACKAGE_VERSION}_${PACKAGE_ARCH}")
include(CPack)
if (UNIX AND NOT MINGW AND NOT APPLE AND NOT ANDROID)
install(TARGETS ${JA2_BINARY} RUNTIME DESTINATION bin)
if(BUILD_LAUNCHER)
install(TARGETS ${LAUNCHER_BINARY} RUNTIME DESTINATION bin)
endif()
if(WITH_RUST_BINARIES)
install(PROGRAMS "${STRACCIATELLA_EXECUTABLES}" DESTINATION bin)
endif()
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets/externalized assets/mods assets/unittests DESTINATION share/ja2)
if(WITH_EDITOR_SLF)
install(FILES "${EDITORSLF_FILE}" DESTINATION share/ja2/externalized)
endif()
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/distr-files-linux/ja2-stracciatella.desktop DESTINATION share/applications)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/icons/logo.svg
RENAME ja2-stracciatella.svg
DESTINATION share/icons/hicolor/scalable/apps)
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|DragonFly|OpenBSD")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/distr-files-linux/ja2_manpage DESTINATION man/man6 RENAME ja2.6)
else()
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/distr-files-linux/ja2_manpage DESTINATION share/man/man6 RENAME ja2.6)
endif()
elseif(ANDROID)
install(TARGETS ${JA2_BINARY} LIBRARY DESTINATION .)
else()
install(TARGETS ${JA2_BINARY} RUNTIME DESTINATION .)
if(BUILD_LAUNCHER)
install(TARGETS ${LAUNCHER_BINARY} RUNTIME DESTINATION .)
endif()
if(WITH_RUST_BINARIES)
install(PROGRAMS "${STRACCIATELLA_EXECUTABLES}" DESTINATION .)
endif()
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets/externalized assets/mods assets/unittests DESTINATION .)
if(WITH_EDITOR_SLF)
install(FILES "${EDITORSLF_FILE}" DESTINATION ./externalized)
endif()
install(FILES changes.md DESTINATION .)
endif()
if(MSVC OR MINGW)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
include(InstallRequiredSystemLibraries)
file(GLOB WIN_DIST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/assets/distr-files-win/*.txt")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-SDL2-2.0.20-mingw/README-SDL.txt DESTINATION .)
install(FILES ${WIN_DIST_FILES} DESTINATION .)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/icons/logo.ico DESTINATION .)
endif()
if (MSVC)
install(FILES ${SDL_DLL} DESTINATION .)
endif()
if (MINGW)
configure_file("${CMAKE_SOURCE_DIR}/cmake/install-dlls-mingw.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/install-dlls-mingw.cmake" @ONLY)
install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/install-dlls-mingw.cmake")
endif()
if(APPLE)
file(GLOB APPLE_DIST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/assets/distr-files-mac/*.txt")
install(FILES ${APPLE_DIST_FILES} DESTINATION .)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-SDL2-2.0.20-macos/SDL2.framework DESTINATION .)
endif()
## Build AppImage
add_custom_target(package-appimage
COMMAND rm -rf *.AppImage
COMMAND linuxdeploy --appdir AppDir --output appimage
COMMAND mv *.AppImage ${PROJECT_NAME}_${CPACK_PACKAGE_VERSION}_${PACKAGE_ARCH}.AppImage
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS "${JA2_BINARY}"
)
## Uninstall
add_custom_templated_target("uninstall")
## Rebuilding contributors.txt
add_custom_templated_target("rebuild-contributors-list")