Including source directories with target platform name in cpp source sets

Is there any way to insert a srcDir in a cpp sourceSet that includes the target platform name?

What I’m trying to do is something like the following:

sources {
    cpp {
        source {
            srcDirs ["src/main/common", "src/main/${targetPlatform.name}"]
            include "**/*.cpp"
        }
        exportedHeaders {
            srcDirs ["src/main/include", "src/main/${targetPlatform.name}/include"]
            include "**/*.hpp"
        }
    }
}

The above is obvously not correct, since I get an error trying to run it. Would it be possible to add it in the binaries.all section?

I would try to do something like this:

The ‘cpp’ sourceset is shared with all binaries, so if you could add the source directory with the platform name, you’d add it to all binaries.

1 Like

Thanks!

Since I have a bunch of custom defined target platforms (the name of each one being a custom board, by the way, and no OS is used since it’s on bare metal), I think I got away with doing the following:

componentName(NativeLibrarySpec) {
    targetPlatform "board1"
    targetPlatform "mingw32"

    binaries.all {
        sources {
            platformCpp(CppSourceSet) {
                source {
                    srcDir "src/main/common"
                    srcDir "src/main/${targetPlatform.name}"
                    include "**/*.cpp"
                }
                exportedHeaders {
                    srcDir "src/main/include"
                    srcDir "src/main/${targetPlatform.name}/include"
                    include "**/*.hpp"
                }
            }
        }
    }

Yep, I think that would work too. Each platformCpp is unique to the binary.

1 Like