为CMake中的子目录生成“干净”目标 [英] Generating a 'clean' target for a subdirectory in CMake

查看:118
本文介绍了为CMake中的子目录生成“干净”目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为子目录生成一个 clean 目标。

I want to generate a clean target for a subdirectory.

我的项目结构如下:

app/
  A
  B

lib/
   A
   B
   C

有时候我只想在应用程序/ A上运行干净,而又不想

Sometimes I want to run clean on just app/A and don't want to clean the library.

是否可以告诉CMake为每个目录生成 clean 目标?

Is it possible to tell CMake to generate a clean target for each directory?

还是像 app-clean 这样的自定义目标将在每个应用程序子目录上调用clean?

Or a custom target like app-clean which will call clean on each application sub-directory?

推荐答案

您只需将CD刻录到$ {CMAKE_BINARY_DIR} / app / A并在其中运行 make clean

You can just cd to ${CMAKE_BINARY_DIR}/app/A and run make clean there.

当然,您可以添加add_custom_target(app-A-clean ...)。

Of course, you can add_custom_target(app-A-clean ...) which would do this for you.

macro(add_clean_target dir)
add_custom_target(clean-${dir} COMMAND ${CMAKE_MAKE_PROGRAM} clean WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${dir})
endmacro(add_clean_target)

现在,您可以按以下方式使用它:

Now you can use it in such way:

add_clean_target(app-A)

这篇关于为CMake中的子目录生成“干净”目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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