I am using Conan2 to resolve external dependencies. I add them via find_ package in my CMakeLists.txt.
My own project binaries created by cmake --build ... have their run path's set by cmake pointing to dependencies living in the conan cache. But those binaries in the conan cache have no runpath set.
Example: libcrypto.so in the conan cache will have no runpath set and load the system installed libssl.so, which has the wrong version. It will not find the correct version which is available in the conan cache.
My solution so far is to always build and install into an installation directory which I use to test or debug. This works totally fine for me but there are some limitations. CTest for example, assumes running from within the build directory, hence I cannot use that. gtest however is no problem and I prefer using its test binaries directly anyhow.
If you say, that setting LD_LIBRARY_PATH is the only way, then how do I set it generically in CMakeLists.txt or conanfile.py?