Thanks, that worked for printing a message during our “check” target.  Makes 
sense for “if (TARGET…)” to truthfully enter if that target name exists.  What 
threw me off, I think, was having "TARGET test” not actually pass and 
misunderstanding the docs that this would embed logic in the generator output.

I ended up adding COMMAND ${CMAKE_COMMAND} -E echo “…” lines to the 
add_custom_target() and that did the trick for my “check” target.  Getting 
similar behavior for the “test" target seems to be impossible, though.

I even tried to trick ctest by creating a test that printed a message but 
failed.  I could create a custom target that only printed a message and ran 
‘false’ to give an error; and I could create another cmake target that ran 
ctest with —output-on-failure to see the message — and that worked just fine 
for running that target via cmake.  However, every which way I tried to invoke 
that target via add_test seemed to only produce an infinite loop during “make 
test” or ctest.

What I ended up doing was punting on displaying the fancy message and just 
added a test whose test name was a very shortened form of the message intended 
(via add_test(NAME “NOTE\\ important\\ message\\ here”…).  Made the test still 
run the ‘false’ message target too (via COMMAND cmake …), so it ends up in the 
testing log during make test and conveniently pauses for 3-4 seconds on just 
that one test (apparently the overhead on our build system to simply invoke 
cmake).

In all, it’s working, but hopefully this info might be useful to any archive 
searcher hitting a similar problem… at least until 
http://public.kitware.com/Bug/view.php?id=8438 is addressed... 

Cheers!
Sean



On Nov 24, 2015, at 7:44 AM, Parag Chandra <pa...@ionicsecurity.com> wrote:

> The if() statements are executed when CMake runs, because you’re basically 
> adding logic to the “meta-build” process that generates your build system; 
> not the build system itself. Maybe you can use “add_custom_target” to create 
> targets which do nothing but print the desired message, and then use 
> “add_dependencies” to tie these targets back to your original ones? So 
> something like:
> 
> add_custom_target(“test_print” …)
> add_dependencies(test test_print)
> 
> 
> 
> 
> Parag Chandra
> Senior Software Engineer, Mobile Team
> Mobile: +1.919.824.1410
> 
> <https://ionic.com> 
> 
> Ionic Security Inc.
> 1170 Peachtree St. NE STE 400, Atlanta, GA 30309
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> On 11/24/15, 12:04 AM, "CMake on behalf of Christopher Sean Morrison" 
> <cmake-boun...@cmake.org on behalf of brl...@mac.com> wrote:
> 
>> 
>> 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
>> 
>> -- 
>> 
>> Powered by www.kitware.com
>> 
>> Please keep messages on-topic and check the CMake FAQ at: 
>> http://www.cmake.org/Wiki/CMake_FAQ
>> 
>> Kitware offers various services to support the CMake community. For more 
>> information on each offering, please visit:
>> 
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>> 
>> Visit other Kitware open-source projects at 
>> http://www.kitware.com/opensource/opensource.html
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to