Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake: difference between install(files,etc) and files(install,etc)

Tags:

cmake

I'm learning cmake and I'm puzzled by the following thing:

I'm trying to move a file to a specific location and I did it like this:

file(
      INSTALL file.txt DESTINATION ../install_dir
    )

This worked fine. This moved 'file.txt' to the specified destination.

However then I tried like this:

install (
         FILES ./file.txt DESTINATION ./install_dir
        )

Using 'install' only doesn't work as expected. The file is not installed at that location. Can someone please explain the difference to me? Why is it working in the first case but not when only using install command? Thank you.

like image 490
Kennedy Avatar asked Apr 04 '18 06:04

Kennedy


1 Answers

The two commands do different things. install(FILES fil DESTINATION dest) instructs CMake to generate a build rule so that file fil is copied into dest when running the install step (make install or equivalent).

file(INSTALL ...) is evaluated immediately at configure time, while CMake is parsing the CMakeLists.txt file. Note that this signature is primarily intended for CMake's internal implementation of the above mentioned installation step: it prints install-themed status messages etc. If you just want to copy a file at configure time, you might want to prefer file(COPY) or file(COPY_IF_DIFFERENT).

like image 109
Angew is no longer proud of SO Avatar answered Oct 21 '22 01:10

Angew is no longer proud of SO