Cmake

From miki
Revision as of 09:51, 13 June 2023 by Mip (talk | contribs) (→‎Print variables)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Select toolchain

On Windows

On Windows, cmake default to the latest Visual Studio version installed on the system. To select MinGW toolchain [1]:

cmake -G "MinGW Makefiles" .

Tips

Print variables

# Using message
message(PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}")

# Using helper:
include(CMakePrintHelpers)
cmake_print_variables(PROJECT_SOURCE_DIR ANOTHER_VARIABLE

Verbose build

  • Add CMAKE_VERBOSE_MAKEFILE to CMakeLists.txt (note: it only applies to current file):
set(CMAKE_VERBOSE_MAKEFILE ON)
  • Add -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to cmake command to enable it for all files:
cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ..
  • Add VERBOSE=1 to make command:
cmake ..; make VERBOSE=1

See here for more.