[CMake] What is the preferred method of establishing
the dependence of a custom command on an executable target?
Bill Hoffman
bill.hoffman at kitware.com
Mon Apr 9 09:27:24 EDT 2007
Brandon J. Van Every wrote:
> 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
> )
Actually from the wiki:
http://www.cmake.org/Wiki/CMake_FAQ
Your custom commands should look like this:
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
DEPENDS ${DOIT_EXE})
That will make sure the DOIT_EXE is built before the command is run.
Newer versions of cmake also support just using the target name there,
so you can even have:
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
DEPENDS doit)
)
The wiki should be updated to show that information. Then this part:
ADD_DEPENDENCIES(foo-files doit)
is no longer required, and is implied by the custom commands.
-Bill
More information about the CMake
mailing list