[CMake] add_custom_command

Michael Wild themiwi at gmail.com
Mon Oct 15 00:42:14 EDT 2012


Hi

On 10/15/2012 12:54 AM, Totte Karlsson wrote:
> Hi, I have an executable target, that I want to be executed as part
> of its own build.
> 
> The target takes one argument, which is output folder of a text
> file. This text file is part of my source dir.
> 
> In my CMake file I have, at the end
> 
> set( resultFileFolder "${PROJECT_SOURCE_DIR}/wiki/reports") set(
> resultFile "${resFileFolder}/tests_auto.xml")

First things first: You should *never* pollute your source tree, always
output to the build tree.

> 
> add_custom_command( DEPENDS ${target} OUTPUT ${resultFile} COMMAND
> ${CMAKE_CURRENT_BINARY_DIR}/bin/${target} ARGS ${resultFileFolder} )
> 
> Now, this never seem to execute. No warnings, no nothing.
> 
> How to get it going?
> 
> -totte
> 

You need a top-level target that DEPENDS on the output, that's all. E.g.

add_custom_target(createWikiReports ALL DEPENDS ${resultFile})

BTW: You don't need to specify the full path to the executable in the
COMMAND, and also no DEPENDS on it in the custom command. Just use the
target name, and CMake will handle the rest for you.

HTH

Michael


More information about the CMake mailing list