Gradle - 针对C++子模块库进行编译

Bra*_*one 5 c++ compilation gradle git-submodules

我正在尝试设置一个本身使用另一个(而不是gradle)C++项目的C++项目.

由于编译不需要任何特殊内容,我尝试将项目作为子模块包含在内,并通过gradle本身将该库编译为库.

据我所知,我已正确设置构建脚本,如下所示:

// Project-Type
apply plugin: "cpp"
// IDEs
apply plugin: "visual-studio"

model {
    visualStudio {
        solutions.all {
            solutionFile.location = "vs/${name}.sln"
            solutionFile.withContent { TextProvider content ->
                content.asBuilder().insert(0, "# GENERATED FILE: DO NOT EDIT\n")
                content.text = content.text.replaceAll("HideSolutionNode = FALSE", "HideSolutionNode = TRUE")
            }
        }
    }

    repositories {
        libs(PrebuiltLibraries) {
            easyloggingpp {
                headers.srcDir "lib/easyloggingpp/src"
            }
            eigen {
                headers.srcDir "lib/OpenNN/eigen/src"
            }
        }
    }

    platforms {
        x86 {
            architecture "x86"
        }
        x64 {
            architecture "x64"
        }
    }

    buildTypes {
        debug
        release
    }

    components {
        tinyxml2(NativeLibrarySpec) {
            sources.cpp {
                source {
                    srcDirs "lib/OpenNN"
                    include "tinyxml2/**/*.cpp"
                }
                exportedHeaders {
                    srcDirs "lib/OpenNN"
                    include "tinyxml2/**/*.h"
                }
            }
        }
        openNN(NativeLibrarySpec) {
            sources.cpp {
                source {
                    srcDirs "lib/OpenNN"
                    include "opennn/**/*.cpp"
                }
                exportedHeaders {
                    srcDirs "lib/OpenNN"
                    include "opennn/**/*.h"
                }

                lib library: "eigen", linkage: "api"
                lib library: "tinyxml2", linkage: "static"
            }
        }
        anni(NativeExecutableSpec) {
            if(System.properties['sun.arch.data.model'] == "64") {
                targetPlatform "x64"
            } else {
                targetPlatform "x86"
            }

            sources.cpp {
                source {
                    srcDirs "src"
                    include "**/*.cpp"
                }
                exportedHeaders {
                    srcDirs "src"
                    include "**/*.hpp"
                }

                lib library: "easyloggingpp", linkage: "api"
                lib library: "openNN", linkage: "static"
            }
        }
    }

    binaries {
        withType(NativeExecutableBinarySpec) {
            if (toolChain in Gcc) {
                cppCompiler.args "-Wall", "-Wextra", "-Wpedantic", "-fPIC"
            }
            if (toolChain in Clang) {
                cppCompiler.args "-Weverything", "-pedantic"
            }
            if (toolChain in VisualCpp) {
                cppCompiler.args "/W4", "/FS", "/EHsc"
            }
        }
        withType(SharedLibraryBinary) {
            buildable = false
        }
        withType(StaticLibraryBinarySpec) {
            if (toolChain in Gcc) {
                cppCompiler.args "-Werror"
            }
            if (toolChain in Clang) {
                cppCompiler.args "-Werror"
            }
            if (toolChain in VisualCpp) {
                cppCompiler.args "/W0", "/EHsc"
            }
        }
        all {
            if(buildType == buildTypes.debug) {
                cppCompiler.define "__DEBUG__"

                if (toolChain in Gcc) {
                    cppCompiler.args "-Og", "-g3"
                }
                if (toolChain in Clang) {
                    cppCompiler.args "-O0", "-g"
                }
                if (toolChain in VisualCpp) {
                    cppCompiler.args "/Od", "/Z7"
                }
            }
            if(buildType == buildTypes.release) {
                cppCompiler.define "__NDEBUG__"

                if (toolChain in Gcc) {
                    cppCompiler.args "-Ofast", "-g0"
                }
                if (toolChain in Clang) {
                    cppCompiler.args "-Ofast", "-g0"
                }
                if (toolChain in VisualCpp) {
                    cppCompiler.args "/O2"
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

虽然我跑的时候遇到gradle build以下错误:

Parallel execution is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':linkAnniReleaseExecutable'.
> No static library binary available for library 'openNN' with [flavor: 'default', platform: 'x64', buildType: 'release']

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
Run Code Online (Sandbox Code Playgroud)

任何人都能帮我解决我做错的事吗?(可在此处找到回购,发布此问题的时间版本为:e518d77c4d)