Official CMake modules for Skyrim Scripting tutorials
-
add_skse_plugin
automatically sets up precompile headers (includes its ownPCH.h
) -
add_skse_plugin
can automatically deploy to your MO2/Vortex mods folder -
add_skse_plugin
can automatically deploy to your SkyrimData/
folder - Support for Papyrus scripts
- Support for
.esp
/.bsa
files or other assets - Support for packaging mod for release
I actually enjoy CMake.
But, when your goal is: Create a fun Skyrim SKSE plugin
then you should not also be forced to learn this wicked language.
The SkyrimScripting.CMake
module provides CMake
functions which make it easy to ignore CMake and just write Skyrim plugins!
The easiest way to get started is by using this template:
https://github.com/SkyrimScripting/SKSE_Template_StarterKit
- Set an environment variable to configure where generated SKSE plugins are output:
CMAKE_SKYRIM_MODS_FOLDER
: set to your MO2 or Vortex mods folder
orCMAKE_SKYRIM_FOLDER
: plugin will output to yourData\
directory
- Clone that repository (or download as a .zip file)
- Open the folder in any C++ editor program (e.g. CLion, Visual Studio, VS Code)
- Choose other the
Debug
orRelease
build, if prompted (CLion/VS Code) - Build the project!
SKSE plugin automatically copied into your mods or Data folder, per config above
- Enable the mod (if using a mod manager) and run Skyrim 🐉
In your own projects, add SkyrimScripting.CMake
by adding the following 2x files to the root of your project:
View Content
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"name": "my-project",
"version-string": "0.0.1",
"dependencies": [
"commonlibsse-ng",
{ "name": "skyrimscripting-cmake", "version>=": "0.0.1" }
]
}
Please always specify an explicit
version<=
(view content for example).
Development ofSkyrimScripting.CMake
is currently active and the interface/functions will change.
View Content
{
"default-registry": {
"kind": "git",
"repository": "https://github.com/microsoft/vcpkg.git",
"baseline": "cc288af760054fa489574bd8e22d05aa8fa01e5c"
},
"registries": [
{
"kind": "git",
"repository": "https://gitlab.com/colorglass/vcpkg-colorglass",
"baseline": "ef8d43afe4d26e842de3d034bff1081cb7990f07",
"packages": [
"commonlibsse-ng"
]
},
{
"kind": "git",
"repository": "https://github.com/SkyrimScripting/vcpkg.git",
"baseline": "< INSERT THE LATEST COMMIT SHA >",
"packages": [
"skyrimscripting-cmake"
]
}
]
}
And make sure that your project is configured to use vcpkg
!
e.g. via setting your
CMAKE_TOOLCHAIN_FILE
to$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
.
If you want, you can add this CMakePresets.json
into the root of your project (if you don't already have your own preferred CMakePresets.json
)
View Content
{
"version": 3,
"configurePresets": [
{
"name": "base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"installDir": "${sourceDir}/install/${presetName}",
"architecture": { "value": "x64", "strategy": "external" },
"cacheVariables": {
"CMAKE_CXX_COMPILER": "cl.exe",
"CMAKE_CXX_FLAGS": "/permissive- /Zc:preprocessor /EHsc /MP /W4 -DWIN32_LEAN_AND_MEAN -DNOMINMAX -DUNICODE -D_UNICODE",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md",
"VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake",
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "debug",
"inherits": ["base"],
"displayName": "Debug",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
},
{
"name": "release",
"inherits": ["base"],
"displayName": "Release",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
}
]
}
Example CMakeLists.txt
:
cmake_minimum_required(VERSION 3.21)
project(MyCoolSksePlugin VERSION 0.0.1 LANGUAGES CXX)
find_package(SkyrimScripting.CMake CONFIG REQUIRED)
add_skse_plugin(${PROJECT_NAME} SOURCES plugin.cpp)
That's it.
If you configured either CMAKE_SKYRIM_MODS_FOLDER
or CMAKE_SKYRIM_FOLDER
as described above, then just build the project and your SKSE plugin will go into your MO2/Vortex mods folder (or directly into your Data/
folder).
Alternatively, you can specify these locations manually:
# Provide a path to your mods folder
add_skse_plugin(
${PROJECT_NAME}
MODS_FOLDER "C:/path/to/my/mods/folder"
SOURCES plugin.cpp
)
# Provide a path to your Data/ folder
add_skse_plugin(
${PROJECT_NAME}
DATA_FOLDER "C:/Program Files (x86)/Steam/steamapps/common/Skyrim Special Edition/Data"
SOURCES plugin.cpp
)
That's all I'm going to share for now.
The usage will change over time, so let's keep it simple for now.
There will be a Skyrim Scripting video covering CMake in detail in the future.