CMake add_custom_command / _target在不同的目录进行交叉编译 [英] CMake add_custom_command/_target in different directories for cross-compilation

查看:672
本文介绍了CMake add_custom_command / _target在不同的目录进行交叉编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CMake,我试图构建一个项目,包括多个不同处理器架构的库,由不同的工具链编译。对于每个体系结构,静态库都构建在多个子目录中,然后收集到根目录中的共享库中。

In CMake, I'm trying to build a project that includes libraries for multiple different processor architectures, compiled by different toolchains. For each architecture, static libraries are built in multiple subdirectories, and then collected into a shared library in the root directory. So far, I haven't been able to figure this out.

到目前为止,我最接近的是使用 add_custom_command add_custom_target 在子目录中生成.a文件,然后尝试使用 add_custom_command将它们收集到根目录中的.so add_custom_target 。但是如果我使.so依赖指向自定义命令输出列表,则makefile会显示No rule to make ...,因为自定义命令输出不会导出子目录。所以我试图让.so依赖指向子目录中的自定义目标列表,并且抱怨它找不到具有该名称的文件。

The closest I've come so far is to use add_custom_command and add_custom_target in the subdirectories to produce the .a files and then try to collect them into a .so in the root directory using add_custom_command and add_custom_target again. But if I make the .so dependency point to the list of custom command outputs, the makefile says "No rule to make ..." because the custom command outputs are not exported out of the subdirectory. So I tried making the .so dependency point to the list of custom targets in the subdirectory, and it complains that it can't find a file with that name.

代码形式,这里是我在一个子目录:

To put it in code form, here is what I have in a subdirectory:

add_custom_command(OUTPUT subout.a COMMAND ${MYAR} ...)
add_custom_target(subout_target DEPENDS subout.a)

我试过这个:

add_custom_command(OUTPUT my.so COMMAND ${MYLD} ... DEPENDS sub/subout.a)
add_custom_target(dll ALL DEPENDS my.so)

我得到 'sub / subout.a',需要'my.so'。停止。这是有道理的,因为 add_custom_command 目标不会导出到目录之外。

And I get "No rule to make target 'sub/subout.a', needed by 'my.so'. Stop." Which makes sense because add_custom_command targets are not exported out of a directory.

>

And I tried this:

add_custom_command(OUTPUT my.so COMMAND ${MYLD} ... DEPENDS subout_target)
add_custom_target(dll ALL DEPENDS my.so)

这实际上会导致生成sub / subout.a文件,说没有规则,使目标'subout_target'...

This will actually cause the sub/subout.a file to be generated, but then it dies, saying "No rule to make target 'subout_target'..."

我想我真正想要的是能够模仿 add_library 行为为多个不同的体系结构。但显然,CMake不希望我这样做...:)

I think what I really want is to be able to mimic the add_library behavior for multiple different architectures. But apparently, CMake doesn't want me to do that... :)

任何想法?

推荐答案

我假设您需要使用 add_dependencies 定义使用 add_custom_target 定义的目标之间的依赖关系。 DEPENDS 选项用于在自定义规则中指定文件级依赖关系,但不指定目标级依赖关系。

I presume you need to use add_dependencies to define dependencies between targets defined using add_custom_target. The DEPENDS option is used to specify file-level dependencies in custom rules but not target-level dependencies.

例如,生成 .obj 文件作为输出的命令使用DEPENDS指定它取决于 .cpp 文件。此外,目标可以依赖于单个文件,而不仅仅依赖于其他目标。所以,对于文件级依赖,使用DEPENDS选项,但add_dependencies为目标级。

For example, command generating .obj file as output uses DEPENDS to specify it depends on .cpp file. Also, a target can be dependant on a single file, not only on other targets. So, for file-level dependendies, use DEPENDS option, but add_dependencies for target-level.

这篇关于CMake add_custom_command / _target在不同的目录进行交叉编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆