Is it somehow possible with CMake (version >= 2.8.7) to execute a macro or command as a last step before the configuration phase finishes?
The functionality should be executed before the following lines get printed on screen:
-- Configuring done
-- Generating done
Up to now I wasn't able to find a CMake target which could be used as a dependency to achieve this with add_custom_command
add_custom_target
or add_dependencies
.
EDIT:
We have a library exporting several CMake macros and some of these macros must be executed at the end of each CMakeLists.txt
file after all other CMake commands were run.
Ideally the desired behavior can be achieved by including a file macros.cmake
in a CMakeLists.txt
file without the necessity to add an additional command at the end of this CMakeLists.txt
file.
It would also be possible to achieve this by gathering all functionality in one macro which needs to be called explicitly at the end of the CMakeLists.txt
.
However, there are already several dependent libraries which would need to be adapted and a solution to this problem would omit this additional work.
Also, adding the macro can be forgotten or the requirement for it being the very last statement can be easily violated.
Example macros.cmake
:
macro(FINAL_MACRO)
message(STATUS "Last step before finishing Configure phase")
endmacro()
# HERE: something like add_custom_target(final_steps)
# followed by something like add_dependencies(final_steps cmake_configure_finished)
Example toplevel CMakeLists.txt
:
cmake_minimum_required(VERSION 2.8.7)
include(macros.cmake)
add_subdirectory(source)
add_subdirectory(interfaces)
# Here FINAL_MACRO should get executed without explicitly writing it down
If there is no other option we will have to require every user to call a special macro at the end of their CMakeLists.txt
file.