[CPP] Conditional Linking and Excluding

Since I found Gradle’s DSL to be comprehensible,
I decided to use it instead of CMake. I was able to build somefiles within Gradle but need help.

My project structure looks like this:

Noir/
    build.gradle
    settings.gradle
    engine/
        build.gradle
        Noir/
            headers
            cpp
        Noir.Graphics/
        Noir.Sound/
    editor/
        Nothing yet

My Noir.Graphics component, does require certain libraries to be linked.
For windows I need “User32.dll”, “OpenGL32.dll” to be linked,
on linux I need X11 and MesaGLDev (I currently don’t now the libraries name).

My sound Component will need certain libraries too.

On the other hand, I’ll need to exclude certain files, which are used in conjunction with the PIMPL-Pattern (also known as Bridge-Pattern). These files are merely implementations for every platform.

How can this be achieved the Gradle DSL, since I am fairly new to it?
That’s my current gradle file:

apply plugin: 'cpp'

model{
    components{
        Noir(SharedLibraryBinarySpec)
        Noir.Graphics(SharedLibraryBinarySpec)
        Noir.Sound(SharedLibraryBinarySpec)
    }
}

P.S.:
Who ever came up with the idea having two folders (headers, cpp), I admire it.

For libraries/dependencies that Gradle doesn’t build, your two main options are to model them as prebuilt libraries: https://github.com/gradle/gradle/tree/master/subprojects/docs/src/samples/native-binaries/prebuilt

or to add the arguments required to use them by hand for now (this makes the most sense for system libraries). i.e., You’d depend on the environment having the correct search paths and you’d say:

binaries.all {
   linker.args '-lopengl32'
}

WRT having separate platform specific implementations of things, you’d do something like this:

You basically selectively add new source sets based on the variant being built.

HTH

Thanks for your answer.
Currently I am using the second approach since I have troubles understanding
how to configure prebuildt libraries.

I have adapted my buildfile a bit and fixed some errors, which came from my lack of knowledge of gradle’s DSL.
Will there be an official tutorial?
The tutorials presented on the “Cpp Build Operator” Page are deprecated and the Gradle Docs are kind off unclear (still, in comparison to CMake I got something to build :stuck_out_tongue: ).

Yes, breaking up and improving the documentation is one of the things we want to do. The samples and the user guide chapter are the most we have right now.