qbs找不到子模块的输出(用cmake构建)

时间:2018-06-04 07:02:56

标签: cmake git-submodules qbs

我有一个由cmake构建的子模块,并在qbs脚本中成功构建它(参见下面的代码)。

Product {
name: "mylib"
type: ["staticlibrary"]

// define buildScript, outputPath, libPrefix, libExt, cmakeBuildType, cmakeBuildConfig
// Note that outputPath is inside mylib folder, not qbs's build directory

Rule {
    multiplex: true
    outputArtifacts: [
        {
            filePath: product.outputPath + product.libPrefix + "lib1static" + product.libExt,
            fileTags: ["staticlibrary"]
        },
        {
            filePath: product.outputPath + product.libPrefix + "lib2static" + product.libExt,
            fileTags: ["staticlibrary"]
        }
    ]
    outputFileTags: ["staticlibrary"]
    prepare: {
        var cmd = new Command(product.buildScript, [product.outputPath, product.cmakeBuildType, product.cmakeBuildConfig]);
        cmd.description = "cmake generate mylib";
        cmd.workingDirectory = product.sourceDirectory + "/mylib/build_cmake";

        return [cmd];
    }
}

但是,有时qbs会删除“lib1static”和“lib2static”,并在链接时出现此错误:

clang: error: no such file or directory: '<path>/lib1static.a'
clang: error: no such file or directory: '<path>/lib2static.a'

我试图调试但仍然不知道为什么。第一个构建可以成功构建所有输出库,但在下一个构建中,所有库都会消失。

这里的任何人都可以解释并告诉我这种情况的最佳做法是什么?

1 个答案:

答案 0 :(得分:0)

我不明白为什么文件会被删除。但是,还有另一个问题: 上面显示的规则只运行一次,因为它没有输入,因此子项目的源文件中的更改将不会被选中。 (并且,作为旁注:如果输出不是“动态”,则可以声明工件项,而不是使用outputArtifacts和outputFileTags属性。) 试试这个:

Rule {
    multiplex: true
    alwaysRun: true
    Artifact {
        filePath: product.outputPath + product.libPrefix + "lib1static" + product.libExt
        fileTags: ["staticlibrary"]
        alwaysUpdated: false
    }
    Artifact {
        filePath: product.outputPath + product.libPrefix + "lib2static" + product.libExt
        fileTags: ["staticlibrary"]
        alwaysUpdated: false
    }
    prepare: {
        var cmd = new Command(product.buildScript, [product.outputPath, product.cmakeBuildType, product.cmakeBuildConfig]);
        cmd.description = "cmake generate mylib";
        cmd.workingDirectory = product.sourceDirectory + "/mylib/build_cmake";

        return [cmd];
    }
}