cmake - Why does CMake export() command defer the output file creation? Can it be avoided?
问题描述
We are including separate repositories into a common CMake superproject (which simply add_subdirectory()
each repository folder, in the correct dependency order).
The different repositories all rely on export() to ouptut a XxxTargets.cmake
file, such as:
# Assumes this repository provide the 'Alpha' target
install(TARGETS Alpha EXPORT AlphaTargets)
export(EXPORT $AlphaTargets
FILE $AlphaTargets.cmake
NAMESPACE myrepo::)
Yet, this superproject approach allowed us to observe that the export
does not create the file directly. We could draw this conclusion because when the generated file is include()
from another repository (added later, with a subsequent add_subdirectory()
), the file does not exist yet.
- Why is
export()
delaying the file creation? - And more importantly, is there a way to force it to actually create the file before the next
add_subdirectory()
?
解决方案
- 为什么会
export()
延迟文件创建?
因为您要求它为特定的导出集生成代码,直到配置步骤结束才完全定义。如果它立即生成它,那么export()
and的行为install(EXPORT)
将是令人烦恼和不一致的。
- 更重要的是,有没有办法强制它在下一个之前实际创建文件
add_subdirectory()
?
据export(TARGETS)
我所知,签名会立即运行。但我也想不出在使用add_subdirectory
. 目标已经存在,因此无需导入它们!如果名称不同,请根据需要创建 ALIAS 目标。
推荐阅读
- api - 文本框中不显示文本
- php - 拒绝,因为 php8.0 可能会导致无效的组合
- notifications - 当构建在依赖项后面排队时,Teamcity 通知?
- firebase - “用户”不是函数。尝试更正名称以匹配现有函数,或定义名为 'User'.dartinvocation_of_non_func 的方法或函数
- javascript - 使用 XHR 请求 API 时出现 CORS 错误
- reactjs - NextJs:仅在登录/注册页面中隐藏页眉和页脚?
- javascript - 使用 jQuery 和 CSS 选择器计算元素
- javascript - How to automatically add a new name to cloned radio buttons in a new card
- javascript - 如何验证是否已使用 Yup 验证设置状态?
- python - PostgreSQL 批量更新记录