Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake command-line help for user options

Tags:

cmake

I have some options in my CMakeLists.txt file that can be selected with -D on the command line, like this:

# Set some options the user may choose
OPTION(USE_MPI "Use the MPI library for parallelization" OFF)
OPTION(USE_OPENMP "Use OpenMP for parallelization" OFF)
OPTION(TESTING "Enable testing of both Fortran and Python code" OFF)
OPTION(PYTHON_TOOLS "Build the python helper tools" OFF)
OPTION(BUILD_DOCS "Build the documentation; turns on PYTHON_TOOLS" OFF)

and I can activate one of them with something like

$ cmake . -DUSE_MPI=ON

Sometimes I forget what the options I have chosen are. It would be nice if there was some sort of -h flag I could use to display those on the command line in an automated way (in the style of python's argparse).

Is there an automated way to generate help documentation for a particular CMakeLists.txt, and/or call that help with some sort of -h or --help flag? I'm looking for something that will give me this behavior:

$ cmake . --help
USE_MPI - Use the MPI library for parallelization (Default: OFF)
USE_OPENMP - Use OpenMP for parallelization (Default: OFF)
TESTING - Enable testing of both Fortran and Python code (Default: OFF)
PYTHON_TOOLS - Build the python helper tools (Default: OFF)
BUILD_DOCS - Build the documentation; turns on PYTHON_TOOLS (Default: OFF)

If there is no automated way, is there at least an easy way to pass --help or -h to CMakeLists.txt so that I can manually write a help message?

like image 368
SethMMorton Avatar asked Dec 12 '13 04:12

SethMMorton


People also ask

How do I configure CMake options?

There are two different ways to configure with cmake ; one is to run cmake in a fresh directory passing some options on the command line, and the other is to run ccmake and use its editor to change options. For both, assume you are in a directory called debug and the IMP source is in a directory at ../imp .

How use CMake command line?

Running CMake from the command line From the command line, cmake can be run as an interactive question and answer session or as a non-interactive program. To run in interactive mode, just pass the option “-i” to cmake. This will cause cmake to ask you to enter a value for each value in the cache file for the project.

What are CMake options?

Provide a boolean option that the user can optionally select. If no initial <value> is provided, boolean OFF is the default value. If <variable> is already set as a normal or cache variable, then the command does nothing (see policy CMP0077 ).

What CMake command does?

CMake can generate a native build environment that will compile source code, create libraries, generate wrappers and build executables in arbitrary combinations. CMake supports in-place and out-of-place builds, and can therefore support multiple builds from a single source tree.


1 Answers

I think the closest to what you're looking for is the -L command line arg. Running cmake . -LH should configure your project, then output all your cached, non-advanced variables along with their help strings.

The i arg also allows you to see the current values of options, but this actually runs cmake in command line "wizard mode" - it configures the project, asking you to set/update each variable one at a time.

like image 89
Fraser Avatar answered Sep 28 '22 18:09

Fraser