Reputation: 200
The problem: i want to echo some info when make makefile, the makefile is generated by CMakeLists.txt, and i don't want to echo the info when cmake CMakeLists.txt, what should i do? In Makefile, the code is like this:
.build-pre:
@echo
@echo "###########################################################"
@echo "######## Welcome to Prosim Build System ###################"
What should i wirte in the CMakeLists.txt so that i can get like these in MakeFile?
Upvotes: 0
Views: 1103
Reputation: 19071
You can use add_custom_target
function to create a dummy target that has dependencies set to all other targets causing it to be built first.
You can use the ALL
option to make it build every time. However, you will still need to use add_dependencies
to make it build before every other target.
Finally, use the command-line tool mode of CMake to make it platform independent. (The COMMENT
option of add_custom_target
may be enough to show the message).
add_custom_target(display_intro ALL COMMAND cmake -E echo Foo)
# ....
add_executable(your_app ...)
add_dependencies(your_app display_intro)
add_library(your_lib ...)
add_dependencies(your_lib display_intro)
For convenience, you could probably wrap the add_executable
and add_dependencies
in a function or macro.
Upvotes: 1