通过命令提示符将参数传递给 CMAKE

编程入门 行业动态 更新时间:2024-10-15 06:13:58
本文介绍了通过命令提示符将参数传递给 CMAKE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有一个生成文件,并且我正在传递一些参数,并根据该参数设置一些标志.我能够做到这一点.但现在我想用 cmake 做同样的事情.我已经创建了 cmakelist.txt 但我不知道如何传递参数并检查 cmakelist.txt 中的参数值.

I have a makefile for my project and also I am passing some argument and based on that argument i am seting some flag. I am able to do this . but now I want to do the same using cmake. I have created cmakelist.txt but I don't know how to pass the argument and check for the argument value in cmakelist.txt.

我的生成文件示例:

ifeq "$(FAB)" "po"
      //setting some flags
else
      //setting some iother flag
endif

从命令提示符获取参数并基于此设置标志的方法是什么?

What is the way to take the argument from command prompt and set flags based on that?

推荐答案

在 CMakeLists.txt 文件中,创建一个缓存变量,如下所述:

In the CMakeLists.txt file, create a cache variable, as documented here:

SET(FAB "po" CACHE STRING "Some user-specified option")

来源:http://cmake/cmake/help/v2.8.8/cmake.html#command:set

然后,要么使用 GUI(ccmake 或 cmake-gui)设置缓存变量,要么在 cmake 命令行中指定变量的值:

Then, either use the GUI (ccmake or cmake-gui) to set the cache variable, or specify the value of the variable on the cmake command line:

cmake -DFAB:STRING=po

来源:http://cmake/cmake/help/v2.8.8/cmake.html#opt:-Dvar:typevalue

如果实际上您的选项是布尔值,则将缓存变量修改为布尔值.

Modify your cache variable to a boolean if, in fact, your option is boolean.

这篇关于通过命令提示符将参数传递给 CMAKE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 05:08:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/795926.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令提示符   参数   CMAKE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!