PRE_BUILD event runs after target is built
The documentation of add_custom_command states for PRE_BUILD
commands:
Run before any other rules are executed within the target.
The issue is, that a given pre-build event runs after building the target. This affects a given pre-link event too, which is executed after linking the target.
CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
project (build_event)
add_executable(build_event build_event.cpp)
add_custom_command(
TARGET build_event
PRE_LINK
COMMAND echo "I am prelinked to actual target"
COMMENT " Running PRE_LINK action "
)
add_custom_command(
TARGET build_event
PRE_BUILD
COMMAND echo " I am prebuilt to actual target"
COMMENT " Running PRE_BUILD action"
)
add_custom_command(
TARGET build_event
POST_BUILD
COMMAND echo " I postbuild to actual target"
COMMENT " Running POST_BUILD action "
)
Output:
Scanning dependencies of target build_event
[ 50%] Building CXX object CMakeFiles/build_event.dir/build_event.cpp.o
[100%] Linking CXX executable build_event
Running PRE_BUILD action
I am prebuilt to actual target
Running PRE_LINK action
I am prelinked to actual target
Running POST_BUILD action
I postbuild to actual target
[100%] Built target build_event
Environment:
- CMake: 3.10.2
- GCC: gcc (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0