如何检查目标是否已添加? [英] How to check whether a target has been added or not?

查看:63
本文介绍了如何检查目标是否已添加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个cmake宏,可以根据某些条件添加目标(库或可执行文件)

Assume I have a cmake macro that adds target (library or executable) based on some conditions

macro (conditionally_add target_name target_src condition)
  if (condition)
    add_library (target_name target_src)
  endif ()
endmacro()

我的问题是,调用此函数后

My question is, after calling this function

conditionally_add (mylib mysrc.cc ${some_condition})

如何检查是否已添加库?更具体地说,我想在以下地方做一些事情

How can I check whether the library has been added? More specifically, I'd like to do something below

if (my_lib_is_added)    # HOW TO DO THIS?
  # Do something.
endif ()


推荐答案

使用<$ if 命令的c $ c> TARGET 子句:

Use the TARGET clause of the if command:

conditionally_add (mylib mysrc.cc ${some_condition})
if (TARGET mylib)
  # Do something when target found
endif()

这篇关于如何检查目标是否已添加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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