cmake - 在命令行中设置 cmake 变量并将其与字符串进行比较
问题描述
我这样称呼我的 CMakeLists.txt:
cmake ../.. -DTARGET=JETSON_NANO
然后,这一行:
message(STATUS "------------ TARGET: ${TARGET}")
印刷------------ TARGET: JETSON_NANO
但是这一行:
if (TARGET STREQUAL JETSON_NANO)
给出错误:
if given arguments:
"TARGET" "STREQUAL" "JETSON_NANO"
为什么?TARGET
定了!
解决方案
TARGET
是命令的特殊关键字if
。它用于检查给定目标(在 CMake 意义上)是否存在。此关键字的正确用法包括以下两个参数if
:
if(TARGET JETSON_NANO) # Checks whether CMake target JETSON_NANO exists
这就是为什么当你使用这个关键字和三个参数时 CMake 会发出错误:
if (TARGET STREQUAL "JETSON_NANO") # Error: 'TARGET' keyword requires two `if` arguments
但是,您可以在命令中交换比较的字符串:if
if ("JETSON_NANO" STREQUAL TARGET) # Compares string "JETSON_NANO" with variable TARGET
在其文档中查看有关if
命令的更多信息。
推荐阅读
- vue.js - 显示菜单取决于 url
- xslt - 从带有附加前缀的特定节点复制 XSLT
- jsch - 如何在 Jsch exec Channel 上设置读取超时
- sparql - 访问包含在父项的值中的项的属性
- grafana - 如何通过 REST API 更新 Grafana 面板中的指标值
- javascript - 如何在 daterangepicker 中禁用过去的日期?
- java - 如何使用 java SDK 生成 AWS 引导证书?
- php - 在 Debian 10 Buster 中安装 php-db 时出错
- python-3.x - 使用每列的唯一值作为每一级字典的键的多级嵌套字典
- javascript - 如何在我的 chrome 扩展程序中访问 chrome 通知 API?