forked from SaneEngineer/No-Grass-In-Objects-NG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
292 lines (254 loc) · 6.95 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
cmake_minimum_required(VERSION 3.21)
set(NAME "NGIO-NG" CACHE STRING "")
set(VERSION 1.0.9 CACHE STRING "")
set(VR_VERSION 2)
set(AE_VERSION 1)
option(COPY_BUILD "Copy the build output to the Skyrim directory." FALSE)
option(BUILD_SKYRIMVR "Build for Skyrim VR" OFF)
option(BUILD_SKYRIMAE "Build for Skyrim AE" OFF)
# ---- Cache build vars ----
macro(set_from_environment VARIABLE)
if(NOT DEFINED ${VARIABLE} AND DEFINED ENV{${VARIABLE}})
set(${VARIABLE} $ENV{${VARIABLE}})
endif()
endmacro()
macro(find_commonlib_path)
if(CommonLibName AND NOT ${CommonLibName} STREQUAL "")
# Check extern
find_path(CommonLibPath
include/REL/Relocation.h
PATHS extern/${CommonLibName})
if(${CommonLibPath} STREQUAL "CommonLibPath-NOTFOUND")
# Check path
set_from_environment(${CommonLibName}Path)
set(CommonLibPath ${${CommonLibName}Path})
endif()
endif()
endmacro()
set_from_environment(VCPKG_ROOT)
if(BUILD_SKYRIMAE)
add_compile_definitions(SKYRIM_AE)
add_compile_definitions(SKYRIM_SUPPORT_AE)
set(CommonLibName "CommonLibSSE")
set_from_environment(SkyrimAEPath)
set(SkyrimPath ${SkyrimAEPath})
set(SkyrimVersion "Skyrim AE")
set(VERSION ${VERSION}.${AE_VERSION})
elseif(BUILD_SKYRIMVR)
add_compile_definitions(SKYRIMVR)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
set(CommonLibName "CommonLibVR")
set_from_environment(SkyrimVRPath)
set(SkyrimPath ${SkyrimVRPath})
set(SkyrimVersion "Skyrim VR")
set(VERSION ${VERSION}.${VR_VERSION})
else()
set(CommonLibName "CommonLibSSE")
set_from_environment(Skyrim64Path)
set(SkyrimPath ${Skyrim64Path})
set(SkyrimVersion "Skyrim SSE")
endif()
find_commonlib_path()
message(
STATUS
"Building ${NAME} ${VERSION} for ${SkyrimVersion} at ${SkyrimPath} with ${CommonLibName} at ${CommonLibPath}."
)
if(DEFINED VCPKG_ROOT)
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
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 "")
# ---- Project ----
project(
${NAME}
VERSION ${VERSION}
LANGUAGES CXX
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Version.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/Version.h
@ONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in
${CMAKE_CURRENT_BINARY_DIR}/version.rc
@ONLY
)
# ---- Include guards ----
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()
# ---- Globals ----
add_compile_definitions(
SKSE_SUPPORT_XBYAK
)
if(MSVC)
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 ----
# dependency macros
macro(find_dependency_path DEPENDENCY FILE)
# searches extern for dependencies and if not checks the environment variable
if(NOT ${DEPENDENCY} STREQUAL "")
# Check extern
message(
STATUS
"Searching for ${DEPENDENCY} using file ${FILE}"
)
find_path("${DEPENDENCY}Path"
${FILE}
PATHS "extern/${DEPENDENCY}"
)
if("${${DEPENDENCY}Path}" STREQUAL "${DEPENDENCY}Path-NOTFOUND")
# Check path
message(
STATUS
"Getting environment for ${DEPENDENCY}Path: $ENV{${DEPENDENCY}Path}"
)
set("${DEPENDENCY}Path" "$ENV{${DEPENDENCY}Path}")
endif()
message(
STATUS
"Found ${DEPENDENCY} in ${${DEPENDENCY}Path}; adding"
)
add_subdirectory("${${DEPENDENCY}Path}" ${DEPENDENCY})
endif()
endmacro()
if(DEFINED CommonLibPath AND NOT ${CommonLibPath} STREQUAL "" AND IS_DIRECTORY ${CommonLibPath})
add_subdirectory(${CommonLibPath} ${CommonLibName})
else()
message(
FATAL_ERROR
"Variable ${CommonLibName}Path is not set or in extern/."
)
endif()
# GLM
find_package(GLM REQUIRED)
include_directories(${GLM_INCLUDE_DIRS})
# ---- Add source files ----
include(cmake/headerlist.cmake)
include(cmake/sourcelist.cmake)
source_group(
TREE
${CMAKE_CURRENT_SOURCE_DIR}
FILES
${headers}
${sources}
)
source_group(
TREE
${CMAKE_CURRENT_BINARY_DIR}
FILES
${CMAKE_CURRENT_BINARY_DIR}/include/Version.h
)
# ---- Create DLL ----
add_library(
${PROJECT_NAME}
SHARED
${headers}
${sources}
${CMAKE_CURRENT_BINARY_DIR}/include/Version.h
${CMAKE_CURRENT_BINARY_DIR}/version.rc
.clang-format
.editorconfig
)
target_compile_features(
${PROJECT_NAME}
PRIVATE
cxx_std_23
)
target_compile_definitions(
${PROJECT_NAME}
PRIVATE
_UNICODE
)
target_include_directories(
${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CLIB_UTIL_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/external/CasualLibrary1.0
)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
${CommonLibName}::${CommonLibName}
${CMAKE_CURRENT_SOURCE_DIR}/external/CasualLibrary1.0/lib/x64/Release/CasualLibrary.lib
)
target_precompile_headers(
${PROJECT_NAME}
PRIVATE
include/PCH.h
)
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
"$<$<CONFIG:DEBUG>:>"
"$<$<CONFIG:RELEASE>:/Zc:inline;/JMC-;/Ob3>"
)
target_link_options(
${PROJECT_NAME}
PRIVATE
"$<$<CONFIG:DEBUG>:/INCREMENTAL;/OPT:NOREF;/OPT:NOICF>"
"$<$<CONFIG:RELEASE>:/INCREMENTAL:NO;/OPT:REF;/OPT:ICF;/DEBUG:FULL>"
)
endif()
# ---- Post build ----
# if(COPY_BUILD)
# if(DEFINED SkyrimPath)
# add_custom_command(
# TARGET ${PROJECT_NAME}
# POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> ${SkyrimPath}/SKSE/Plugins/
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> ${SkyrimPath}/SKSE/Plugins/
# )
# else()
# message(
# WARNING
# "Variable ${SkyrimPath} is not defined. Skipping post-build copy command."
# )
# endif()
# endif()
# https://gitlab.kitware.com/cmake/cmake/-/issues/24922#note_1371990
if(MSVC_VERSION GREATER_EQUAL 1936 AND MSVC_IDE) # 17.6+
# When using /std:c++latest, "Build ISO C++23 Standard Library Modules" defaults to "Yes".
# Default to "No" instead.
#
# As of CMake 3.26.4, there isn't a way to control this property
# (https://gitlab.kitware.com/cmake/cmake/-/issues/24922),
# We'll use the MSBuild project system instead
# (https://learn.microsoft.com/en-us/cpp/build/reference/vcxproj-file-structure)
file(CONFIGURE OUTPUT "${CMAKE_BINARY_DIR}/Directory.Build.props" CONTENT [==[
<Project>
<ItemDefinitionGroup>
<ClCompile>
<BuildStlModules>false</BuildStlModules>
</ClCompile>
</ItemDefinitionGroup>
</Project>
]==] @ONLY)
endif()