[CMake] How to set Overwrite or no over write in install(FILES ....)?

Andreas Stahl andreas.stahl at tu-dresden.de
Mon Mar 11 05:34:50 EDT 2013


Am 11.03.2013 um 06:14 schrieb hce:

> Hi,
> 
> I have following statement to install a file from source directory to
> destination. It got a conflict error if the destination has already had the
> file. 
> 

Hello Jupiter,

can you post the error message here? I wasn't aware that install(FILES ...) did any checking besides comparing the dates and overwriting if the file to be installed is newer. 
Also, you misunderstood what Petr meant. You need to escape the quotes in the install(CODE "...") call, because you're effectively writing a string to a file, i.e.:

 install(CODE "
  if (NOT EXISTS \"${destination}/myfile.txt\")
        install(FILES \"${source}/myfile.txt\" DESTINATION ${destination})
    endif()
 ")

BUT: using install inside an install command smells like problems, so you better use the file(INSTALL...) directive, anyway:

 install(CODE "
  if (NOT EXISTS \"${destination}/myfile.txt\")
        file(INSTALL \"${source}/myfile.txt\" DESTINATION \"${destination}\")
    endif()
 ")

using the SCRIPT signature expects a cmake script file that will be included in the cmake_install.cmake script file. This means you would need to configure your paths in your cmakelists file

 configure_file(myfile_install.cmake.in myfile_install.cmake)
 install(SCRIPT myfile_install.cmake)

and in myfile_install.cmake.in you'd put

 if(NOT EXISTS "${destination}/myfile.txt")
   file(INSTALL "${source}/myfile.txt" DESTINATION "${destination}")
 endif()

Hope that helps,

Andreas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4681 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130311/21dab894/attachment.bin>


More information about the CMake mailing list