[CMake] add_custom_command

Totte Karlsson totte at dunescientific.com
Mon Oct 15 14:20:02 EDT 2012


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.
This is part of a google code project and the output file is a report in 
the wiki. It belongs in the repository. Actually, its not an output from 
the build itself, but output from a test, run just after the build.

>
> You need a top-level target that DEPENDS on the output, that's all. E.g.
>
> add_custom_target(createWikiReports ALL DEPENDS ${resultFile})
I ended up doing this instead;
set( resultFileFolder "${CMAKE_SOURCE_DIR}/wiki/reports")

add_custom_target(test PACKAGE
     COMMAND ${exe_path}/${target}.exe ${resultFileFolder}
)

This seem to work well with borland, but with visual studio it is 
executed before the target is built, which is a problem, obviously.

So perhaps the combination of add_custom_command and add_custom_target 
is needed?

Weird that it behaves differently using borland and visual studio though?
> 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.
I always seem to have problem with the paths regarding targets, because 
of Visual Studios addition of Debug and Release.
-totte


More information about the CMake mailing list