[CMake] Only install file if it does not exist?

Eric Noulard eric.noulard at gmail.com
Thu Sep 10 02:12:43 EDT 2009


2009/9/10 Bob Tanner <tanner at real-time.com>:
> On 2009-09-09 05:53:15 -0500, David Cole <david.cole at kitware.com> said:
>
>> Or just use "install(FILES" -- it already does the "if not exists, if
>> newer
>> than" checks...
>
> INSTALL (
>        FILES ${CMAKE_CURRENT_SOURCE_DIR}/sample_features
>        DESTINATION etc
>        RENAME features
> )

Yes I think you want a different behavior than that.

I think you want:
"Do not install if FILE IS ALREADY THERE"

but I think INSTALL(FILES  do
"Dot not install IF FILE EXISTS OR IS NEWER"

You should try to:

1) put your initial CMake script logic using IF(EXISTS "...
    in a CopyIfNotExists.cmake file

2)  use INSTALL(SCRIPT CopyIfNotExists.cmake)

You may have to write parameterized CopyIfNotExists.cmake.in which
configured using CONFIGURE_FILE because CopyIfNotExists.cmake
will be executed at install time with no variables coming from your
CMakeLists.txt defined.

So the most general way may be :

0)  Write your parameterized  CMake script CopyIfNotExists.cmake.in

1)  CONFIGURE_FILE(CopyIfNotExists.cmake.in CopyIfNotExists.cmake)
     This step will replace appropriate vars in CopyIfNotExists.cmake.in
     with value coming from your current config.

2)  INSTALL(SCRIPT CopyIfNotExists.cmake)

Should makes it possible to run any CMake scripts at install time.
Note however that in the CopyIfNotExists.cmake[.in] scripts you are
in CMake scripting mode (the one used when CMake -P) so you
may not use INSTALL command inside that one
(anyone correct me if I'm wrong)
but you already did that using the "cmake -E copy"


-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list