2

The following does not work:

cmake file ( copy "C:/pathtofile/file.file" DESTINATION "D:/pathtofile2/file2.file" )

Is there a way to achieve the same thing using cmake?

codeMetis
  • 420
  • 4
  • 16
  • Possible duplicate of [CMake: copy file from source directory to binary directory](http://stackoverflow.com/questions/34799916/cmake-copy-file-from-source-directory-to-binary-directory) – Tsyvarev May 18 '17 at 07:15

2 Answers2

2

The documentation states that DESTINATION has to be a directory. Therefore renaming the file does not work this way.

execute_process(COMMAND ${CMAKE_COMMAND} -E copy "C:/pathtofile/file.file" "D:/pathtofile2/file2.file")

should work.

vre
  • 6,041
  • 1
  • 25
  • 39
  • You are 100% correct, however I think configure_file( C:/pathtofile/file.file" "D:/pathtofile2/file2.file") is cooler. – codeMetis May 18 '17 at 07:21
  • Do you think that it's unclear code if I have it calling configure_file? or unnecessary processing? – codeMetis May 18 '17 at 07:23
  • 1
    I don't think so. But I use configure_file only in cases when variable substitutions should be made. The option COPYONLY is crucial to configure_file for your first case. It says: whatever is in the file leave it alone. – vre May 18 '17 at 07:29
0

cmakes fantastic Configure file system will work. The files can have different names, but basically if it finds any variables that can be expanded by cmake like ${cmake_root_dir} or $ENV{localappdata}, it will edit the file, replace the variables with their values and save it to the new location under the new name. So if there are no variables it just copies.

Configure_file( C:/pathtofile/file.file" "D:/pathtofile2/file2.file")

If you have cmake style variables in there for whatever reason and you don't want them expanded, use @Only as it will only expand variables surrounded by "@":

Configure_file( C:/pathtofile/file.file" "D:/pathtofile2/file2.file" @ONLY)
codeMetis
  • 420
  • 4
  • 16