Passing the argument to CMAKE via command prompt

2019-01-22 18:03发布

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.

Sample of my makefile:

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?

1条回答
你好瞎i
2楼-- · 2019-01-22 18:11

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

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

Source: http://cmake.org/cmake/help/v2.8.8/cmake.html#command:set

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

Source: 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.

查看更多
登录 后发表回答