forked from klei1984/max
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
185 lines (146 loc) · 6.12 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
cmake_minimum_required (VERSION 3.24)
project(max LANGUAGES C CXX)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
option(MAX_BUILD_TESTS "Build unit tests by default" ON)
option(MAX_ENABLE_UPNP "Use miniupnpc library" ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(setup)
set(GAME_INCLUDES "")
set(GAME_SOURCES "")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src")
add_executable(${PROJECT_NAME} ${GAME_SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${GAME_INCLUDES}
)
set_target_properties(${PROJECT_NAME} PROPERTIES
COMPILE_FLAGS "${MAX_CFLAGS} -DGAME_VERSION_STRING=\"\\\"v${GAME_VERSION_STRING}\\\"\" -DGAME_VERSION_MAJOR=\"${GAME_VERSION_MAJOR}\" -DGAME_VERSION_MINOR=\"${GAME_VERSION_MINOR}\" -DGAME_VERSION_PATCH=\"${GAME_VERSION_PATCH}\" -DSDL_ASSERT_LEVEL=2"
)
if(MAX_ENABLE_UPNP)
target_compile_definitions(${PROJECT_NAME} PUBLIC MAX_ENABLE_UPNP=1)
endif()
if(NOT BUILD_SHARED_LIBS)
set(${PROJECT_NAME}_deps SDL2::SDL2main Iconv::Iconv Freetype::Freetype Miniaudio::Miniaudio Enet::Enet SDL2::SDL2-static)
if(MAX_ENABLE_UPNP)
list(APPEND ${PROJECT_NAME}_deps miniupnpc::miniupnpc)
endif()
target_link_options(${PROJECT_NAME} PUBLIC -static -static-libgcc -static-libstdc++)
target_link_libraries(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_deps})
else()
set(${PROJECT_NAME}_deps SDL2::SDL2main Iconv::Iconv Freetype::Freetype Miniaudio::Miniaudio Enet::Enet SDL2::SDL2)
if(MAX_ENABLE_UPNP)
list(APPEND ${PROJECT_NAME}_deps miniupnpc::miniupnpc)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_deps})
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cmake/lib-iconv ${CMAKE_CURRENT_BINARY_DIR}/_deps/iconv-build)
include(sdl2)
include(freetype)
include(miniaudio)
set(ENET_RELEASE ON)
include(enet)
if(MAX_ENABLE_UPNP)
include(miniupnp)
endif()
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ARGS --only-keep-debug $<TARGET_FILE:${PROJECT_NAME}> ${PROJECT_NAME}.debug
COMMAND ${CMAKE_STRIP} ARGS --strip-debug --strip-unneeded $<TARGET_FILE:${PROJECT_NAME}>
COMMAND ${CMAKE_OBJCOPY} ARGS --add-gnu-debuglink ${PROJECT_NAME}.debug $<TARGET_FILE:${PROJECT_NAME}>
)
if(MAX_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
set(CPACK_PACKAGE_VERSION_MAJOR ${GAME_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${GAME_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${GAME_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
set(CPACK_PACKAGE_NAME "max-port")
set(CPACK_PACKAGE_CONTACT "M.A.X. Port Team")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "M.A.X. Port v${GAME_VERSION_STRING}")
set(CPACK_PACKAGE_DESCRIPTION "M.A.X. Port is an SDL library based runtime executable for the 1996 MS-DOS game M.A.X.: Mechanized Assault & Exploration developed and published by Interplay Productions.")
set(CPACK_SOURCE_IGNORE_FILES "/\.git/;/\.github/;/\.settings/;\.gitignore;.\.launch;\.project;\.cproject;\.clang-format;\.gdbinit;README.md;/doc/;${CMAKE_BINARY_DIR};Debug;Release;RelWithDebInfo;MinSizeRel;/dependencies/.*\.tar\.gz")
if(UNIX)
include(GNUInstallDirs)
set(CPACK_GENERATOR "DEB")
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_SECTION "games")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://klei1984.github.io/max/")
if(X86)
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
elseif(X86_64)
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
endif()
set(DEP_BIN_DIRS)
foreach(TARGET_NAME ${${PROJECT_NAME}_deps})
get_target_property(BIN_DIR ${TARGET_NAME} BINARY_DIR)
list(APPEND DEP_BIN_DIRS "${BIN_DIR}")
list(APPEND DEP_BIN_DIRS "${BIN_DIR}/lib")
endforeach()
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS ${DEP_BIN_DIRS})
install(CODE "set(PROJECT_NAME \"${PROJECT_NAME}\")")
install(CODE "set(CMAKE_INSTALL_BINDIR \"${CMAKE_INSTALL_BINDIR}\")")
install(CODE "set(CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\")")
install(CODE "set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS \"${DEP_BIN_DIRS}\")")
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES max
RESOLVED_DEPENDENCIES_VAR DEPS_RESOLVED
UNRESOLVED_DEPENDENCIES_VAR DEPS_UNRESOLVED
CONFLICTING_DEPENDENCIES_PREFIX DEPS_CONFLICTING
DIRECTORIES ${CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS}
)
if(DEPS_CONFLICTING_FILENAMES)
message(WARNING "Conflicting dependencies for library: \"${DEPS_CONFLICTING}\"!")
endif()
foreach(DEP_FILE ${DEPS_RESOLVED})
file(INSTALL
FILES "${DEP_FILE}"
FOLLOW_SYMLINK_CHAIN
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
endforeach()
]])
install(TARGETS ${PROJECT_NAME}
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}
)
endif()
if(MINGW)
set(CMAKE_INSTALL_BINDIR "." CACHE PATH "User executables directory" FORCE)
set(CMAKE_INSTALL_DATADIR "." CACHE PATH "Read-only architecture-independent data directory" FORCE)
include(GNUInstallDirs)
set(CPACK_GENERATOR "7Z")
set(CPACK_SOURCE_GENERATOR "7Z")
find_program(MAKENSIS_EXECUTABLE NAMES makensis${CMAKE_EXECUTABLE_SUFFIX} DOC "The NSIS package maker command")
if(MAKENSIS_EXECUTABLE)
list(APPEND CPACK_GENERATOR "NSIS")
set(CPACK_NSIS_EXECUTABLES_DIRECTORY ".")
set(CPACK_NSIS_MUI_FINISHPAGE_RUN "${PROJECT_NAME}")
set(CPACK_NSIS_DISPLAY_NAME "M.A.X. Port")
set(CPACK_NSIS_PACKAGE_NAME "M.A.X. Port v${GAME_VERSION_STRING}")
set(CPACK_NSIS_URL_INFO_ABOUT "https://klei1984.github.io/max/")
endif()
install(TARGETS ${PROJECT_NAME}
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
RUNTIME DESTINATION .
)
if(BUILD_SHARED_LIBS)
set(DEP_BIN_DIRS)
foreach(TARGET_NAME ${${PROJECT_NAME}_deps})
get_target_property(BIN_DIR ${TARGET_NAME} BINARY_DIR)
list(APPEND DEP_BIN_DIRS "${BIN_DIR}")
endforeach()
install(CODE "
include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}\" \"\" \"${DEP_BIN_DIRS}\")
"
)
endif()
endif()
add_subdirectory(assets)
INCLUDE(CPack)