199 lines
6.9 KiB
CMake
199 lines
6.9 KiB
CMake
cmake_minimum_required(VERSION 3.21)
|
|
|
|
########################################################################################################################
|
|
## Define project
|
|
########################################################################################################################
|
|
|
|
# Get current version
|
|
set(ENDERAL_VERSION_INI "${CMAKE_CURRENT_SOURCE_DIR}/../../SKSE/Plugins/EnderalVersion.ini")
|
|
file(READ "${ENDERAL_VERSION_INI}" CONFIG_CONTENT)
|
|
string(REGEX MATCH "version[ \t]*=[ \t]*([0-9.]+)" _ ${CONFIG_CONTENT})
|
|
set(VERSION_NUMBER "${CMAKE_MATCH_1}")
|
|
|
|
# file(READ) does not register a dependency: without this, bumping the version in
|
|
# the INI would not re-run CMake and the DLL would keep the previous version.
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${ENDERAL_VERSION_INI}")
|
|
|
|
project(
|
|
EnderalSteam
|
|
VERSION ${VERSION_NUMBER}
|
|
DESCRIPTION "Enderal SE Steam Support"
|
|
LANGUAGES CXX
|
|
)
|
|
|
|
# Shown as ProductName in the version resource.
|
|
set(PROJECT_FRIENDLY_NAME "Enderal SE")
|
|
|
|
# The binary FILEVERSION/PRODUCTVERSION fields need all four components;
|
|
# PROJECT_VERSION_TWEAK is empty when the INI carries only three.
|
|
if(NOT PROJECT_VERSION_TWEAK)
|
|
set(PROJECT_VERSION_TWEAK 0)
|
|
endif()
|
|
|
|
set(CMAKE_CXX_STANDARD 23)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# Link-time optimization for release builds only (debug builds stay fast).
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
|
|
|
|
# CommonLibSSE-NG requires the dynamic CRT. Dependencies used to be supplied by
|
|
# vcpkg (which set this via a preset); now that they come from FetchContent we
|
|
# set it here so both build.cmd and Visual Studio "Open Folder" pick it up.
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
|
|
|
add_compile_definitions(NOMINMAX _USE_MATH_DEFINES WIN32_LEAN_AND_MEAN)
|
|
add_definitions(-DUNICODE -D_UNICODE)
|
|
add_compile_options(/Zc:preprocessor /EHsc)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
configure_file(
|
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in
|
|
${CMAKE_CURRENT_BINARY_DIR}/version.rc
|
|
@ONLY
|
|
)
|
|
|
|
file(
|
|
GLOB_RECURSE
|
|
sources
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
|
|
${CMAKE_CURRENT_BINARY_DIR}/version.rc
|
|
)
|
|
|
|
source_group(
|
|
TREE ${CMAKE_CURRENT_SOURCE_DIR}
|
|
FILES
|
|
${headers}
|
|
${sources}
|
|
)
|
|
|
|
########################################################################################################################
|
|
## Fetch dependencies (pinned versions, no vcpkg required)
|
|
########################################################################################################################
|
|
|
|
include(FetchContent)
|
|
|
|
# DirectXMath - required by DirectXTK.
|
|
FetchContent_Declare(
|
|
DirectXMath
|
|
URL "https://github.com/microsoft/DirectXMath/archive/refs/tags/apr2025.tar.gz"
|
|
OVERRIDE_FIND_PACKAGE
|
|
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
|
EXCLUDE_FROM_ALL
|
|
SYSTEM
|
|
)
|
|
FetchContent_MakeAvailable(DirectXMath)
|
|
add_library("Microsoft::DirectXMath" ALIAS "DirectXMath")
|
|
|
|
# DirectXTK - required by CommonLibSSE-NG (find_package(directxtk CONFIG REQUIRED)).
|
|
# PATCH_COMMAND fixes its shader-compile step under modern CMake (see the script).
|
|
FetchContent_Declare(
|
|
DirectXTK
|
|
URL "https://github.com/microsoft/DirectXTK/archive/refs/tags/jul2025.tar.gz"
|
|
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
|
OVERRIDE_FIND_PACKAGE
|
|
EXCLUDE_FROM_ALL
|
|
SYSTEM
|
|
PATCH_COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/patch_directxtk.cmake"
|
|
)
|
|
FetchContent_MakeAvailable(DirectXTK)
|
|
add_library("Microsoft::DirectXTK" ALIAS "DirectXTK")
|
|
|
|
# simpleini - used directly (Util.h).
|
|
FetchContent_Declare(
|
|
simpleini
|
|
URL "https://github.com/brofield/simpleini/archive/refs/tags/v4.25.tar.gz"
|
|
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
|
)
|
|
FetchContent_MakeAvailable(simpleini)
|
|
INCLUDE_DIRECTORIES(${simpleini_SOURCE_DIR})
|
|
|
|
# rapidcsv - header only, required by CommonLibSSE-NG (find_path "rapidcsv.h").
|
|
FetchContent_Declare(
|
|
rapidcsv
|
|
URL "https://github.com/d99kris/rapidcsv/archive/refs/tags/v8.90.tar.gz"
|
|
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
|
OVERRIDE_FIND_PACKAGE
|
|
)
|
|
FetchContent_MakeAvailable(rapidcsv)
|
|
set(RAPIDCSV_INCLUDE_DIRS ${rapidcsv_SOURCE_DIR}/src)
|
|
|
|
# spdlog - used directly (PCH.h) and by CommonLibSSE-NG.
|
|
set(SPDLOG_INSTALL ON CACHE BOOL " " FORCE)
|
|
set(SPDLOG_USE_STD_FORMAT ON CACHE BOOL " " FORCE)
|
|
FetchContent_Declare(
|
|
spdlog
|
|
URL "https://github.com/gabime/spdlog/archive/refs/tags/v1.17.0.tar.gz"
|
|
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
|
OVERRIDE_FIND_PACKAGE
|
|
)
|
|
FetchContent_MakeAvailable(spdlog)
|
|
|
|
# CommonLibSSE-NG - pinned commit (SE + AE + VR runtime support).
|
|
# No engine patches here, so xbyak trampoline support stays off (FORCE flips
|
|
# the stale ON left in caches configured before xbyak was dropped).
|
|
set(SKSE_SUPPORT_XBYAK OFF CACHE BOOL " " FORCE)
|
|
set(ENABLE_SKYRIM_SE ON CACHE BOOL " " FORCE)
|
|
set(ENABLE_SKYRIM_AE ON CACHE BOOL " " FORCE)
|
|
set(ENABLE_SKYRIM_VR ON CACHE BOOL " " FORCE)
|
|
set(BUILD_TESTS OFF CACHE BOOL " " FORCE)
|
|
message(STATUS "Fetching CommonLibSSE-NG...")
|
|
FetchContent_Declare(
|
|
CommonLibSSE
|
|
GIT_REPOSITORY https://github.com/alandtse/CommonLibVR
|
|
GIT_TAG aacbd76c01bff9381e253ffdfcb4f9d5f263f1df
|
|
)
|
|
FetchContent_MakeAvailable(CommonLibSSE)
|
|
|
|
get_target_property(COMMONLIB_SRC_DIR CommonLibSSE SOURCE_DIR)
|
|
|
|
include(${COMMONLIB_SRC_DIR}/cmake/CommonLibSSE.cmake)
|
|
|
|
########################################################################################################################
|
|
## Configure target DLL
|
|
########################################################################################################################
|
|
|
|
add_commonlibsse_plugin(${PROJECT_NAME} SOURCES ${headers} ${sources})
|
|
|
|
add_library("${PROJECT_NAME}::${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")
|
|
|
|
# Steamworks SDK import library, shipped in src/ next to the steam/ headers.
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/steam_api64.lib)
|
|
|
|
target_link_libraries(CommonLibSSE PUBLIC
|
|
DirectXTK
|
|
)
|
|
|
|
target_link_libraries(${PROJECT_NAME} PUBLIC
|
|
CommonLibSSE::CommonLibSSE
|
|
spdlog Version.lib
|
|
)
|
|
|
|
target_include_directories(${PROJECT_NAME}
|
|
PRIVATE
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
|
|
$<INSTALL_INTERFACE:src>
|
|
)
|
|
|
|
target_include_directories(${PROJECT_NAME}
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
)
|
|
|
|
target_precompile_headers(${PROJECT_NAME}
|
|
PRIVATE
|
|
src/PCH.h
|
|
)
|
|
|
|
install(TARGETS ${PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
########################################################################################################################
|
|
## Automatic plugin deployment
|
|
########################################################################################################################
|
|
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/../../SKSE/Plugins/")
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> "${CMAKE_CURRENT_SOURCE_DIR}/../../SKSE/Plugins/")
|