13

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 ?

Vi.
  • 37,014
  • 18
  • 93
  • 148
Reddy
  • 943
  • 6
  • 12
  • 21
  • 1
    I found answer. It's was simple just use key -D= in command-line. For example : cmake_minimum_required (VERSION 2.6) project (CMakeOptionTest) Message(STATUS "Poco directory: ${poco-dir}") And result : #cmake -Dpoco-dir=/usr -- Poco directory: /usr -- Configuring done -- Generating done -- Build files have been written to: xxx – Reddy Jul 22 '11 at 10:49
  • 4
    That's great that you figured this out. The usual practice is to post your findings as an answer and mark it as accepted. That way other people can learn from your question. http://meta.stackexchange.com/questions/12513/should-i-not-answer-my-own-questions – Rian Sanderson Jul 22 '11 at 17:38

1 Answers1

14

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.

Like
  • 1,470
  • 15
  • 21