-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
259 lines (218 loc) · 7.02 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
cmake_minimum_required(VERSION 3.22)
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"Trying to run cmake inside the source directory. Generate a build dir first!"
)
endif()
set(NAME "SoulsyHUD")
set(VERSION 0.16.10.0)
project(
${NAME}
VERSION ${VERSION}
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
macro(set_from_environment VARIABLE)
if(NOT DEFINED ${VARIABLE} AND DEFINED ENV{${VARIABLE}})
set(${VARIABLE} $ENV{${VARIABLE}})
endif()
endmacro()
# We are managing our dependencies with vcpkg and need this env var set.
set_from_environment(VCPKG_ROOT)
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(
FATAL_ERROR
"Variable VCPKG_ROOT is not set. Please set it in either the cmake file or your env."
)
endif()
set(Boost_USE_STATIC_RUNTIME OFF CACHE BOOL "")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "")
option(ENABLE_SKYRIM_SE "Enable support for Skyrim SE in the dynamic runtime feature." ON)
option(ENABLE_SKYRIM_AE "Enable support for Skyrim AE in the dynamic runtime feature." ON)
option(ENABLE_SKYRIM_VR "Enable support for Skyrim VR in the dynamic runtime feature." OFF)
set(BUILD_TESTS OFF)
# We're building and linking with a Rust library.
set(CARGO_MANIFEST ${CMAKE_SOURCE_DIR}/Cargo.toml)
set(CARGO_TARGET_DIR ${CMAKE_SOURCE_DIR}/target)
set(SOULSY_SOURCE_FILE ${CMAKE_SOURCE_DIR}/src/lib.rs)
set(SOULSY_BRIDGE_CPP ${CARGO_TARGET_DIR}/cxxbridge/soulsy/src/lib.rs.cc)
set(SOULSY_LIB ${CARGO_TARGET_DIR}/release/${CMAKE_STATIC_LIBRARY_PREFIX}soulsy${CMAKE_STATIC_LIBRARY_SUFFIX})
# Add a custom command that builds the rust crate and generates C++ bridge code
add_custom_command(
OUTPUT ${SOULSY_BRIDGE_CPP} ${SOULSY_LIB}
COMMAND cargo build --manifest-path ${CARGO_MANIFEST} --release
DEPENDS ${SOULSY_SOURCE_FILE}
USES_TERMINAL
COMMENT "Running cargo..."
)
# Set up our version header.
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
)
if(MSVC)
add_compile_definitions(
_UNICODE
)
if(NOT ${CMAKE_GENERATOR} STREQUAL "Ninja")
add_compile_options(
/MP # Build with Multiple Processes
)
endif()
endif()
set(Boost_USE_STATIC_LIBS ON)
add_compile_definitions(SKYRIM)
set(CommonLibPath "extern/CommonLibSSE-NG")
set(CommonLibName "CommonLibSSE")
set(GameVersion "Skyrim")
# Find our vcpkg dependencies.
# find_package(CommonLibSSE CONFIG REQUIRED)
find_package(imgui REQUIRED)
include(cmake/sourcelist.cmake)
source_group(
TREE
${CMAKE_CURRENT_SOURCE_DIR}
FILES
${sources}
)
source_group(
TREE
${CMAKE_CURRENT_BINARY_DIR}
FILES
${CMAKE_CURRENT_BINARY_DIR}/include/Version.h
)
# We're building a DLL.
add_library(
${PROJECT_NAME}
SHARED
${sources}
${SOULSY_BRIDGE_CPP}
${CMAKE_CURRENT_BINARY_DIR}/include/Version.h
${CMAKE_CURRENT_BINARY_DIR}/version.rc
)
set_target_properties(
${PROJECT_NAME}
PROPERTIES ADDITIONAL_CLEAN_FILES ${CARGO_TARGET_DIR}
)
target_compile_features(
${PROJECT_NAME}
PRIVATE
cxx_std_23
)
# Set up our compiler options. Windows is weird.
if(MSVC)
add_compile_definitions(
_UNICODE
)
if(NOT ${CMAKE_GENERATOR} STREQUAL "Ninja")
add_compile_options(
/MP # Build with Multiple Processes
)
endif()
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:alignedNew # C++17 over-aligned allocation
/Zc:auto # Deduce Variable Type
/Zc:char8_t
/Zc:__cplusplus # Enable updated __cplusplus macro
/Zc:externC
/Zc:externConstexpr # Enable extern constexpr variables
/Zc:forScope # Force Conformance in for Loop Scope
/Zc:hiddenFriend
/Zc:implicitNoexcept # Implicit Exception Specifiers
/Zc:lambda
/Zc:noexceptTypes # C++17 noexcept rules
/Zc:preprocessor # Enable preprocessor conformance mode
/Zc:referenceBinding # Enforce reference binding rules
/Zc:rvalueCast # Enforce type conversion rules
/Zc:sizedDealloc # Enable Global Sized Deallocation Functions
/Zc:strictStrings # Disable string literal type conversion
/Zc:ternary # Enforce conditional operator rules
/Zc:threadSafeInit # Thread-safe Local Static Initialization
/Zc:tlsGuards
/Zc:trigraphs # Trigraphs Substitution
/Zc:wchar_t # wchar_t Is Native Type
/external:anglebrackets
/external:W0
/W4 # Warning level
/WX # Warning level (warnings are errors)
"$<$<CONFIG:DEBUG>:>"
"$<$<CONFIG:RELEASE>:/Zc:inline;/JMC-;/Ob3>"
)
target_link_options(
${PROJECT_NAME}
PRIVATE
/WX # Treat Linker Warnings as Errors
"$<$<CONFIG:DEBUG>:/INCREMENTAL;/OPT:NOREF;/OPT:NOICF>"
"$<$<CONFIG:RELEASE>:/INCREMENTAL:NO;/OPT:REF;/OPT:ICF;/DEBUG:FULL>"
)
SET_PROPERTY(
TARGET ${PROJECT_NAME}
PROPERTY
VS_USER_PROPS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/no_precomp_std.props
)
endif()
add_subdirectory(${CommonLibPath} ${CommonLibName} EXCLUDE_FROM_ALL)
target_include_directories(
${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/config
${CMAKE_CURRENT_SOURCE_DIR}/src/game
${CMAKE_CURRENT_SOURCE_DIR}/src/log
${CMAKE_CURRENT_SOURCE_DIR}/src/plugin
${CMAKE_CURRENT_SOURCE_DIR}/src/renderer
${CMAKE_CURRENT_SOURCE_DIR}/src/util
${CARGO_TARGET_DIR}/cxxbridge/soulsy/src
${CARGO_TARGET_DIR}/cxxbridge
${CMAKE_CURRENT_BINARY_DIR}/include
)
# The last few of these are surprising, but are pulled in by some of the rust crates
# included in the Rust library.
target_link_libraries(
${PROJECT_NAME}
PRIVATE
${SOULSY_LIB}
CommonLibSSE::CommonLibSSE
imgui::imgui
wsock32
ws2_32
bcrypt
ntdll
userenv
)
# Windows-only configuration (from rust bridge example;)
# if(WIN32)
# target_link_libraries(${PROJECT_NAME} userenv ws2_32 bcrypt)
# set_target_properties(
# ${PROJECT_NAME}
# PROPERTIES
# MSVC_RUNTIME_LIBRARY "MultiThreadedDLL"
# RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}
# RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}
# )
# endif()
# Precompiled headers, because C++ compilers are slow. Everything is slow.
target_precompile_headers(
${PROJECT_NAME}
PRIVATE
src/PCH.h
)