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.
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)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With