我有一个包含多个产品的项目,其中一些取决于生成的代码(cpp 和 hpp 文件)。这个生成的代码是它自己取决于作为 CppApplication 的 code_generator 产品。
如果他的来源发生变化,我希望重新构建 code_generator,然后始终运行。只有在输出文件发生更改时才会修改输出文件(它在内部将它们生成在一个临时文件夹中,并在将它们移动到正确的位置之前使用校验和检查更改)。然后一旦生成文件,其他产品的编译就可以开始了。
我的问题是,在构建 code_generator.exe 之前,我将生成的文件放入其中的 StaticLibrary 开始构建。其他依赖于 StaticLibrary 的产品也可以在生成 .hpp 文件之前开始构建。
所以我的问题是:是否有一些机制可以让产品等到完全建立特定的依赖项?
我对任何类型的解决方案持开放态度,生成的代码可以在任何类型的模块中,我只是尝试使用 StaticLibrary,因为它看起来更方便。
PS:code_generator 产品生成了很多文件,并采用了一些我在 qbs 中不精确的输入,因为它始终可以运行,并且可以将其视为输入本身,因为它可以更改。这就是为什么我不确定使用 Rule 对我来说是否真的很有趣。
这是我的 qbs 文件的摘录:
CppApplication
{
name: "code_generator"
consoleApplication: true
files: [
"../sources/code_generator/code_generator.cpp",
"../sources/code_generator/code_generator.hpp",
...
]
Depends { name: "default-cpp-configuration" }
Depends { name: "tinyxml2" }
destinationDirectory: "../" // @Warning we move the binary to ease his usage by the "generated_code" module
}
StaticLibrary // @Warning as static library to build those sources only once
{
name: "generated_code"
Depends { name: "default-cpp-configuration" }
Depends { name: "code_generator" }
Rule {
multiplex: true
alwaysRun: true
// inputs: [project.buildDirectory + "/../code_generator.exe"]
Artifact { filePath: "generated/common/directx/driver_call_table.cpp"; fileTags: "cpp" }
Artifact { filePath: "generated/common/directx/driver_call_table.hpp"; fileTags: "hpp" }
Artifact { filePath: "generated/common/directx/d3d11.def"; fileTags: "def" }
Artifact { filePath: "generated/common/directx/uuid_helpers.cpp"; fileTags: "cpp" }
Artifact { filePath: "generated/common/directx/uuid_helpers.hpp"; fileTags: "hpp" }
prepare: {
var code_generator_path = project.buildDirectory + "/../code_generator.exe";
var cmd = new Command(code_generator_path, ["DirectX", "Outdir=${GENERATED_SOURCES_PATH}", "Indir=${CMAKE_SOURCE_DIR}/lib/specs", "CompilerPath=${CMAKE_CXX_COMPILER}", "--preprocess"]);
cmd.description = "generating sources";
return cmd;
}
}
}
CppApplication
{
name: "client"
consoleApplication: true
files: [
"../sources/client/main.cpp",
]
Depends { name: "default-cpp-configuration" }
Depends { name: "generated_code" }
Depends { name: "openssl" }
}