[CMake] copy_if_different on build
Skippy VonDrake
skippyvondrake at gmail.com
Fri Mar 29 17:07:24 EDT 2013
>> I'm using:
>> execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
>> <some-file> <some-dest-dir>)
>>
>> Should the file be copied when:
>> the file has changed AND a build is executed?
>> Or
>> the file has changed AND CMakeLists.txt has changed AND a build is
>> executed?
>>
>> Only the 2nd method (when the CMakeLists.txt file is touched) results in
>> the
>> changed file being copied.
>>
>> I'd expect the 1st method to also cause a file copy.
>> If this assumption is wrong please tell me why.
>
>
> execute_process is a configure step. It does not create build rules and will
> ONLY execute when CMake is run.
>
> If you want to create a build rule, use add_custom_command or
> add_custom_target instead.
>
> Anyway, the above is silly; if you really only wanted the file copied at
> cmake time, you should instead use configure_file(... COPY_ONLY) :-) rather
> than unnecessarily invoking an extra process.
I'll look closer at add_custom_command. I want the file to copy over if
it has changed - at build time. Not cmake time. And not copy if it hasn't
changed. But that may not be doable.
Seems like every StackOverflow post I see has a different take on how
to do this simple process.
More information about the CMake
mailing list