Reputation: 317
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(FILES)
doesn't copy files like I expect. The file is not installed at that location when I run the CMake configure command.
Can someone please explain the difference to me? Why is it that file(INSTALL)
works when running the configure command, but install(FILES)
doesn't?
Upvotes: 8
Views: 3082
Reputation: 171127
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)
.
Upvotes: 10