0

I wanna using configure_file(<input> <output> COPYONLY) to copy a specific directory files recursive , I used this command:

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/res/* ${CMAKE_CURRENT_BINARY_DIR}/res COPYONLY)

but I got some errors , How I should use this command for this porpuse? (I looked at this question too), the Errors:

CMake Error at CMakeLists.txt:86 (configure_file): configure_file Problem configuring file

I know that I can use it with file(...) too , but I wanna use configure_file(...):

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/res)
H.M
  • 425
  • 2
  • 16
  • From the cmake documentation of `configure_file` (emphasis mine): *"Copies **an** `` file to **an** `` file .."* – fabian Apr 09 '22 at 11:39
  • 1
    "I wanna use configure_file(...)" - Then you need to use it for **every** separate file. You could obtain list of files using `file(GLOB)` and iterate over this list with `foreach`. – Tsyvarev Apr 09 '22 at 11:39
  • There's `execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/res" "${CMAKE_CURRENT_BINARY_DIR}/res")` which does seem to achieve what you seem to attempt here btw... – fabian Apr 09 '22 at 11:41

1 Answers1

2

I don't think it is possible to use configure_file to copy a folder directly. The command is about

copy a file to another location and modify its contents.

It operates on one file only. https://cmake.org/cmake/help/latest/command/configure_file.html

Joe_Bao
  • 116
  • 6