Cmake File COPY across drives

636 views Asked by At

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?

2

There are 2 answers

0
codeMetis On BEST ANSWER

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)
3
vre On

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.