通过命令提示符将参数传递给 CMAKE [英] Passing the argument to CMAKE via command prompt

查看:40
本文介绍了通过命令提示符将参数传递给 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.org/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.org/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屋!

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