Skip to content
Wenliang ZHANG edited this page Jan 2, 2021 · 1 revision

CMake is widely used nowadays, and it it evolving rapidly. IDEs like CLion, VScode work well with it.

Get the list of arguments

$ cd build
$ cmake .. -LH

// Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ...
 CMAKE_BUILD_TYPE:STRING=

// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local
<snipped>

Get the list of targets

$ cd build
$ make help
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... edit_cache
... install
... install/local
... install/strip
... list_install_components
... package
... package_source
... rebuild_cache
... test
... GenBison_hints
<snipped>

Show compile/link command lines

$ cd build
$ make VERBOSE=1 mysqld
$ make VERBOSE=1 mysqld 2>&1 | tee make.log

Actually, the link command is saved in files like ./sql/CMakeFiles/mysqld.dir/link.txt。

Generate the dependency graph

The core idea of CMake is targets and their relationships, visualizing them is a must-have feature.

$ cmake .. --graphviz=mysql.dot
$ dot -Tsvg -o mysql.svg mysql.dot
$ explorer.exe mysql.svg  # open it in WSL2; use `open' in macOS.

But if there are customized targets, a special option is needed. And it must be in a special file. See https://cmake.org/cmake/help/latest/module/CMakeGraphVizOptions.html. This feature is introduced in 3.18?

$ cat CMakeGraphVizOptions.cmake
cmake_minimum_required(VERSION 3.18)
SET(GRAPHVIZ_CUSTOM_TARGETS TRUE)
Clone this wiki locally