How can I list cmake default build option in command-line?
I need to build OpenCV libraries from source. Before that, I want to know what are the default build settings.
3 Answers
cmake -LAH
To list all option(...)
and set(... CACHE ...)
variables, including those marked as advanced, do:
cmake -LAH
where:
-L
: list variables-A
: include advanced variables.CMake marks most but not all of its default pre-defined variables as, and you can mark you own variables as advanced with
mark_as_advanced
). Some default CMake advanced variables include basic default compilation parameters such as:CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++ CMAKE_CXX_FLAGS:STRING= CMAKE_CXX_FLAGS_DEBUG:STRING=-g
If you are only interested in the main configuration options of some project, you will likely want to remove the
-A
as it would be mostly noise.-H
: include the help strings as// My help
above each setting.-H
was previously mentioned at: https://stackoverflow.com/a/53075317/895245 consider upvoting that answer
Example
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(ProjectName)
set(GREETING "hello" CACHE STRING "How to greet")
set(GREETING2 "hello2" CACHE STRING "Supersecret greeting")
mark_as_advanced(FORCE VAR GREETING2)
set(MYNOCACHE "mynocacheval")
option(WORLD "Print world or not?" ON)
If we run:
mkdir -p build
cd build
cmake -LAH ..
the output contains:
// How to greet
GREETING:STRING=hello
// Supersecret greeting
GREETING2:STRING=hello2
// How to greet
MSG:STRING=hello
// Supersecret greeting
MSG2:STRING=hello2
// Print world or not?
WORLD:BOOL=ON
plus a bunch of default defined CMake variables. If we remove -A
we get only:
// Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ...
CMAKE_BUILD_TYPE:STRING=debug
// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local
// How to greet
GREETING:STRING=hello
// How to greet
MSG:STRING=hello
// Print world or not?
WORLD:BOOL=ON
so we see that our advanced variable GREETING2
is not present. We also understand that CMake feels that two of their default variables are often useful to merit the non-advanced distinction:
CMAKE_BUILD_TYPE
to control debug vs release: Debug vs Release in CMakeCMAKE_INSTALL_PREFIX
to decide where to install the project output
Without -H
we get just:
CMAKE_BUILD_TYPE:STRING=debug
CMAKE_INSTALL_PREFIX:PATH=/usr/local
GREETING:STRING=hello
MSG:STRING=hello
WORLD:BOOL=ON
Note that the values are the cached values, not the defaults. E.g. if we first set a cached value:
cmake -DGREETING=bye ..
then running again cmake -L ..
gives:
CMAKE_BUILD_TYPE:STRING=debug
CMAKE_INSTALL_PREFIX:PATH=/usr/local
GREETING:STRING=bye
MSG:STRING=hello
WORLD:BOOL=ON
Better way to determine the exact build options: run a verbose build!
I think some of people coming to this question are trying to understand how CMake is building their things exactly.
While you could deduce much of that from cmake -LA
, a better more direct and sure-fire way would be as per: Using CMake with GNU Make: How can I see the exact commands? to just build with with:
make VERBOSE=1
The output would then contain a line of type:
/usr/bin/cc -DGREETING=\"hello\" -DWORLD -MD -MT CMakeFiles/main.dir/main.c.o -MF CMakeFiles/main.dir/main.c.o.d -o CMakeFiles/main.dir/main.c.o -c /home/ciro/main.c
which makes it clear exactly what CMake is doing.
ccmake
ncurses
ccmake is an nCurses Cmake UI. The advantage over cmake -L
is that you can interactively set the values as you find them:
sudo apt-get install cmake-curses-gui
ccmake .
shows:
To see the advanced options from cmake-curses-gui
you can just enter the t
key as mentioned on the UI which toggles them on or off.
cmake-gui
This UI is a bit better than ccmake
in terms of capabilities:
sudo apt install cmake-qt-gui
cmake-gui .
we have:
- "Advanced" checkbox to show the advanced options
- "Grouped" checkbox to group options. By default it produces two categories:
- "CMAKE" for the "CMAKE" default options
- "Ungrouped Entries" for your variables Option groups are apparently generated automatically based on common option name prefixes: Creating groups of CMake options
Tested in Ubuntu 22.10, cmake 3.5.2.

- 347,512
- 102
- 1,199
- 985
-
3
-
@PrzemekD thanks, mentioned it in the answer. Clients don't always know what is best for them :-) – Ciro Santilli OurBigBook.com Apr 24 '18 at 12:27
-
1Well... those are the options relevant to the project. How can you list all POSSIBLE options? – Mr. Developerdude Aug 14 '18 at 20:13
-
Sometimes it will not show all options listed in CMakeLists.txt, e.g.: OpenBLAS. You could run `cmake -D BUILD_SHARED_LIBS=ON` but nothing of proposed above will show it avaliability or status :( – banderlog013 Mar 22 '20 at 16:22
-
1@banderlog013 maybe it is because that is a general CMake option and not added specifically by OpenBLAS: https://cmake.org/cmake/help/v3.0/variable/BUILD_SHARED_LIBS.html – Ciro Santilli OurBigBook.com Mar 22 '20 at 17:01
-
1@CiroSantilli新疆改造中心法轮功六四事件 makes sense, but then how I could get values of standard options? Also, Will it work if I have cmake files in subdirs (~nested cmake)? – banderlog013 Mar 22 '20 at 18:37
-
@banderlog013 I'm not sure, try it out and ask a new question and link to it if you don't find out :-) – Ciro Santilli OurBigBook.com Mar 22 '20 at 18:48
-
Try `cmake -LAH` with additional information due to the `H` flag. – Melroy van den Berg Jan 06 '22 at 23:13
You can do cmake -LAH
too. The H
flag will provide you help for each option.

- 10,600
- 9
- 48
- 75
-
This only lists options as a by-product of doing many other things, for example if called like this it would clutter the root folder with extra files. Better use in form `cd build && cmake -LAH ..`. – scrutari Feb 11 '20 at 13:33
I do not know of an direct way to do it.
A way around this is to edit the main CMakeLists.txt and print at the end of the file the settings you are interested. The Variables where the most important cmake setting are stored are listed here:
I always print these variables at the end of my CMakeLists.txt to see the settings.
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
MESSAGE(STATUS "Library Type: " ${LIB_TYPE})
MESSAGE(STATUS "Compiler flags:" ${CMAKE_CXX_COMPILE_FLAGS})
MESSAGE(STATUS "Compiler cxx debug flags:" ${CMAKE_CXX_FLAGS_DEBUG})
MESSAGE(STATUS "Compiler cxx release flags:" ${CMAKE_CXX_FLAGS_RELEASE})
MESSAGE(STATUS "Compiler cxx min size flags:" ${CMAKE_CXX_FLAGS_MINSIZEREL})
MESSAGE(STATUS "Compiler cxx flags:" ${CMAKE_CXX_FLAGS})

- 7,605
- 5
- 41
- 57
-
a more detail answer can be found here : https://stackoverflow.com/questions/24767450/using-cmake-how-do-you-determine-the-default-compiler-flags-per-build-type – Marine Galantin Dec 06 '20 at 15:31