2

Working on a project using CMake. This project contains an executable and a python script. These two files should be compiled/copied in the same directory at build.

I try something like :

add_executable( ${myTarget} ${all_c_sources} )
add_custom_command(
  TARGET ${myTarget} POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy ${pythonScriptPath} ${RUNTIME_OUTPUT_DIRECTORY}/
)

The executable is well build in a default location like ${CMAKE_BINARY_DIR}/Debug but the copy of the python script failed :

c:\Program Files (x86)\CMake\bin\cmake.exe" -E copy C:/.../script.py /\r

My goal is to use CMake default behavior as mush as possible. Is there a simple way to get the default output path ?

Thanks !

3
  • You have missed closed brace in ${RUNTIME_OUTPUT_DIRECTORY/. Commented Feb 15, 2016 at 9:44
  • Why "at build" and not "at install" ? Commented Feb 15, 2016 at 10:09
  • Installation is not necessary for this project for now. We just want to execute the python script with the executable beside as soon as they are compiled. Commented Feb 15, 2016 at 10:28

1 Answer 1

1

Something like this:

add_custom_command(TARGET ${LIBRARY_NAME} POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy_if_different
  $<TARGET_FILE:${LIBRARY_NAME}>
  $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/path/to/where/module/should/be
  COMMENT "Copying file to Runtime directory: " $<TARGET_FILE:${LIBRARY_NAME}>
)

Adjust it to your needs.

Read about CMake Generator Expressions if you need to know more.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.