-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathCMakeLists.txt
183 lines (160 loc) · 6.29 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.12 FATAL_ERROR)
include(CheckCXXCompilerFlag)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
# force Release by default.
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
project(TheForceEngine
HOMEPAGE_URL "https://theforceengine.github.io"
DESCRIPTION "Modern 'Jedi Engine' replacement supporting Dark Forces, mods, and in the future Outlaws."
)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
## gcc-12+ and clang-15+ have a feature to automatically zero all variables/members/...
## this mimics what modern MSVC does. Enable it for release builds (i.e.
## when not debugging to not hide any real bugs).
if(CMAKE_BUILD_TYPE STREQUAL "Release")
check_cxx_compiler_flag("-ftrivial-auto-var-init=zero" COMPILER_ENABLE_AUTOZERO)
endif()
# disable Clangs excessive warnings about unhandled switch values
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch")
endif()
if (UNIX AND NOT APPLE)
set(LINUX ON)
endif()
if(WIN32)
# windows: drop everything into one folder
set(CMAKE_INSTALL_BINDIR ".")
set(CMAKE_INSTALL_LIBDIR ".")
set(CMAKE_INSTALL_DATADIR ".")
else()
set(TFE_ICONDIR "share/icons/hicolor")
# tweak DATADIR to end up with ./share/TheForceEngine/
set(CMAKE_INSTALL_DATADIR "share/${PROJECT_NAME}"
CACHE PATH "Read-only architecture-independent data"
)
endif()
include(GNUInstallDirs)
## Options
option(ENABLE_TFE "Enable building “The Force Engine”" ON)
option(ENABLE_SYSMIDI "Enable System-MIDI Output if RTMidi is available" ON)
option(ENABLE_EDITOR "Enable TFE Editor" OFF)
option(ENABLE_ADJUSTABLEHUD_MOD "Install the build‑in “AdjustableHud mod” with TFE" ON)
if(ENABLE_TFE)
add_executable(tfe)
set_target_properties(tfe PROPERTIES OUTPUT_NAME "theforceengine")
if(UNIX)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(SDL2 REQUIRED)
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
target_include_directories(tfe PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(tfe PRIVATE ${SDL2_INCLUDE_DIRS})
target_include_directories(tfe PRIVATE ${SDL2_IMAGE_INCLUDE_DIRS})
target_link_libraries(tfe PRIVATE ${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${CMAKE_DL_LIBS}
Threads::Threads
)
# set up build directory to be able to run TFE immediately: symlink
# the necessary support file directories into the build env.
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/Captions)
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/Documentation)
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/ExternalData)
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/Fonts)
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/Mods)
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/Shaders)
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/SoundFonts)
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/UI_Images)
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/UI_Text)
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/TheForceEngine/EditorDef)
include(CreateGitVersionH.cmake)
create_git_version_h()
endif()
if(COMPILER_ENABLE_AUTOZERO)
message(STATUS "enabled -ftrivial-auto-var-init=zero")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftrivial-auto-var-init=zero")
endif()
if(ENABLE_SYSMIDI)
pkg_check_modules(RTMIDI rtmidi>=5.0.0)
if(RTMIDI_FOUND)
add_definitions("-DBUILD_SYSMIDI")
target_link_libraries(tfe PRIVATE ${RTMIDI_LIBRARIES})
else()
set(ENABLE_SYSMIDI 0)
message(STATUS "System MIDI Disabled")
endif()
endif()
if(ENABLE_EDITOR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBUILD_EDITOR")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBUILD_FORCE_SCRIPT")
target_include_directories(tfe PRIVATE "TheForceEngine/TFE_ForceScript/Angelscript/angelscript/include")
target_include_directories(tfe PRIVATE "TheForceEngine/TFE_ForceScript/Angelscript/add_on")
target_include_directories(tfe PRIVATE TheForceEngine)
add_subdirectory(TheForceEngine/)
endif()
### installation ###
if(ENABLE_TFE)
# Main binary
install(TARGETS tfe
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
# Support data
install(DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/Captions"
"${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/Documentation"
"${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/ExternalData"
"${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/UI_Text"
"${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/UI_Images"
"${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/EditorDef"
"${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/Shaders"
"${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/SoundFonts"
"${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/Fonts"
DESTINATION "${CMAKE_INSTALL_DATADIR}"
FILE_PERMISSIONS
OWNER_READ OWNER_WRITE
GROUP_READ
WORLD_READ
DIRECTORY_PERMISSIONS
OWNER_READ OWNER_EXECUTE OWNER_WRITE
GROUP_READ GROUP_EXECUTE GROUP_WRITE
WORLD_READ WORLD_EXECUTE
)
# Always install the “Mods” directory but not always the “AdjustableHud” mod
install(DIRECTORY
DESTINATION "${CMAKE_INSTALL_DATADIR}/TheForceEngine/Mods"
DIRECTORY_PERMISSIONS
OWNER_READ OWNER_EXECUTE OWNER_WRITE
GROUP_READ GROUP_EXECUTE GROUP_WRITE
WORLD_READ WORLD_EXECUTE
)
# Linux .desktop files
if(LINUX)
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/io.github.theforceengine.tfe.desktop" DESTINATION "share/applications"
)
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/io.github.theforceengine.tfe.png" DESTINATION "${TFE_ICONDIR}/256x256/apps"
)
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/io.github.theforceengine.tfe.metainfo.xml"
DESTINATION "share/metainfo"
)
endif()
endif()
if(ENABLE_ADJUSTABLEHUD_MOD)
add_subdirectory(TheForceEngine/Mods/TFE/AdjustableHud)
if(LINUX)
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/TheForceEngine/io.github.theforceengine.tfe.Mod.AdjustableHud.metainfo.xml"
DESTINATION "share/metainfo"
)
endif()
endif()