[cmake-developers] Introducing: message(DEBUG)

Eric Noulard eric.noulard at gmail.com
Sat Mar 3 06:45:12 EST 2012


2012/3/3 Rolf Eike Beer <eike at sf-mail.de>:
> I have a small patch to CMake that looks like this:
>
> diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx
> index e1dbf34..ad24368 100644
> --- a/Source/cmMessageCommand.cxx
> +++ b/Source/cmMessageCommand.cxx
> @@ -52,6 +52,18 @@ bool cmMessageCommand
>     status = true;
>     ++i;
>     }
> +  else if (*i == "DEBUG")
> +    {
> +    if (!this->Makefile->GetCMakeInstance()->GetDebugOutput())
> +      {
> +      if (!this->Makefile->IsOn("CMAKE_DEBUG_MESSAGES"))
> +        {
> +        return true;
> +        }
> +      }
> +    status = true;
> +    ++i;
> +    }
>
>   for(;i != args.end(); ++i)
>     {
>
> The idea behind this is like that: you can write message(DEBUG ...) everywhere
> in your CMake code and it will just print out nothing. Once you run cmake --
> debug-output these messages will behave like message(STATUS), i.e. give you
> their contents and call trace. If at the point of the message(DEBUG) call a
> variable CMAKE_DEBUG_MESSAGES is set the message will behave like a normal
> message(STATUS), too. This variable is a completely normal CMake variable,
> i.e. it follows the normal scoping rules. My idea is to go into
> Modules/Find*.cmake and e.g. replace if(Boost_DEBUG) message(...) endif() just
> by "CMAKE_DEBUG_MESSAGES |= Boost_DEBUG" message(DEBUG ...).
>
> Opinions?

I like it, I thought about similar feature when writing CPackRPM.cmake
which uses the "CPACK_RPM_PACKAGE_DEBUG" for the same purpose.

However I thing that debug output should usually be prefixed by the context
emitting the  message in order to be able to tell debug output apart.

Thus I would rather have

message(DEBUG ...) automatically prefix with the name of the current list file
(for example) or may be adding a variable
CMAKE_DEBUG_MESSAGES_PREFIX with local scope which may
be set by the module/list file write before calling
message(DEBUG ...)

currently in CPackRPM I do:

MESSAGE("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")

I would like to be able to write:

set(CMAKE_DEBUG_MESSAGES_PREFIX "CPackRPM:Debug: ")
...
MESSAGE(DEBUG "rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
....
That way I would have typed the prefix once for the whole CPackRPM.cmake file.

Note that if one begins to use "message(DEBUG" instead of  "if(Boost_DEBUG)"
you won't be able to have selective debug output anymore, i.e.
activating DEBUG output
would enable debug output for all module/list files which may not be
as convenient
as set(Boost_DEBUG 1)

or may be that what you meant by
CMAKE_DEBUG_MESSAGES |= Boost_DEBUG ?
message(DEBUG ...)

-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org



More information about the cmake-developers mailing list