How do I specify build options for CMake-based projects?

Reddy picture Reddy · Jul 22, 2011 · Viewed 25k times · Source

I don't understand how to configure project and handling command line options using CMake. I need to set variables of directories of 3rd party library (for example Poco and GTest). Usual, i just run ./configure with necessary parameters. For example:

./configure --poco-inc=~/libs/poco/include --poco-lib=~/libs/poco/lib --gtest-inc=~/libs/gtest/include --gtest-lib=~/libs/gtest/lib

But how do I pass the equivalent information to CMake ? How to specify options and handling it with 'set' or 'property' in cmake file ?

Answer

Like picture Like · Feb 4, 2013

Additionally, you can use OPTION command

option(<option_variable> "help string describing option" [initial value])

See also

http://cmake.org/cmake/help/v2.8.10/cmake.html#command:option

The options are defined by cmake command line arguments

-D<variable-name>=<value>

You can also use

cmake -LH

to display the options and their help messages.