Skip to content
John Stewart edited this page Jul 27, 2022 · 3 revisions

stability-stable

CommonLibSSE NG simplifies creation of plugins by integrating with CMake, allowing you to avoid code that repeats yourself to make a plugin that is detected by SKSE.

Defining a Plugin with CMake

from-3.4.0

A useful way to both simplify your project, make it more maintainable, but also ensure your plugin is detected properly across multiple runtimes, is to use CMake to define your plugin metadata. You can do this by replacing add_library with add_commonlibsse_plugin in CMakeLists.txt.

find_package(CommonLibSSE CONFIG REQUIRED)

add_commonlibsse_plugin(${PROJECT_NAME} SOURCES ${headers} ${sources})

This will automatically generate SKSEPlugin_Version and SKSEPlugin_Query and use your CMake project and target information to fill in the plugin name and version metadata. It will also default to declaring its compatibility mode is using Address Library. All of this can be overridden.

add_commonlibsse_plugin(<target>
    # The plugin's name, defaults to target.
    NAME <string>

    # The plugin's author, empty by default.
    AUTHOR <string>

    # The support email address, empty by default.
    EMAIL <string>

    # The plugin version number, defaults to ${PROJECT_VERSION}.
    VERSION <version number>

    # Indicates the plugin is compatible with all runtimes via address library. This is the default if no
    # other compatibilility mode is specified. Can be used with USE_SIGNATURE_SCANNING but not
    # COMPATIBLE_RUNTIMES.
    USE_ADDRESS_LIBRARY

    # Indicates the plugin is compatible with all runtimes via signature scanning.  Can be used with
    # USE_ADDRESS_LIBRARY but not COMPATIBLE_RUNTIMES.
    USE_SIGNATURE_SCANNING

    # List of up to 16 Skyrim versions the plugin is compatible with. Cannot be used with
    # USE_ADDRESS_LIBRARY or USE_SIGNATURE_SCANNING.
    COMPATIBLE_RUNTIMES <version number> [<version number>...]

    # The minimum SKSE version to support; defaults to 0, and recommended by SKSE project to be left
    # 0.
    MINIMUM_SKSE_VERSION <version number>

    # Omit from all targets, same as used with add_library.
    EXCLUDE_FROM_ALL

    # List of the sources to include in the target, as would be the parameters to add_library.
    SOURCES <path> [<path> ...]
)

When using this method, you can remove your use of SKSEPlugin_Version, SKSEPlugin_Query, and/or SKSEPluginInfo from your source code. You also no longer need to link CommonLibSSE::CommonLibSSE for that CMake target, as the CMake function configures that for you. It will also add CommonLibSSE headers to your include paths.

This method also obsoletes the common use of a plugin information header that is configured by CMake to inject the project name and version into C++. If you are using a Plugin.h.in or PluginInfo.h.in file to inject that information, you can now access that information through SKSE::PluginDeclaration::GetSingleton().

auto* plugin = SKSE::PluginDeclaration::GetSingleton();
auto name = plugin->GetName();
auto version = plugin->GetVersion();

Adding SKSE Properties to Existing Targets

from-4.0.0

To add SKSE plugin data to an existing target, you can call target_commonlibsse_properties.

add_library(MyPlugin SHARED Main.cpp)

target_commonlibsse_properties(MyPlugin)

This will have the same effect as using add_commonlibsse_plugin but using existing targets. The EXCLUDE_FROM_ALL and SOURCES arguments are not supported for this function since those should be provided to add_library. The full command syntax is as follows:

target_commonlibsse_properties(<target>
    # The plugin's name, defaults to target.
    NAME <string>

    # The plugin's author, empty by default.
    AUTHOR <string>

    # The support email address, empty by default.
    EMAIL <string>

    # The plugin version number, defaults to ${PROJECT_VERSION}.
    VERSION <version number>

    # Indicates the plugin is compatible with all runtimes via address library. This is the default if no
    # other compatibilility mode is specified. Can be used with USE_SIGNATURE_SCANNING but not
    # COMPATIBLE_RUNTIMES.
    USE_ADDRESS_LIBRARY

    # Indicates the plugin is compatible with all runtimes via signature scanning.  Can be used with
    # USE_ADDRESS_LIBRARY but not COMPATIBLE_RUNTIMES.
    USE_SIGNATURE_SCANNING

    # List of up to 16 Skyrim versions the plugin is compatible with. Cannot be used with
    # USE_ADDRESS_LIBRARY or USE_SIGNATURE_SCANNING.
    COMPATIBLE_RUNTIMES <version number> [<version number>...]

    # The minimum SKSE version to support; defaults to 0, and recommended by SKSE project to be left
    # 0.
    MINIMUM_SKSE_VERSION <version number>
)