前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cmake:EXCLUDE_FROM_ALL的用处

cmake:EXCLUDE_FROM_ALL的用处

作者头像
10km
发布2019-05-25 22:34:20
3.9K0
发布2019-05-25 22:34:20
举报
文章被收录于专栏:10km的专栏10km的专栏

版权声明:本文为博主原创文章,转载请注明源地址。 https://cloud.tencent.com/developer/article/1433734

cmake 的add_library,add_executable,add_subdirectory等命令都有一个EXCLUDE_FROM_ALL参数.

这个参数的作用根据cmake官网的解释就是如果某个target或subdirectory被设置为EXCLUDE_FROM_ALL属性,那么这个target(或这个subdirectory中的所有target)就会被排除在all target列表之外,这样,当执行默认的make(或nmake)时,这个target(或这个subdirectory中的所有target)就不会被编译。

EXCLUDE_FROM_ALL Exclude the target from the all target. A property on a target that indicates if the target is excluded from the default build target. If it is not, then with a Makefile for example typing make will cause this target to be built. The same concept applies to the default build of other generators. Installing a target with EXCLUDE_FROM_ALL set to true has undefined behavior. @cmake.org

在一个项目中不可避免会有一些测试代码,这些测试代码,我们并不一定需要每次都编译,尤其是编译正式版本的时候,这些测试代码是不会加入release版本的。为了加快编译速度,可以将这些测试用的target或不会加入release的target 加上EXCLUDE_FROM_ALL属性就不需要每次编译它了。

下面是代码示例:

代码语言:javascript
复制
add_library(cmimpl SHARED ${CMIMPL_SOURCE_FILES})
add_library(cmjnidrv SHARED ${JNI_SOURCE_FILES})
# fctest指定了EXCLUDE_FROM_ALL 属性,不会自动编译,只能手动编译
add_executable(fctest EXCLUDE_FROM_ALL FeatureCompareSpeedTest.cpp)

加了EXCLUDE_FROM_ALL属性的target在默认编译的时候,不会被编译,如果要编译它们,需要手动编译,

比如make fctest指定编译名为fctest

参考:

https://cmake.org/cmake/help/v3.1/prop_tgt/EXCLUDE_FROM_ALL.html#prop_tgt:EXCLUDE_FROM_ALL

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年06月25日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档