I am currently running some builds on a shared host where I don't have root access. Unfortunately, this means that most of my 3rd party libraries are installed in ~/local instead of in standard locations like /usr/ and /usr/local
In my CMakeLists.txt, I have commands such as FIND_LIBRARY and FIND_PATH.
I didn't want to change those to use the machine dependent paths, but rather
control them with environment variables.
So in order to get everything working smoothly, it proved to be pretty easy.
I just added the following to my .bashrc
export CMAKE_PREFIX_PATH=~/local/
export LD_LIBRARY_PATH=~/local:$LD_LIBRARY_PATH
export LD_RUN_PATH=~/local:$LD_LIBRARY_PATH
Now cmake can find the nonstandard libraries and when I execute the program, the libraries are dynamically loaded properly.