Can't define different CppSourceSet for different buildtype


(66229754) #1

Hi,

I am using gradle 1.11. As the title described, I have the following configuratin with my library project: model {

buildTypes {

create(“Release”)

create(“Debug”)

} }

binaries.all {

def genratedFileFolder=“GeneratedFilesDebug”

if(buildType == buildTypes.Release)

{

genratedFileFolder = “GeneratedFilesRelease”

}

sources {

main {

cpp {

source {

srcDir genratedFileFolder

include “*.cpp”

}

}

}

} }

For debug build I only want to build the cpp files in “GeneratedFilesDebug” folder, while for release build only in “GeneratedFilesRelease”, seems " GeneratedFilesDebug" will add to release build. Can’t cpp sourceset be configured dynamically for different cases?


#2

It’s possible, but this isn’t the way to do it. When you reference ‘sources’ from inside the ‘binaries.all’ block, you’re configuring the component-level sources. There’s no ‘sources’ attribute on a native binary.

If you want to selectively add sources to a native binary (and not to the entire component), you need to do:

sources {
    mainRelease {
        cpp {
             srcDir "GeneratedFilesRelease"
        }
    }
    mainDebug {
        cpp {
             srcDir "GeneratedFilesDebug"
        }
    }
}
binaries.all {
     if (buildType == buildTypes.Release) {
        source sources.mainRelease.cpp
    } else {
        source sources.mainDebug.cpp
    }
}

I realise that this isn’t ideal: we’d like to make it easier to add variant-specific source sets. But this should solve your use case.

You can see an example of this in the ‘assembler’ sample in the Gradle distribution.


(rekh127) #3

Has there been any progress on variant-specific source sets?


#4

Not yet. However, we’re working on bringing variants to the JVM and Android domains at the moment, so you can expect to see this stuff get some love in the next few months.