Changing the baseName doesn't work as expected


(Ralf Schallenberg) #1

Gradle Version: 2.14.1
Operating System: Windows 10

Hi, I want to change the baseName of a native shared library depending on the target platform and I’m running into problems. Here’s a modified samples\native-binaries\cpp-lib\build.gradle that exhibits the problem:

apply plugin: "cpp"

model {
    buildTypes {
        debug
        release
    }
    
    platforms {
        x86 {
            architecture 'x86'
        }
        x64 {
            architecture 'x86_64'
        }
    }

    components {
        main(NativeLibrarySpec) {
            targetPlatform "x86"
            targetPlatform "x64"

            binaries.withType(SharedLibraryBinarySpec) {
                def arch = "INVALID_PLATFORM"
                if (targetPlatform == platforms.x86) {
                    arch = "32"
                } else if (targetPlatform == platforms.x64) {
                    arch = "64"
                }

                baseName = "main" + arch

                // Define a preprocessor macro that only applies to shared libraries
                cppCompiler.define "DLL_EXPORT"
            }
        }
    }
}

And this is the actual output:

build\libs\main\shared\x64\debug\main.dll
build\libs\main\shared\x64\release\main64.dll
build\libs\main\shared\x86\debug\main64.dll
build\libs\main\shared\x86\release\main32.dll

Is this a bug or am I doing it wrong?