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

jupiter jupiter.hce at gmail.com
Tue Mar 12 09:47:07 EDT 2013


Thanks Eric.

That clarifies lots of things.

Kind regards,

Jupiter


On 3/11/13, Eric Noulard <eric.noulard at gmail.com> wrote:
> 2013/3/11 hce <jupiter.hce at gmail.com>:
>> Andreas Stahl wrote
>>> 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
>>
>> Ahh, that's tricky, the file(INSTALL ....) works. Thank you so much
>> Andreas,
>> and thanks Petr for your kind helps.
>
> You should keep in mind that actions takes place at different "time":
>
> CMake/Configure time - when cmake runs and configure your source (when
> the CMakeLists.txt are read)
> Build time - when you compile
> Install time - when you use the "make install" or build the "install"
> target with your favorite build tool
> CPack time - when CPack runs, during this step the CPack generator is
> running and CPack itself
>                       is running a "CPack install time"  step which
> install things in a CPack-private location
>                       <buildtree>/_CPack_Packages/...
> Package Install time - when the package itself (RPM, DEB, ZIP, NSIS)
> is installed.
>
> have a look at slides 15 and 16 here:
> https://github.com/TheErk/CMake-tutorial/blob/master/CMake-tutorial-8feb2012.pdf
>
> install(...) command found in CMakeLists.txt is processed at CMake-time
> which creates a set of cmake_install.cmake files which get used
> at "Install time" or "CPack time::CPack install time".
>
> The [CMake] command you can use without trouble in
>   install(SCRIPT
>  or
>   install(CODE
>
> are "scriptable" commands, the one you use when using cmake -P.
> That why you find
> file(INSTALL ...)
> in cmake_install.cmake and no install(TARGET ...), "install" is not
> scriptable.
>
> At "Package Install time" you have what your packaging system offers and
> usually
> you dont expect to have CMake running at this point.
>
> I hope this clarifies the process.
> Depending on "when" you expect action to take place drive "how" you can do
> it.
>
> --
> Erk
> Le gouvernement représentatif n'est pas la démocratie --
> http://www.le-message.org
>


More information about the CMake mailing list