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

Petr Kmoch petr.kmoch at gmail.com
Mon Mar 11 05:24:49 EDT 2013


install(SCRIPT ...) takes a name of a file as an argument, and
executes the CMake code in the file at installation time. That's why
you don't have to care about escaping there.

How this works is that the code in the file (or the code you give to
install(CODE ...)) is injected into cmake_install.cmake, which is the
file CMake executes when you do 'make install'. So the if() will then
be executed at install time.

Note: I've never used CPack, so I don't know whether/how this differs.

Petr

On Mon, Mar 11, 2013 at 10:06 AM, hce <jupiter.hce at gmail.com> wrote:
> Thanks Petr. I changed to use SCRIPT, it still got syntax error either.
> Please correct me what is wrong in the following statement.
>
> install(SCRIPT "
>      if (not exists "${destination}/myfile.txt")
>          install(FILES "${source}/myfile.txt" DESTINATION ${destination})
>      endif()
> ")
>
> Also, even the syntax is fixed, I am not clear how it can work. The
> install(FILES "${source}/myfile.txt" DESTINATION ${destination}) is
> basically to install ${source}/myfile.txt to %config
> "${destination}/myfile.txt" in the spec, where the check "if (not exists
> "${destination}/myfile.txt")" can be performed during installation?
>
> Appreciate correct me.
>
> Thank you.
>
> Kind regards.
>
> Jupiter
>
>
>
> Petr Kmoch wrote
>> Hi Jupiter,
>>
>> regarding your second question: you'd need to escape the nested
>> quotes. Also, I'm not sure if 'not exists' can be given in lowercase.
>>
>> However, I'd strongly suggest using install(SCRIPT ...) instead of
>> install(CODE ...), precisely because of the escaping issues.
>>
>> Petr
>>
>> On Mon, Mar 11, 2013 at 6:14 AM, hce &lt;
>
>> jupiter.hce@
>
>> &gt; wrote:
>>> 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.
>>>
>>> install(FILES "${source}/myfile.txt" DESTINATION ${destination})
>>>
>>> Is there anyway to set either overwrite, or no overwrite if the file
>>> exists?
>>> Or any workaround to stop the conflict error?
>>>
>>> I also tried following code, but I've got syntax error, if the
>>> install(CODE
>>> ..) can make it work, could you please correct my following code?
>>>
>>> install(CODE "
>>>     if (not exists "${destination}/myfile.txt")
>>>         install(FILES "${source}/myfile.txt" DESTINATION ${destination})
>>>     endif()
>>> ")
>>>
>>> Thank you.
>>>
>>> Kind regards,
>>>
>>> Jupiter
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://cmake.3232098.n2.nabble.com/How-to-set-Overwrite-or-no-over-write-in-install-FILES-tp7583548.html
>>> Sent from the CMake mailing list archive at Nabble.com.
>>> --
>>>
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the CMake FAQ at:
>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.cmake.org/mailman/listinfo/cmake
>> --
>>
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>
>
>
>
> --
> View this message in context: http://cmake.3232098.n2.nabble.com/How-to-set-Overwrite-or-no-over-write-in-install-FILES-tp7583548p7583563.html
> Sent from the CMake mailing list archive at Nabble.com.
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list