Native binary cpp: add linker args in prebuilt library section

I’m trying to add the boost library to my repositories as a prebuilt library and don’t want to make one prebuilt library for each of the boost sub-libs that come with a static lib. Since the boost sub-libs that come with a static lib know how to link theirs libs (via pre-processor #pragmas) my idea was to just add LIBPATH pointing to these static libs to the linker args like this:

repositories {
    libs(PrebuiltLibraries) {
        boost {
            headers.srcDir "src/3rdParty/boost_1_57_0/boost"
            binaries.all {
                def arch = (targetPlatform == platforms.x86) ? "Win32" : "x64";
                def type = (buildType == buildTypes.debug) ? "Debug" : "Release";
                linker.args << "/LIBPATH:src/3rdParty/boost_1_57_0/Lib/${arch}_${type}"
            }
        }
...

This doesn’t work, because I can’t access linker from this scope. Is there another way to solve this?

What’s your reason for not wanting to create separate prebuilt library instances? The usual way to do this would be to iterate over the libraries on disk and configure a prebuilt library for each.

Because normally (when not using Gradle but Visual Studio) I don’t have to. All I need to do is tell the compiler where the boost headers are, and the linker where the libs are. Not each lib individually, just the directory where all lib files are stored. Then when I include e.g. boost/thread.hpp, the linker will automatically be told to link the corresponding lib file. I thought I could replicate that with Gradle.

That sounds interesting. Can you point me to an example? I’m new to Gradle and don’t know the usual tricks.

I don’t have an example on hand, but if you know a bit of Groovy you can iterate over the directories or files, and configure a prebuilt library for each with the normal syntax.

Completely untested code:::

repositories {
    libs(PrebuiltLibraries) { prebuilt ->
        file('boost').listFiles().each { subDir ->
            prebuilt."boost-${subDir.name}" {
                headers.srcDir "${subDir.absolutePath}/headers"
                ...
            }
        }