-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
199 lines (168 loc) · 4.78 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
cmake_minimum_required(VERSION 3.21)
# Setup project
project(
TimeFormatChanger
VERSION 1.2.1
LANGUAGES CXX
)
set(FORMATTED_NAME "Time Format Changer")
set(LICENSE "MIT License")
set(AUTHOR "Vermunds")
# 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()
# Configure files
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 sources
include(cmake/sourcelist.cmake)
source_group(
TREE "${CMAKE_CURRENT_SOURCE_DIR}"
FILES ${SOURCES}
)
# Global compile definitions
if (MSVC)
add_compile_definitions(
_UNICODE
)
if (NOT ${CMAKE_GENERATOR} STREQUAL "Ninja")
add_compile_options(
/MP # Build with Multiple Processes
)
endif ()
endif ()
# Create DLL
add_library(
${PROJECT_NAME}
SHARED
${SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/include/Version.h
${CMAKE_CURRENT_BINARY_DIR}/version.rc
.clang-format
.editorconfig
)
# CXX standard
target_compile_features(
${PROJECT_NAME}
PRIVATE
cxx_std_23
)
# Include directories
target_include_directories(
${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_include_directories(
${PROJECT_NAME}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
# Precompile header
target_precompile_headers(
${PROJECT_NAME}
PRIVATE
"include/PCH.h"
)
# Find and link dependencies
find_package(spdlog REQUIRED CONFIG)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
CommonLibSSE::CommonLibSSE
spdlog::spdlog
)
# Compile definitions
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: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
# Warning -> error
/we4715 # 'function' : not all control paths return a value
# Disable warnings
/wd4458 # declaration hides class member
/wd4100 # unreferenced formal parameter
/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>"
)
endif ()
target_compile_definitions(
"${PROJECT_NAME}"
PUBLIC
BOOST_STL_INTERFACES_DISABLE_CONCEPTS
WINVER=0x0601 # windows 7, minimum supported version by skyrim special edition
_WIN32_WINNT=0x0601
"$<$<BOOL:${SKSE_SUPPORT_XBYAK}>:SKSE_SUPPORT_XBYAK=1>"
)
# Function to copy build artifacts to the specified path
function(copy_build_artifacts TARGET_NAME)
if (DEFINED SKYRIM_DATA_PATH)
set(INSTALL_PATH "${SKYRIM_DATA_PATH}/SKSE/Plugins")
elseif (DEFINED MO_MODS_FOLDER_PATH)
set(INSTALL_PATH "${MO_MODS_FOLDER_PATH}/${TARGET_NAME}/SKSE/Plugins")
else ()
message(STATUS "No install path specified for mod ${TARGET_NAME}. Skipping post-build copy command.")
return()
endif()
# Create the directories if they don't exist
file(MAKE_DIRECTORY ${INSTALL_PATH})
message(STATUS "Using install path for ${TARGET_NAME}: ${INSTALL_PATH}")
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${TARGET_NAME}> ${INSTALL_PATH}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${TARGET_NAME}> ${INSTALL_PATH}
)
endfunction()
# Post build command
copy_build_artifacts(${PROJECT_NAME})