generated from ponzipyramid/CommonLibSSE-NG-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
110 lines (98 loc) · 4.56 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
cmake_minimum_required(VERSION 3.21)
project(
TK_Dodge_RE
VERSION 1.1.0
LANGUAGES CXX
)
set(FORMATTED_NAME "TK Dodge NG")
set(LICENSE "MIT License")
set(AUTHOR "itahol")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# ########################################################################################################################
# ## Build options
# ########################################################################################################################
message("Options:")
option(AUTO_PLUGIN_DEPLOYMENT "Copy the build output and addons to env:${PROJECT_NAME}_OutputDir." OFF)
option(ZIP_TO_DIST "Zip the base mod and addons to their own 7z file in dist." ON)
option(AIO_ZIP_TO_DIST "Zip the base mod and addons to a AIO 7z file in dist." OFF)
message("\tAuto plugin deployment: ${AUTO_PLUGIN_DEPLOYMENT}")
message("\tZip to dist: ${ZIP_TO_DIST}")
message("\tAIO Zip to dist: ${AIO_ZIP_TO_DIST}")
# #######################################################################################################################
# # Add CMake features
# #######################################################################################################################
include(XSEPlugin)
# #######################################################################################################################
# # Find dependencies
# #######################################################################################################################
find_package(magic_enum CONFIG REQUIRED)
find_package(xbyak CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_path(CLIB_UTIL_INCLUDE_DIRS "ClibUtil/utils.hpp")
add_subdirectory("extern/DKUtil" DKUtil EXCLUDE_FROM_ALL)
target_include_directories(
${PROJECT_NAME}
PRIVATE
${CLIB_UTIL_INCLUDE_DIRS}
)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
magic_enum::magic_enum
xbyak::xbyak
nlohmann_json::nlohmann_json
DKUtil::DKUtil
)
# 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()
if(ZIP_TO_DIST)
message("Making a zip for distribution")
set(CPACK_GENERATOR "7Z") # Use the 7z generator
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}") # Set the name of the generated package
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF) # Do not include top-level directory in the package
install(FILES "$<TARGET_FILE:${PROJECT_NAME}>" DESTINATION "SKSE/Plugins")
install(FILES "$<TARGET_PDB_FILE:${PROJECT_NAME}> " DESTINATION "SKSE/Plugins")
install(FILES "${CMAKE_SOURCE_DIR}/TK Dodge RE.ini" DESTINATION "SKSE/Plugins")
include(CPack)
# Run CPack after the build
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Packaging for distribution..."
COMMAND ${CMAKE_COMMAND} -E echo "CPack configuration: ${CPACK_GENERATOR}"
COMMAND cpack --config ${CMAKE_BINARY_DIR}/CPackConfig.cmake
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Packaging for distribution..."
)
endif()
# #######################################################################################################################
# # Automatic deployment
# #######################################################################################################################
if(AUTO_PLUGIN_DEPLOYMENT)
foreach(DEPLOY_TARGET $ENV{${PROJECT_NAME}_OutputDir})
message("Copying AIO to ${DEPLOY_TARGET}")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> "${DEPLOY_TARGET}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> "${DEPLOY_TARGET}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/TK Dodge RE.ini" "${DEPLOY_TARGET}/SKSE/Plugins/"
)
endforeach()
if(NOT DEFINED ENV{${PROJECT_NAME}_OutputDir})
message("When using AUTO_PLUGIN_DEPLOYMENT option, you need to set environment variable '${PROJECT_NAME}_OutputDir'")
endif()
endif()