How to print messages after execution with cmake?

I am trying to print messages after creating a process using CMake.

I just want to tell the user after the make completed without any errors.

How can i do this? I tried add_custom_target() , but I can not choose when to run it.

In addition, I tried add_custom_command() , again, it does not give me the correct result.

Any idea?

Thanks for your idea in advance.

+6
source share
3 answers

You can really do the following:

 add_custom_target( FinalMessage ALL ${CMAKE_COMMAND} -E cmake_echo_color --cyan "Compilation is over!" COMMENT "Final Message" ) add_dependencies( FinalMessage ${ALL_TARGETS} ) 

This custom goal, depending on the list of all the goals that you previously defined, will make sure that it is completed last.

+5
source

To print a message after creating a specific goal, e. d. make yourtarget you can use

 add_custom_command(TARGET yourtarget POST_BUILD COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan "Message after yourtarget has been built.") 

Instead of POST_BUILD you can also use PRE_BUILD or PRE_LINK for other purposes, see the documentation .

(You indicated in the comments that you want to print the message after all the goals, but the original question is less accurate. Therefore, it can be useful for people who look here.)

+3
source

I just solved the problem with smarquis . Thanks.

Here's a step-by-step procedure for this. Since my source tree is associated with the add_subdirectory() method add_subdirectory() complex way, everyone can use this method.

  • Initialize the ALL_TARGETS cache variable. Add a line to CMakeLists.txt right below the version check command.

     Set(ALL_TARGETS "" CACHE INTERNAL "") 
  • Override the Add_library() and Add_executable() methods. If there is another goal, redefine it. Add the lines below to the end of the CMakeLists.txt file.

     function(Add_library NAME) Set(ALL_TARGETS ${ALL_TARGETS} "${ARGN}" CACHE INTERNAL "ALL_TARGETS") _add_library(${NAME} ${ARGN}) endfunction() function(Add_executable NAME) Set(ALL_TARGETS ${ALL_TARGETS} "${ARGN}" CACHE INTERNAL "ALL_TARGETS") _add_executable(${NAME} ${ARGN}) endfunction() 
  • Create a custom goal that will complete all the actions you want to do after creation. In this example, I just print some information on the screen. Add it and then above.

     add_custom_target(BUILD_SUCCESSFUL ALL DEPENDS ${ALL_TARGETS} COMMAND ${CMAKE_COMMAND} -E echo "" COMMAND ${CMAKE_COMMAND} -E echo "=====================" COMMAND ${CMAKE_COMMAND} -E echo " Compile complete!" COMMAND ${CMAKE_COMMAND} -E echo "=====================" COMMAND ${CMAKE_COMMAND} -E echo " ) 
  • TA-dah!

+2
source

Source: https://habr.com/ru/post/973642/


All Articles