setting generated shared library path for client


When “installing” a shared library target, is there a special way to declare the resulting .so/.dll path.
So far I manage it like my static libraries and, at least on windows/mingw/make, my client code using the dll compiles but when I try to execute it, It crashes with a dll-no-found error.
My workaround is to add the .so/.dll directory to the user path but its not practical if I install each .so/.dll in its own dir.
Is there another way or the solution is to pack all my produced .so/.dll into a single directory (/usr/lib, or a single custom directory added to system path) ?

NB By “installing” I mean creating a MyTargetConfig.cmake file and MyTargetTargetsxxx.cmake files

PS I realize that I will need a way to distinguish between the different configurations (debug/release) of the shared library, issue that does not exist with static lib as I can use different paths for different configurations. How to be sure that, say, client.exe in debug will use the debug version of and the release on will use the release version.
I’m currently failing to find a tutorial that covers completely these questions

Typically you use install(RUNTIME DESTINATION) and/or CMAKE_RUNTIME_OUTPUT_DIRECTORY to put .dll files into the same place.

Hi, thanks for your answer,

If I understand you well, you’re recommanding to put all my dlls into a single reserved directory, that I must, therefore, add to my path?

In this case, is there a way, within, CMAKE, to (permanently) this this path into the environment path user variable?


You could write a script that does the necessary. I presume it has to do something with the registry, but I don’t know. If it is, CMake has some support for reading the registry, but I don’t think writing is exposed.