diff --git a/source/Enderal DLL/.gitignore b/source/Enderal DLL/.gitignore index fddaf08be..913d85041 100644 --- a/source/Enderal DLL/.gitignore +++ b/source/Enderal DLL/.gitignore @@ -534,6 +534,9 @@ FodyWeavers.xsd build/ +# Machine-specific, generated by build.cmd - see cmake/write_user_presets.cmake +CMakeUserPresets.json + contrib/Distribution/**/*.dll contrib/Distribution/**/*.pdb contrib/Distribution/**/*.pex diff --git a/source/Enderal DLL/CMakeLists.txt b/source/Enderal DLL/CMakeLists.txt index c6919f1b4..94c1671c8 100644 --- a/source/Enderal DLL/CMakeLists.txt +++ b/source/Enderal DLL/CMakeLists.txt @@ -1,37 +1,57 @@ -option(ENABLE_VCPKG OFF) cmake_minimum_required(VERSION 3.21) -message("Using toolchain file ${CMAKE_TOOLCHAIN_FILE}.") - -# Get current version -file(READ "${CMAKE_SOURCE_DIR}/../../SKSE/Plugins/EnderalVersion.ini" CONFIG_CONTENT) -string(REGEX MATCH "version[ \t]*=[ \t]*([0-9.]+)" _ ${CONFIG_CONTENT}) -set(VERSION_NUMBER "${CMAKE_MATCH_1}") ######################################################################################################################## ## 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( EnderalSE VERSION ${VERSION_NUMBER} DESCRIPTION "Enderal SE DLL" 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) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION 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$<$: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 ) -#include(GNUInstallDirs) - file( GLOB_RECURSE sources @@ -47,75 +67,76 @@ source_group( ) ######################################################################################################################## -## Configure target DLL +## Fetch dependencies (pinned versions, no vcpkg required) ######################################################################################################################## - include(FetchContent) -# DirectXMath +# 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 1 + DOWNLOAD_EXTRACT_TIMESTAMP ON EXCLUDE_FROM_ALL SYSTEM ) FetchContent_MakeAvailable(DirectXMath) add_library("Microsoft::DirectXMath" ALIAS "DirectXMath") -# DirectXTK +# 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 1 + DOWNLOAD_EXTRACT_TIMESTAMP ON 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 +# simpleini - used directly (Util.h). FetchContent_Declare( simpleini URL "https://github.com/brofield/simpleini/archive/refs/tags/v4.25.tar.gz" - DOWNLOAD_EXTRACT_TIMESTAMP 1 + DOWNLOAD_EXTRACT_TIMESTAMP ON ) FetchContent_MakeAvailable(simpleini) INCLUDE_DIRECTORIES(${simpleini_SOURCE_DIR}) -# rapidcsv +# 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 1 + DOWNLOAD_EXTRACT_TIMESTAMP ON OVERRIDE_FIND_PACKAGE ) FetchContent_MakeAvailable(rapidcsv) set(RAPIDCSV_INCLUDE_DIRS ${rapidcsv_SOURCE_DIR}/src) -# spdlog +# 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 1 + DOWNLOAD_EXTRACT_TIMESTAMP ON OVERRIDE_FIND_PACKAGE ) FetchContent_MakeAvailable(spdlog) -# xbyak +# xbyak - JIT assembly used by the engine patches. FetchContent_Declare( xbyak URL "https://github.com/herumi/xbyak/archive/v7.30.tar.gz" - DOWNLOAD_EXTRACT_TIMESTAMP 1 + DOWNLOAD_EXTRACT_TIMESTAMP ON ) FetchContent_MakeAvailable(xbyak) -# CommonLibSSE +# CommonLibSSE-NG - pinned commit (SE + AE + VR runtime support). set(SKSE_SUPPORT_XBYAK ON CACHE BOOL " " FORCE) set(ENABLE_SKYRIM_SE ON CACHE BOOL " " FORCE) set(ENABLE_SKYRIM_AE ON CACHE BOOL " " FORCE) @@ -129,11 +150,14 @@ FetchContent_Declare( ) 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}") @@ -160,7 +184,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC $ ) - + target_precompile_headers(${PROJECT_NAME} PRIVATE src/PCH.h @@ -168,7 +192,6 @@ target_precompile_headers(${PROJECT_NAME} install(TARGETS ${PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_LIBDIR}") - ######################################################################################################################## ## Automatic plugin deployment ######################################################################################################################## @@ -177,4 +200,3 @@ 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 $ "${CMAKE_CURRENT_SOURCE_DIR}/../../SKSE/Plugins/") - \ No newline at end of file diff --git a/source/Enderal DLL/CMakePresets.json b/source/Enderal DLL/CMakePresets.json index 566eb6bb2..bb4bbee12 100644 --- a/source/Enderal DLL/CMakePresets.json +++ b/source/Enderal DLL/CMakePresets.json @@ -13,17 +13,6 @@ "CMAKE_CXX_FLAGS": "$env{COMMONLIBSSE_COMPILER} $env{COMMONLIBSSE_PLATFORM} $env{COMMONLIBSSE_TEXT}" } }, - { - "name": "vcpkg", - "hidden": true, - "cacheVariables": { - "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", - "VCPKG_TARGET_TRIPLET": "x64-windows-skse", - "VCPKG_HOST_TRIPLET": "x64-windows-skse", - "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake", - "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$:Debug>DLL" - } - }, { "name": "win32", "hidden": true, @@ -79,100 +68,68 @@ } } }, - { - "name": "build-tests", - "displayName": "Build Tests", - "hidden": true, - "description": "Include test suites in the build.", - "cacheVariables": { - "BUILD_TESTS": { - "type": "STRING", - "value": "ON" - } - } - }, { "name": "build-release-msvc", "inherits": [ "base", - "vcpkg", "win32-unicode", "x64", - "build-tests", "msvc" ], - "displayName": "Release", + "displayName": "Release (MSVC)", "description": "Optimized release build.", "generator": "Ninja", "binaryDir": "${sourceDir}/build/release-msvc", "cacheVariables": { - "CMAKE_BUILD_TYPE": { - "type": "STRING", - "value": "Release" - } + "CMAKE_BUILD_TYPE": "Release" } }, { "name": "build-debug-msvc", "inherits": [ "base", - "vcpkg", "win32-unicode", "x64", - "build-tests", "msvc" ], - "displayName": "Debug", + "displayName": "Debug (MSVC)", "description": "Debug build for testing.", "generator": "Ninja", "binaryDir": "${sourceDir}/build/debug-msvc", "cacheVariables": { - "CMAKE_BUILD_TYPE": { - "type": "STRING", - "value": "Debug" - } - } - }, - { - "name": "build-debug-clang-cl", - "inherits": [ - "base", - "vcpkg", - "win32-unicode", - "x64", - "build-tests", - "clang-cl" - ], - "displayName": "Debug", - "description": "Debug build for testing.", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/debug-clang", - "cacheVariables": { - "CMAKE_BUILD_TYPE": { - "type": "STRING", - "value": "Debug" - } + "CMAKE_BUILD_TYPE": "Debug" } }, { "name": "build-release-clang-cl", "inherits": [ "base", - "vcpkg", "win32-unicode", "x64", - "build-tests", "clang-cl" ], - "displayName": "Release", + "displayName": "Release (Clang)", "description": "Optimized release build.", "generator": "Ninja", "binaryDir": "${sourceDir}/build/release-clang", "cacheVariables": { - "CMAKE_BUILD_TYPE": { - "type": "STRING", - "value": "Release" - } + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "build-debug-clang-cl", + "inherits": [ + "base", + "win32-unicode", + "x64", + "clang-cl" + ], + "displayName": "Debug (Clang)", + "description": "Debug build for testing.", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/debug-clang", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" } } ], @@ -201,52 +158,5 @@ "configurePreset": "build-debug-clang-cl", "description": "Debug build for testing." } - ], - "testPresets": [ - { - "name": "tests-all", - "displayName": "All Tests", - "configurePreset": "build-debug-msvc", - "output": { - "outputOnFailure": true - }, - "execution": { - "noTestsAction": "error", - "stopOnFailure": false - } - }, - { - "name": "tests-unit", - "displayName": "Unit Tests", - "description": "Runs tests that do not require any Skyrim module loaded into the process.", - "inherits": "tests-all", - "filter": { - "exclude": { - "label": "[integration],[e2e]" - } - } - }, - { - "name": "tests-integration", - "displayName": "Integration Tests", - "description": "Runs tests that interact with a Skyrim module at rest (do not require the Skyrim module to have run any main function).", - "inherits": "tests-all", - "filter": { - "include": { - "label": "[integration]" - } - } - }, - { - "name": "tests-e2e", - "displayName": "End-to-End Tests", - "description": "Runs test that depend on a fully running Skyrim engine in the process.", - "inherits": "tests-all", - "filter": { - "include": { - "label": "[e2e]" - } - } - } ] } diff --git a/source/Enderal DLL/build.cmd b/source/Enderal DLL/build.cmd index 240df5a20..57d0082c4 100644 --- a/source/Enderal DLL/build.cmd +++ b/source/Enderal DLL/build.cmd @@ -35,6 +35,10 @@ if not defined VSINSTALL ( rem --- Import the MSVC x64 developer environment --- call "%VSINSTALL%\VC\Auxiliary\Build\vcvars64.bat" || exit /b 1 +rem --- Point Visual Studio at this same CMake, so the two drivers can share the +rem build tree incrementally (see cmake\write_user_presets.cmake) --- +cmake -P cmake\write_user_presets.cmake || exit /b 1 + rem --- Configure and build using the shared presets --- cmake --preset %CONFIGURE_PRESET% || exit /b 1 cmake --build --preset %PRESET% || exit /b 1 diff --git a/source/Enderal DLL/cmake/patch_directxtk.cmake b/source/Enderal DLL/cmake/patch_directxtk.cmake new file mode 100644 index 000000000..ab00b79a5 --- /dev/null +++ b/source/Enderal DLL/cmake/patch_directxtk.cmake @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:49e65631d5c750bd9711048c94ce39805140809ecc3835bcc5ae80230d11d1fe +size 1238 diff --git a/source/Enderal DLL/cmake/version.rc.in b/source/Enderal DLL/cmake/version.rc.in index 775f8176a..ad6c422e8 100644 --- a/source/Enderal DLL/cmake/version.rc.in +++ b/source/Enderal DLL/cmake/version.rc.in @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f3f8d8b4de30101444236e0ff255c2504e734454596f273e0b496aff080b5abd -size 931 +oid sha256:6f6acb5569bec4deb6de6f5b513a0d910b72d73d7b0ba3665718128008dadc0c +size 965 diff --git a/source/Enderal DLL/cmake/write_user_presets.cmake b/source/Enderal DLL/cmake/write_user_presets.cmake new file mode 100644 index 000000000..619c18dbd --- /dev/null +++ b/source/Enderal DLL/cmake/write_user_presets.cmake @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f5bb2e02efa9c61ae468c21aa10d28a2780c65c1bf0642bbdf829b9d9b38901 +size 4382 diff --git a/source/Enderal DLL/cmake/x64-windows-skse.cmake b/source/Enderal DLL/cmake/x64-windows-skse.cmake deleted file mode 100644 index 4eedaa8f3..000000000 --- a/source/Enderal DLL/cmake/x64-windows-skse.cmake +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:a16e5b30471c2f50b6fe6bae55f973efa2768d5871966ae4ee51c5339873ef42 -size 227