Cpp-application - How to link a static lib

I’m trying to make a plugin to include the headers and static libraries of the vulkan sdk. The examples in the gradle native samples repository showed me how to add the header files to the build programmatically. Now I’m trying to add a static library to add the vulkan static library to the build, and for the life of me I cannot figure it out.

The sample here shows code specific to groovy that I’m trying to translate to a kotlin plugin to add a library. What I’ve tried is this:

val sdkPath = System.getenv("VULKAN_SDK")
    ?: throw PluginNotSupportedException("This plugin requires that the vulkan sdk be installed on this machine.")

val vulkanHeaderPath = Paths.get(sdkPath).resolve("./Include/vulkan").normalize()
val vulkanLibPath = Paths.get(sdkPath).resolve("./Lib/vulkan-1.lib").normalize()

val application = project.properties["application"] as CppApplication

// this works
if (!application.privateHeaderDirs.contains(vulkanHeaderPath)) {
    application.privateHeaders { from(vulkanHeaderPath) }
}

// this does NOT work
application.binaries.whenElementFinalized {
    val binary = this
    project.dependencies {
        // the sample shows binary.linkLibraries.name which doesn't exist (?)
        // not sure if it's a groovy only thing or something like that
        add(binary.linkLibraries.singleFile.toString(), files(vulkanLibPath))
    }
}

When I try this the error I get is:

Expected configuration ‘:nativeLinkDebug’ to contain exactly one file, however, it contains no files.

What is the correct programmatic way to link a static library to the executable?

To anybody else looking at how to add libraries programattically, the way I found that works for the visualcpp toolchain is this;

val linkTasks = project.tasks.withType<LinkExecutable>()
linkTasks.forEach {
    if (!it.libs.contains(vulkanLibPath)) {
        it.libs.from(vulkanLibPath)
    }
}

…where vulkanLibPathw as the path directly to a single library and not a directory.

The LinkExecutable task appears to be that task ran after compiling that links all of the object files together. I’m not sure what part of the model normally sets this, but updating the task manually after project evaluation works fine.