[CMake] ADD_CUSTOM_COMMAND and dependencies

Moreland, Kenneth kmorel at sandia.gov
Thu Feb 9 10:05:40 EST 2006


It sounds like CMake is doing exactly what any good build system should
do.  A better solution is to modify your macro to accept some extra
depends to add to the custom command.

MACRO(GENERATE directory dependencies)
	ADD_CUSTOM_COMMAND(
		OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.cpp
		DEPENDS ${GENERATOR} ${dependencies}
		COMMAND ${GENERATOR}
		ARGS -o generated.cpp ${directory}
	)
	SET(SOURCES ${SOURCES} 
		${CMAKE_CURRENT_BINARY_DIR}/gomgenerated.cpp)
ENDMACRO(GENERATE) 

GENERATE(myDir "target1 target2")

If you insist on running the command every time, an old build trick you
may try is to make a target that never builds a file.  That way it will
run every time.

ADD_CUSTOM_COMMAND(
	OUTPUT NotAFile
	COMMAND ${CMAKE_COMMAND} ARGS -E echo "Forcing Target"
)
ADD_CUSTOM_COMMAND(
	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.cpp
	DEPENDS NotAFile
	COMMAND ${GENERATOR}
	ARGS -o generated.cpp ${directory}
)

-Ken

> -----Original Message-----
> From: cmake-bounces+kmorel=sandia.gov at cmake.org 
> [mailto:cmake-bounces+kmorel=sandia.gov at cmake.org] On Behalf Of cedric
> Sent: Thursday, February 09, 2006 7:50 AM
> To: cmake at cmake.org
> Subject: [CMake] ADD_CUSTOM_COMMAND and dependencies
> 
> Hello,
> 
> I'm using cmake in a project and have some trouble with 
> ADD_CUSTOM_COMMAND.
> What I need is generate a source file with a binary 
> previously generated by the project and then add it in the project.
> 
> It works with this code :
> 
> MACRO(GENERATE directory)
> 	ADD_CUSTOM_COMMAND(
> 		OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.cpp
> 		DEPENDS ${GENERATOR}
> 		COMMAND ${GENERATOR}
> 		ARGS -o generated.cpp ${directory}
> 	)
> 	SET(SOURCES ${SOURCES} 
> ${CMAKE_CURRENT_BINARY_DIR}/gomgenerated.cpp)
> ENDMACRO(GENERATE)
> 
> it works well but it run only when ${GENERATOR} is modified. 
> I canot add  other dependecies because this macro is run on 
> many directories that change often.
> The generator parse all files in ${directory} to check what 
> it have to generate and if it need to generate something.
> What I need is to run that command every time I run make. I 
> tryed to remove the DEPENDS line but it doesn't work better.
> There is a way to do what I need with CMake (in a portable 
> way if possible) ?
> Thanks for your help.
> 
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
> 
> 



More information about the CMake mailing list