[CMake] What is the preferred method of establishing the
dependence of a custom command on an executable target?
Brandon J. Van Every
bvanevery at gmail.com
Sun Apr 8 23:09:11 EDT 2007
Alan W. Irwin wrote:
>
> What do you think of the possibility of using the above "forked"
> arrangement
> of dependencies instead? I will go to that (and not worry about
> GET_TARGET_PROPERTY),
You must use GET_TARGET_PROPERTY to support MSVC. YMMV with other
generators.
> if anybody can assure me that the executable will
> always be built first before the custom command that requires it.
I'm having trouble with what your ASCII diagram really means. So, I
will specify what you have to do in CMake code.
ADD_EXECUTABLE(doit ${DOIT_SOURCES})
GET_TARGET_PROPERTY(DOIT_EXE doit LOCATION)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo0.qaz
COMMAND ${DOIT_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/someinput0.txt
${CMAKE_CURRENT_BINARY_DIR}/foo0.qaz
)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo1.qaz
COMMAND ${DOIT_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/someinput1.txt
${CMAKE_CURRENT_BINARY_DIR}/foo1.qaz
)
[...]
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fooN.qaz
COMMAND ${DOIT_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/someinputN.txt
${CMAKE_CURRENT_BINARY_DIR}/fooN.qaz
)
SET(FOO_FILES_LIST
${CMAKE_CURRENT_BINARY_DIR}/foo0.qaz
${CMAKE_CURRENT_BINARY_DIR}/foo1.qaz
[...]
${CMAKE_CURRENT_BINARY_DIR}/fooN.qaz
)
# The DEPENDS are file level dependencies. By wrapping them with
ADD_CUSTOM_TARGET,
# you have created a target level dependency for all of them.
ADD_CUSTOM_TARGET(foo-files DEPENDS ${FOO_FILES_LIST})
# Make sure ${DOIT_EXE} is built before trying to produce the files.
ADD_DEPENDENCIES(foo-files doit)
# Now we can get on with making our library.
ADD_LIBRARY(libwhatever ${FOO_FILES_LIST})
Cheers,
Brandon Van Every
More information about the CMake
mailing list