[CMake] print a message during a specific build target

Christopher Sean Morrison brlcad at mac.com
Tue Nov 24 00:04:56 EST 2015


Hi,

I’m trying to print a message for a particular build target and am a bit stuck.  I found that the IF statement has a TARGET keyword that should truthfully match for a particular build target, but it doesn’t seem to be working at least the way I’m trying to use it and would expect it to work.  Snippet in question in a top-level CMakeLists.txt file looks like this:

if (TARGET check)
  message(“special note about CHECK target…”)
elseif (TARGET test)
  message(“different note about TEST target…”)
endif (TARGET check)

Now what happens is that the CHECK message is printed … during cmake(!).  What I’m trying to achieve is only have those messages printed during≈ “make check” and “make test”, etc.  Ideally, I want to be able to inject a message before any target actions are taken and possibly after.

I see in the docs that I can set COMMENT during add_custom_target(check …) and that should print my message before any target actions, but how can I get a similar message printed during ‘test’ or ‘all’ or some other implicit target?  Is there a better or more general way?  Thanks for your assistance.

Cheers!
Sean



More information about the CMake mailing list