Which was expanded to -Wl,-rpath,'$ORIGIN' and works perfectly.
Now I am trying to modernize my code and, based on the Professional CMake book, I replaced it with:
set(CMAKE_INSTALL_RPATH $ORIGIN)
But it seems that for some of the files it expands to -Wl,-rpath,:::::::, and I don’t understand why.
Here is a comparison of the flags before and after.
Should I do something special? Maybe put that line first or last, or add something? Should I put it for all the targets? Not sure how should I make it work
The variable which you’re using is used to pre-initialise the property INSTALL_RPATH when a target is created, so if you want to use the variable, you must set it before you create the targets to which it should apply. Alternatively, you can set the property on the targets directly (after you create them).
Second, note that the variable affects install RPATH; that is, RPATH that will be set by CMake as part of the install step (make install or equivalent). If you want to use the same RPATH also during the build, look into the property BUILD_WITH_INSTALL_RPATH, which can similarly be pre-initialised with variable CMAKE_BUILD_WITH_INSTALL_RPATH.
Now I am trying to make it work on macos also
this set(CMAKE_INSTALL_RPATH "@loader_path"), although it expands to -Wl,-rpath,"\$ORIGIN", the executable cannot find the libraries. Library not loaded: @rpath/libfile.dylib