C++ with different sourceSet than default

Many of the libraries we have are organized with myLib for C and myLib++ for C++. We cannot convert/rename this scheme.

Directory structure: src/myLib src/myLib/c src/myLib/headers src/myLib++ src/myLib++/cpp src/myLib++/headers

As using “++” in library name does not seem to work and I have to work around it by supplying a different source directory.

My build.gradle script:

apply plugin: 'c'
apply plugin: 'cpp'
  model {
    platforms {
        x64 {
            architecture "x86_64"
        }
    }
    toolChains {
        gcc(Gcc) {}
    }
      components {
          myLib(NativeLibrarySpec)
          myLibCpp(NativeLibrarySpec) {
              sources {
                  cpp {
                      source {
                          srcDir "src/myLib++"
                          include "**/*.cpp"
                      }
                      exportedHeaders {
                          srcDir "src/myLib++"
                          include "**/*.hpp"
                      }
                  }
              }
          }
      }
}

However if I rename directory src/myLib++ to src/myLibCpp and remove sources from build.gradle and use the following libraries, then it works fine.

If I place the src/myLibCpp/cpp and src/myLibCpp/headers within src/myLib/ I have no problems building. However I only get a combined static and shared library for both C++ and C. build/binaries/myLibStaticLibrary/libMyLib.a build/binaries/myLibSharedLibrary/libMyLib.so

What I want is build/binaries/myLibStaticLibrary/libMyLib.a build/binaries/myLibStaticLibrary/libMyLib++.a build/binaries/myLibSharedLibrary/libMyLib.so build/binaries/myLibSharedLibrary/libMyLib++.so

Is this something that could be fixed in future Gradle versions. Would be great if I could use “++” within library name and output files.

With this directory structure:

src/myLib
 src/myLib/c
 src/myLib/headers
 src/myLib++
 src/myLib++/cpp
 src/myLib++/headers

and this build.gradle:

apply plugin: 'c'
apply plugin: 'cpp'
  model {
    components {
        myLib(NativeLibrarySpec)
        "myLib++"(NativeLibrarySpec)
    }
}

I seem to get the right result (this is Windows, but it should be the same for linux):

build/binaries/myLib++SharedLibrary/myLib++.dll
build/binaries/myLib++StaticLibrary/myLib++.lib
build/binaries/myLibSharedLibrary/myLib.dll
build/binaries/myLibStaticLibrary/myLib.lib

I think if we restricted this in the future, you could always hook into the link tasks and fix the output file name: https://gradle.org/docs/current/dsl/org.gradle.nativeplatform.tasks.LinkSharedLibrary.html#org.gradle.nativeplatform.tasks.LinkSharedLibrary:outputFile

I think we’ll provide something a little easier to configure eventually too.

Great. Using “myLib++”(NativeLibrarySpec) worked.