Passing the argument to CMAKE via command prompt

Meluha picture Meluha · Oct 15, 2012 · Viewed 96.5k times · Source

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?

Answer

Peter picture Peter · Oct 15, 2012

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.