generated from Ryan-rsm-McKenzie/ExamplePlugin-CommonLibSSE
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
310 lines (264 loc) · 8.65 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
cmake_minimum_required(VERSION 3.21)
# ---- Options ----
option(COPY_BUILD "Copy the build output to target directory." OFF)
set(SKYRIM64_DATA_PATH "" CACHE PATH "Path to the Skyrim SE Data folder. Hint: You can set this to the mod folder when using MO2.")
# ---- Cache build vars ----
macro(set_from_environment VARIABLE)
if(NOT DEFINED ${VARIABLE} AND DEFINED ENV{${VARIABLE}})
set(${VARIABLE} $ENV{${VARIABLE}})
endif()
endmacro()
set_from_environment(VCPKG_ROOT)
if(DEFINED VCPKG_ROOT)
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH "")
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "")
else()
message(
WARNING
"Variable VCPKG_ROOT is not set. Continuing without vcpkg."
)
endif()
set(Boost_USE_STATIC_RUNTIME OFF CACHE BOOL "")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "")
set(SKYRIM_VERSION "AE2" CACHE STRING "Sets the DLL target compile version.")
set_property(CACHE SKYRIM_VERSION PROPERTY STRINGS "AE" "AE2" "SE" "VR")
# ---- Project ----
project(
YASTM
VERSION 3.0.0
LANGUAGES CXX
)
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/include/version.hpp
@ONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in
${CMAKE_CURRENT_BINARY_DIR}/version.rc
@ONLY
)
# ---- Globals ----
if(MSVC)
add_compile_definitions(
_UNICODE
)
if(NOT ${CMAKE_GENERATOR} STREQUAL "Ninja")
add_compile_options(
/MP # Build with Multiple Processes
)
endif()
endif()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
set(Boost_USE_STATIC_LIBS ON)
# ---- Dependencies ----
if(SKYRIM_VERSION STREQUAL "SE")
add_subdirectory("extern/CommonLibSSE_SE" CommonLibSSE)
elseif(SKYRIM_VERSION STREQUAL "AE")
add_subdirectory("extern/CommonLibSSE_AE" CommonLibSSE)
elseif(SKYRIM_VERSION STREQUAL "AE2")
add_subdirectory("extern/CommonLibSSE_AE2" CommonLibSSE)
elseif(SKYRIM_VERSION STREQUAL "VR")
if (BUILD_SKYRIMVR)
add_subdirectory("extern/CommonLibVR" CommonLibVR)
else()
add_subdirectory("extern/CommonLibVR" CommonLibSSE)
endif()
else()
message(FATAL_ERROR "Unknown Skyrim version: ${SKYRIM_VERSION}")
endif()
find_package(spdlog REQUIRED CONFIG)
find_package(tomlplusplus REQUIRED)
# ---- Add source files ----
set(SOURCES
src/global.hpp
src/main.cpp
src/PCH.hpp
src/chargeitemfix.hpp
src/chargeitemfix.cpp
src/enchantitemfix.hpp
src/enchantitemfix.cpp
src/expectedbytes.hpp
src/messages.hpp
src/offsets.hpp
src/SoulSize.hpp
src/SoulValue.hpp
src/trampoline.hpp
src/trapsoulfix.hpp
src/trapsoulfix.cpp
src/config/ConcreteSoulGemGroup.hpp
src/config/ConcreteSoulGemGroup.cpp
src/config/ConfigKey/BoolConfigKey.hpp
src/config/ConfigKey/EnumConfigKey.hpp
src/config/ConfigKey/IntConfigKey.hpp
src/config/configutilities.hpp
src/config/DLLDependencyKey.hpp
src/config/Form.hpp
src/config/FormError.hpp
src/config/FormError.cpp
src/config/FormId.hpp
src/config/FormId.cpp
src/config/FormLocator.hpp
src/config/GlobalVarForm.hpp
src/config/LoadPriority.hpp
src/config/ParseError.hpp
src/config/SoulGemGroup.hpp
src/config/SoulGemGroup.cpp
src/config/SoulGemMap.hpp
src/config/SoulGemMap.cpp
src/config/SpecificationError.hpp
src/config/SpecificationError.cpp
src/config/YASTMConfig.hpp
src/config/YASTMConfig.cpp
src/formatters/TESForm.hpp
src/formatters/TESSoulGem.hpp
src/fsutils/FSUtils.hpp
src/fsutils/FSUtils.cpp
src/fsutils/internal/Config.hpp
src/fsutils/internal/Config.cpp
src/fsutils/internal/ConfigManager.hpp
src/fsutils/internal/ConfigManager.cpp
src/trapsoul/SearchResult.hpp
src/trapsoul/SoulTrapData.hpp
src/trapsoul/SoulTrapData.cpp
src/trapsoul/trapsoul.hpp
src/trapsoul/trapsoul.cpp
src/trapsoul/types.hpp
src/trapsoul/Victim.hpp
src/utilities/algorithms.hpp
src/utilities/assembly.hpp
src/utilities/containerutils.hpp
src/utilities/EnumArray.hpp
src/utilities/formidutils.hpp
src/utilities/FormType.hpp
src/utilities/misc.hpp
src/utilities/misc.cpp
src/utilities/native.hpp
src/utilities/PapyrusFunctionRegistry.hpp
src/utilities/printerror.hpp
src/utilities/printerror.cpp
src/utilities/rng.hpp
src/utilities/stringutils.hpp
src/utilities/Timer.hpp
src/yastmutils/YASTMUtils.hpp
src/yastmutils/YASTMUtils.cpp
)
source_group(
TREE
${CMAKE_CURRENT_SOURCE_DIR}
FILES
${SOURCES}
)
source_group(
TREE
${CMAKE_CURRENT_BINARY_DIR}
FILES
${CMAKE_CURRENT_BINARY_DIR}/include/version.hpp
)
# ---- Create DLL ----
add_library(
${PROJECT_NAME}
SHARED
${SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/include/version.hpp
${CMAKE_CURRENT_BINARY_DIR}/version.rc
.clang-format
.editorconfig
)
target_compile_features(
${PROJECT_NAME}
PRIVATE
cxx_std_23
)
target_include_directories(
${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
)
if (SKYRIM_VERSION STREQUAL "VR" AND BUILD_SKYRIMVR)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
CommonLibVR::CommonLibVR
spdlog::spdlog
fmt::fmt
tomlplusplus::tomlplusplus
)
else()
target_link_libraries(
${PROJECT_NAME}
PRIVATE
CommonLibSSE::CommonLibSSE
spdlog::spdlog
fmt::fmt
tomlplusplus::tomlplusplus
)
endif()
if(MSVC)
target_compile_options(
${PROJECT_NAME}
PRIVATE
/sdl # Enable Additional Security Checks
/utf-8 # Set Source and Executable character sets to UTF-8
/Zi # Debug Information Format
/permissive- # Standards conformance
/Zc:preprocessor # Enable preprocessor conformance mode
/wd4200 # nonstandard extension used : zero-sized array in struct/union
/external:anglebrackets
/external:W0
/W4 # Warning level
# /WX # Warning level (warnings are errors)
"$<$<CONFIG:Debug>:>"
"$<$<CONFIG:Release,RelWithDebInfo>:/Zc:inline;/JMC-;/O2;/Ob3>"
)
target_link_options(
${PROJECT_NAME}
PRIVATE
/WX # Treat Linker Warnings as Errors
"$<$<CONFIG:Debug>:/INCREMENTAL;/OPT:NOREF;/OPT:NOICF>"
"$<$<CONFIG:Release,RelWithDebInfo>:/INCREMENTAL:NO;/OPT:REF;/OPT:ICF;/DEBUG:FULL>"
)
else()
message(WARNING "MSVC is the only supported compiler. Proceed at your own caution.")
endif()
target_precompile_headers(
${PROJECT_NAME}
PRIVATE
src/PCH.hpp
)
if (SKYRIM_VERSION STREQUAL "AE")
target_compile_definitions(${PROJECT_NAME} PRIVATE SKYRIM_VERSION_AE)
elseif(SKYRIM_VERSION STREQUAL "AE2")
target_compile_definitions(${PROJECT_NAME} PRIVATE SKYRIM_VERSION_AE2)
elseif(SKYRIM_VERSION STREQUAL "SE")
target_compile_definitions(${PROJECT_NAME} PRIVATE SKYRIM_VERSION_SE)
elseif(SKYRIM_VERSION STREQUAL "VR")
target_compile_definitions(${PROJECT_NAME} PRIVATE SKYRIM_VERSION_VR SKYRIMVR)
else()
message(FATAL_ERROR "Unknown Skyrim version: ${SKYRIM_VERSION}")
endif()
# ---- Post build ----
if(COPY_BUILD)
if(SKYRIM64_DATA_PATH)
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${SKYRIM64_DATA_PATH}/SKSE/Plugins
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> ${SKYRIM64_DATA_PATH}/SKSE/Plugins
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> ${SKYRIM64_DATA_PATH}/SKSE/Plugins
)
else()
message(
WARNING
"Variable SKYRIM64_DATA_PATH is empty. Skipping post-build copy command."
)
endif()
endif()