When working with CMake, especially on larger projects, it's often helpful to know exactly what build targets are available. This is particularly useful when you want to build only a specific executable or inspect intermediate build steps without rebuilding everything. This tutorial demonstrates how to get all available build targets using CMake.
Here's an example of a minimal project defined in CMakeLists.txt
file:
cmake_minimum_required(VERSION 3.27)
project(myapp)
set(CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME} main.cpp)
Generate the build files by running:
cmake -S . -B build
Now, to list all possible build targets generated by CMake (including custom commands, executables, object files, and utility targets), we can run:
cmake --build build -t help
The output will look something like this:
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... edit_cache
... rebuild_cache
... myapp
... main.o
... main.i
... main.s
Leave a Comment
Cancel reply