[CMake] Copy a input file from src folder to EXECUTABLE_OUTPUT_PATH

Totte Karlsson totte at dunescientific.com
Tue Dec 6 03:49:47 EST 2011


>> I want to be moved to the same folder as the executables.
>> How do I do that in CMake?
>
> At configuration time:
>
> CONFIGURE_FILE(<path>/<to>/input.txt ${EXECUTABLE_OUTPUT_PATH} COPYONLY)
>
> Note that the destination directory, i.e. the EXECUTABLE_OUTPUT_PATH,
> possibly must already exist, and refer to the EXECUTABLE_OUTPUT_PATH
> variable only after it has received its value. BTW, this variable is
> obsolete, use [CMAKE_]RUNTIME_OUTPUT_DIRECTORY[_<CONFIG>] variable/
> properties instead.
>
> At build time:
>
> ADD_CUSTOM_TARGET(input ${CMAKE_COMMAND} -E copy_if_different
>      <path>/<to>/input.txt ${EXECUTABLE_OUTPUT_PATH})
> ADD_DEPENDENCIES(OneOfYourExecutables input)
> ADD_DEPENDENCIES(AnotherExecutable input)
>
> or
>
> ADD_CUSTOM_COMMAND(TARGET OneOfYourExecutables
>      COMMAND ${CMAKE_COMMAND} -E copy_if_different
>          <path>/<to>/input.txt $<TARGET_FILE_DIR:OneOfYourExecutables>)
> ADD_CUSTOM_COMMAND(TARGET AnotherExecutable
>      COMMAND ${CMAKE_COMMAND} -E copy_if_different
>          <path>/<to>/input.txt $<TARGET_FILE_DIR:AnotherExecutable>)
>
> Personally, I'd prefer the latter as it's clean and quite flexible.
Thanks. Great feedback!

Totte


More information about the CMake mailing list