-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
183 lines (156 loc) · 6.79 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
cmake_minimum_required(VERSION 3.5)
project(maxr)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/mk/cmake)
# ============================================
# === Additional Packages
# ============================================
find_package(SDL2 REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(SDL2_net REQUIRED)
find_package(OggVorbis REQUIRED)
# ============================================
# === Checks
# ============================================
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
# ---------------------------------------
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /ZI /bigobj")
set(RESOURCE_FILE src/maxr.rc)
# use WinXP compatible platformtoolset
if (CMAKE_VS_PLATFORM_TOOLSET STREQUAL v120)
set(CMAKE_GENERATOR_TOOLSET "v120_xp" CACHE STRING "CMAKE_GENERATOR_TOOLSET" FORCE)
set(CMAKE_VS_PLATFORM_TOOLSET "v120_xp" CACHE STRING "CMAKE_VS_PLATFORM_TOOLSET" FORCE)
endif()
if (CMAKE_VS_PLATFORM_TOOLSET STREQUAL v140)
set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "CMAKE_GENERATOR_TOOLSET" FORCE)
set(CMAKE_VS_PLATFORM_TOOLSET "v140_xp" CACHE STRING "CMAKE_VS_PLATFORM_TOOLSET" FORCE)
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes") # remove noises about C++17 attributes used
endif()
# ============================================
# === Targets
# ============================================
# nlohmann is a library header for json
add_library(nlohmann INTERFACE IMPORTED)
target_include_directories(nlohmann SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/submodules/nlohmann/single_include")
# spiritless_po is a library header for gettext po translation
add_library(spiritless_po INTERFACE IMPORTED)
target_include_directories(spiritless_po SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/submodules/spiritless_po/include")
# doctest is a library header for test framework
include(CTest)
if(BUILD_TESTING)
add_library(doctest INTERFACE IMPORTED)
target_include_directories(doctest SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/submodules/doctest/doctest")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/submodules/doctest/scripts/cmake")
include(doctest)
endif()
# SDL_flic
add_library(SDL_flic src/3rd/SDL_flic/SDL_flic.c src/3rd/SDL_flic/SDL_flic.h)
target_include_directories(SDL_flic PUBLIC ${SDL2_INCLUDE_DIR})
target_include_directories(SDL_flic INTERFACE src)
target_link_libraries(SDL_flic PUBLIC ${SDL2_LIBRARY})
# mve player
add_library(mve_player src/3rd/mveplayer/mveplayer.cpp src/3rd/mveplayer/mveplayer.h)
target_include_directories(mve_player PUBLIC ${SDL2_INCLUDE_DIR})
target_include_directories(mve_player INTERFACE src)
target_link_libraries(mve_player PUBLIC ${SDL2_LIBRARY})
# maxr library
file(GLOB_RECURSE maxr_LIB_SRCS "src/lib/*.cpp" "src/lib/*.h")
add_library(maxr_lib ${maxr_LIB_SRCS})
target_include_directories(maxr_lib PUBLIC src/lib)
target_include_directories(maxr_lib PUBLIC ${SDL2_INCLUDE_DIR} ${SDL2_MIXER_INCLUDE_DIR} ${SDL2_NET_INCLUDE_DIR})
target_link_libraries(maxr_lib PUBLIC nlohmann ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARY} ${SDL2_NET_LIBRARY})
target_link_libraries(maxr_lib PRIVATE spiritless_po)
## add crash reporting library
if(CRASH_RPT_INCLUDE_DIR)
target_compile_definitions(maxr_lib PUBLIC USE_CRASH_RPT)
target_include_directories(maxr_lib PUBLIC ${CRASH_RPT_INCLUDE_DIR})
target_link_libraries(maxr_lib PUBLIC ${CRASH_RPT_LIB})
endif()
## Add GIT Revision
include(GetGitRevisionDescription)
git_describe(GIT_DESC --always)
if (GIT_DESC)
message(STATUS "Setting cpp define GIT_DESC to ${GIT_DESC}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/autoversion.h.in" "${CMAKE_CURRENT_BINARY_DIR}/autoversion.h")
target_include_directories(maxr_lib PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
else()
message("Could not automativally set the maxr GIT_DESC from git. Set cmake variable GIT_EXECUTABLE to use this feature.")
endif()
# maxr dedicated server
file(GLOB_RECURSE maxr_dedicatedserver_SRCS "src/dedicatedserver/*.cpp" "src/dedicatedserver/*.h")
add_executable(maxr_dedicatedserver ${maxr_dedicatedserver_SRCS} ${RESOURCE_FILE})
target_include_directories(maxr_lib PUBLIC src)
target_link_libraries(maxr_dedicatedserver maxr_lib)
# maxr
file(GLOB_RECURSE maxr_SRCS "src/ui/*.cpp" "src/ui/*.h")
add_executable(maxr ${maxr_SRCS} ${RESOURCE_FILE})
target_link_libraries(maxr maxr_lib SDL_flic mve_player)
# maxr tests
if(BUILD_TESTING)
file(GLOB_RECURSE maxr_tests_SRCS "tests/*.cpp" "tests/*.h")
add_executable(maxr_tests ${maxr_tests_SRCS})
target_include_directories(maxr_tests PRIVATE tests)
target_link_libraries(maxr_tests maxr_lib doctest)
doctest_discover_tests(maxr_tests)
endif()
# resinstaller
add_executable(resinstaller
resinstaller/src/converter.cpp
resinstaller/src/converter.h
resinstaller/src/defines.h
resinstaller/src/file.cpp
resinstaller/src/file.h
resinstaller/src/ogg_encode.cpp
resinstaller/src/ogg_encode.h
resinstaller/src/palette.h
resinstaller/src/pcx.cpp
resinstaller/src/pcx.h
resinstaller/src/resinstaller.cpp
resinstaller/src/resinstaller.h
resinstaller/src/wave.cpp
resinstaller/src/wave.h
)
target_include_directories(resinstaller PUBLIC ${SDL2_INCLUDE_DIR} ${OGG_INCLUDE_DIR} ${VORBIS_INCLUDE_DIR})
target_link_libraries(resinstaller SDL_flic ${SDL2_LIBRARY} ${OGG_LIBRARY} ${VORBIS_LIBRARY})
if(WIN32)
else()
target_link_libraries(resinstaller ${VORBISFILE_LIBRARY} ${VORBISENC_LIBRARY})
endif()
# set linker flags for target
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set_target_properties(maxr PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
target_compile_definitions(maxr_lib PRIVATE "NOMINMAX" "_USE_MATH_DEFINES")
target_compile_definitions(maxr PRIVATE "NOMINMAX" "_USE_MATH_DEFINES")
target_compile_definitions(maxr_dedicatedserver PRIVATE "NOMINMAX" "_USE_MATH_DEFINES")
endif()
# Source group for IDE
macro(GroupSources curdir)
file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*)
foreach(child ${children})
if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child})
GroupSources(${curdir}/${child})
else()
string(REPLACE "/" "\\" groupname ${curdir})
source_group(${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child})
endif()
endforeach()
endmacro()
GroupSources(src)
# source_group(TREE . FILES maxr_SRCS)
# ============================================
# === Install
# ============================================
if (UNIX)
install(TARGETS maxr DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/data/"
DESTINATION share/maxr
PATTERN ".gitignore" EXCLUDE
)
endif()