默认在CMake中构建自定义目标 [英] Build custom target by default in CMake

查看:74
本文介绍了默认在CMake中构建自定义目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用cmake运行自定义命令。这听起来像是一个非常简单的任务/问题,但令人沮丧的是找到一个例子很困难。

I'd like to run a custom command with cmake. That sounds like an incredibly simple task/question, but it's frustrating how difficult it is to find an example.

这就是我正在尝试做的事情:

Here's what I'm attempting to do:

$ cmake .
$ make
> Hello World! (Output)

在Gnu中非常简单:

bar: 
        echo Hello World!

但是我想用cmake做到这一点。根据我一直在阅读的内容,应该可以使用下面的 CMakeLists.txt 文件做到这一点:

But I'm trying to do this in cmake. Based on what I've been reading, I should be able to do that with the CMakeLists.txt file below:

cmake_minimum_required(VERSION 3.6)
project(foo)
add_custom_target(bar)
add_custom_command(
  TARGET   bar
  COMMAND  "echo Hello World!"
)

当前,如果我打电话给我 make 。我需要显式调用 make bar 。如何在全部食谱中添加 bar

Currently there is no work to do if I just call make. I need to explicitly call make bar. How can I add bar to the all recipe?

我尝试添加 add_dependency(foo bar),但是 foo 是不存在的目标。如果有一些我不知道的超级目标,那将是完美的。然后,我可以将其用作我的自定义命令的目标,而不必担心 bar

I've tried adding add_dependency(foo bar), but foo is a non-existent target. If there is some super-target that I'm unaware of that would be perfect. Then I could just use that as the TARGET for my custom command and not bother with bar.

推荐答案

使用 ALL 选项默认情况下构建目标

Use ALL option for build the target by default:

add_custom_target(bar ALL)

这篇关于默认在CMake中构建自定义目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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