Germain D.
Germain D.

Reputation: 173

Empty RUNTIME_OUTPUT_DIRECTORY

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 !

Upvotes: 2

Views: 1270

Answers (1)

jacmoe
jacmoe

Reputation: 1697

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.

Upvotes: 1

Related Questions