CMake trace portion of script
CMake
cmake_language(TRACE)
enables tracing selected nestable portions of CMake script, which is important for debugging CMake projects due to the generally large volume of trace output.
The trace output is large as the nature of CMake’s platform-independence means that numerous checks are performed even on minimal CMake scripts.
This can make it difficult to find the relevant portion of the trace output for debugging.
The cmake_language(TRACE) command allows specification of a named portion of the CMake script to trace, including nested trace regions.
This is a powerful debugging tool because it narrows trace output to the relevant part of the CMake script instead of emitting the entire script trace.
To trace only part of a script, wrap that region with cmake_language(TRACE) as in this CMakeLists.txt example:
cmake_minimum_required(VERSION 4.2)
project(demo LANGUAGES C)
cmake_language(TRACE ON)
find_package(Zlib)
cmake_language(TRACE OFF)
find_package(LAPACK)observe that only the trace output for the find_package(Zlib) command is emitted, while the find_package(LAPACK) command and compiler discovery are not traced.