Hi,
I am using the Visual Studio plugin, and I noticed that using the ‘api’ linkage infers the need to generate a NativeLibrarySpec
's shared library VS project files even if the shared library binary is not buildable. Below is an example project where all shared libraries are not buildable, but lib2’s Dll project files are still generated because lib1 uses lib2 with ‘api’ linkage.
Is this the expected behavior?
I suppose I would expect this if all binaries are buildable and the linkage is still ‘api’. However, if a binary is specifically made non-buildable, I would think the Visual Studio plugin would not generate the project files for the binary.
I have no intention of linking one library into another, so I thought this was the correct usage of the ‘api’ linkage. Is my thinking correct?
Any clarity into these matters would help greatly my own understanding of how Gradle works with native projects and its software model. Thanks!
apply plugin: 'cpp'
apply plugin: 'visual-studio'
model {
visualStudio {
solutions.all {
solutionFile.location = "vs/${name}.sln"
}
projects.all {
projectFile.location = "vs/projects/${name}.vcxproj"
filtersFile.location = "vs/projects/${name}.vcxproj.filters"
}
}
components {
exe(NativeExecutableSpec) {
sources {
cpp {
// change linkage to 'shared' and only respective lib1/lib2 project files are generated
lib library: 'lib1', linkage: 'static'
lib library: 'lib2', linkage: 'static'
}
}
}
lib1(NativeLibrarySpec) {
sources {
cpp {
// change linkage to 'static' or 'shared' and only respective lib2 project files are generated
lib library: 'lib2', linkage: 'api'
}
}
}
lib2(NativeLibrarySpec)
}
binaries {
withType(SharedLibraryBinarySpec) {
buildable = false // no shared libraries desired
}
}
}
tasks {
task deleteVisualStudioDirectory(type: Delete) {
delete file('vs/')
}
clean {
dependsOn deleteVisualStudioDirectory
}
}
Here are the VS project files that are created:
$ tree vs
vs
├── exeExe.sln
└── projects
├── exeExe.vcxproj
├── exeExe.vcxproj.filters
├── lib1Lib.vcxproj
├── lib1Lib.vcxproj.filters
├── lib2Dll.vcxproj
├── lib2Dll.vcxproj.filters
├── lib2Lib.vcxproj
└── lib2Lib.vcxproj.filters