Discussion:
[CMake] custom_command pre_build vs. post_build
Richard Fuchs
2006-09-20 16:10:35 UTC
Permalink
I've added some logging around each of our libraries that we build, but
I'm getting an unexpected result. I'm using a custom command with the
cmake -E echo to print a log out before and after a library is built.
However, the results are not consistent. When we have custom targets,
things work the way I'd expect, but when the target is a library, both
PRE_BUILD and POST_BUILD options are run at the same time. I've
attached cmakelists snips and outputs.

Thanks
Richard


im_generator/CMakelist.txt
ADD_CUSTOM_TARGET(im_generator ALL
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_generator.sh
${CMAKE_CURRENT_SOURCE_DIR})

# Helpful logging
ADD_CUSTOM_COMMAND(
TARGET im_generator
PRE_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E echo "*****Begin Interest Management Generator *****")

ADD_CUSTOM_COMMAND(
TARGET im_generator
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E echo "***** End Interest Management Generator *****")

daki/CMakeLists.txt
ADD_LIBRARY(${DAKI_CPlusPlus_LIB} SHARED ${SRCS})

# Helpful logging
ADD_CUSTOM_COMMAND(
TARGET ${DAKI_CPlusPlus_LIB}
PRE_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E echo "***** Begin ${DAKI_CPlusPlus_LIB} *****")

ADD_CUSTOM_COMMAND(
TARGET ${DAKI_CPlusPlus_LIB}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E echo "***** End ${DAKI_CPlusPlus_LIB} *****")


Output:

*****Begin Interest Management Generator *****
path :=
/work/secore-dev/secore/services/distributed_object/src/interest_management/generator/../..
[PARSING]{[imSimpleTypeTest] sdm.phys.StartResume: SimulationTime
<OPERATOR> time}
[PARSING]{[imComplexTest] sdm.phys.RDMPhysicalEntity:
MountedOn.SectorOfFire.AngleFromHeading <OPERATOR> someAngle}
[PARSING]{[imCompoundTest] sdm.phys.RDMPhysicalEntity:
(MountedOn.SectorOfFire.AngleFromHeading <OPERATOR> someAngle) <Compound
Operator> (SectorOfFire.AngleFromHeading <OPERATOR> angle2) <Compound
Operator> TentDeployed <OPERATOR> deployed}
[PARSING]{[imSimpleTypeTest] sdm.phys.StartResume: SimulationTime
<OPERATOR> time}
[PARSING]{[imComplexTest] sdm.phys.RDMPhysicalEntity:
MountedOn.SectorOfFire.AngleFromHeading <OPERATOR> someAngle}
[PARSING]{[imCompoundTest] sdm.phys.RDMPhysicalEntity:
(MountedOn.SectorOfFire.AngleFromHeading <OPERATOR> someAngle) <Compound
Operator> (SectorOfFire.AngleFromHeading <OPERATOR> angle2) <Compound
Operator> TentDeployed <OPERATOR> deployed}
***** End Interest Management Generator *****
Building CXX object
services/distributed_object/src/c++/vsasvc/doss/daki/CMakeFiles/daki.dir/daki.o
Linking CXX shared library
../../../../../../../../lib/services/distributed_object/libdaki.so
***** Begin daki *****
***** End daki *****
Brad King
2006-09-20 16:19:16 UTC
Permalink
Post by Richard Fuchs
I've added some logging around each of our libraries that we build, but
I'm getting an unexpected result. I'm using a custom command with the
cmake -E echo to print a log out before and after a library is built.
However, the results are not consistent. When we have custom targets,
things work the way I'd expect, but when the target is a library, both
PRE_BUILD and POST_BUILD options are run at the same time. I've
attached cmakelists snips and outputs.
Richard Fuchs
2006-09-20 16:40:21 UTC
Permalink
Ah, I see the note now. It's not in the section of the cmake book that
describes the command, but it's in the command index in the back and on
the web.
So why does it work with the add_custom_target?


Brad King wrote:
Brad King
2006-09-20 16:45:56 UTC
Permalink
Post by Richard Fuchs
Ah, I see the note now. It's not in the section of the cmake book that
describes the command, but it's in the command index in the back and on
the web.
So why does it work with the add_custom_target?
It doesn't AFAIK. The custom rule specified by the custom target is put
at the beginning of the post-build rules list. Therefore the pre-build
rules do run before it. However if there are any custom commands in the
target (using the DEPENDS argument of ADD_CUSTOM_COMMAND) I think they
will still run first.

-Brad

Loading...