Cmake log messages configuration

Hello, I want to know how does the Cmake messages such as warning messages get displayed or logged in the the logfile. For example, if there is a find_package(“one”) in the cmakelist.txt, and this package does not exist, a Cmake warning message would show up saying that it could not find the package configuration file.

May I know how can I get into this message logging system, where does it configure this message to display in the console. Is there an option to suppress this message or display at all times? How can I access all these settings and files? Thank you.

The messages go to the output and I don’t think there’s a way to hook into it and intercept. You might want this instead:

find_package(one QUIET)
if (NOT one_FOUND)
  # whatever you wanted to do
endif ()

Thank you for your reply. I was getting this warning when I run with Cmake

CMake Warning at src/tad-commonapi/CMakeLists.txt:17 (find_package):
By not providing “Findtad.cmake” in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by “tad”, but
CMake did not find one.

Could not find a package configuration file provided by “tad” with any of
the following names:

tadConfig.cmake
tad-config.cmake

Add the installation prefix of “tad” to CMAKE_PREFIX_PATH or set “tad_DIR”
to a directory containing one of the above files. If “tad” provides a
separate development package or SDK, be sure it has been installed

It seems like there is already a default formatted warning messages built into Cmake that gets shown (when file is not located for e.g.), is there no way to configure this part of the log system? Can I find the if-else condition for this message?

Oh, that means CMake couldn’t even find to file to determine if tad can be found or not. No, there’s no way to configure this particular message at least.

1 Like

Thanks for clarifying.

Also, I am new to Cmake, there are some things I am confused about. I understand that there are message() to display messages based on the condition set in the parenthesis, but we can also set CMAKE_MESSAGE_LOG_LEVEL. For the latter, what does it mean by setting that variable, is there an option (e.g. debug, warning or error) to insert after “set(CMAKE_MESSAGE_LOG_LEVEL XXX)”?

Please see the docs for the variable.

1 Like