cmake: how to keep path to libraries during installation
It is INSTALL_RPATH target's property which affects on RPATH for installed executable. This property is set to value of variable CMAKE_INSTALL_RPATH at target creation time.
So, variable CMAKE_INSTALL_RPATH
needs to be set before add_executable()
call for make effect on the target.
Most of global variables and target-unaware commands affect on the target only at target creation time.
There are exceptions, like command include_directories()
, which affects on all targets created in the current directory. But preparing everything before creation of the target could be good practice.