[CMake] Run custom command only when dependency changes

Lloyd lloydkl.tech at gmail.com
Wed Apr 2 00:23:27 EDT 2014


On Tue, Apr 1, 2014 at 12:55 PM, Nils Gladitz <nilsgladitz at gmail.com> wrote:

> SET (MY_SRC Event_log.h other.cpp other1.cpp)
>>
>> ADD_EXECUTABLE(MyExe ${MY_SRC }
>>
>> add_custom_command(OUTPUT Event_log.h COMMAND mc Event_log.mc
>> WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS Event_log.mc)
>>
>> Whenever I run the build command, this causes the "mc" to rerun each
>> time (even if the .mc file is not changed), and in effect recompiling a
>> major portion of my project.
>>
>> May I know what am I doing wrong here?
>>
>
> The OUTPUT path is relative to the current binary directory.
> Since you set the WORKING_DIRECTORY to the current source directory (I
> assume this is where the output actually goes) the actual output path and
> the output you specified don't match up.
>
> This causes to command to rerun every time since the output as specified
> is never created.
>
> I would generate the output in the binary directory rather than the source
> directory if possible so that separate parallel build directories for the
> same source directory still work as intended.
>
> Nils
>


Thanks it solved the problem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140402/407ef067/attachment.html>


More information about the CMake mailing list