windowscmakecopydrives

Cmake File COPY across drives


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?


Solution

  • 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)