I use RUNTIME_DEPENDENCIES to copy all dlls. But it doesn’t find all. In particular, it doesn’t find postgresql dlls. They are on my PATH though.

Adding postgreql to the DIRECTORIES options gives me the lib directory, but I need the bin directory

Using $<TARGET_RUNTIME_DLLS:PostgreSQL::PostgreSQL> doesn’t work either. FindPostgresql.cmake does set IMPORTED_LOCATION, but also sets the target to UNKNOWN, so according to the documentation it is not considered.

Questions therefore are:

  • Is the PATH not considered by file(RUNTIME_DEPENDENCIES)? Can I change it
  • Why is the PostgreSQL::PostgreSQL target set to Unknown? Or why is it ignored by TARGET_RUNTIME_DLLS even though it has IMPORTED_LOCATION set

I could also not generate the RUNTIME_DEPENDENCIES as they are on the PATH anyway in this case, but how would I ignore all the dlls without listing each explicitly in POST_EXCLUDE_REGEXES as Postgresql as many dlls.

On an UNKNOWN library, the IMPORTED_LOCATION is the .lib file, not the DLL. There’s nowhere to put the DLL path on an UNKNOWN library. Someday I’d like to get back to this MR to help reduce the number of UNKNOWN imported libraries. The docs were updated recently to clarify this situation.

1 Like

So this is something that would need to be improved in the findPostgresql.cmake script?

What’s about my other question with the PATH. Why is it not considered for the file(RUNTIME_DEPENDENCIES) command?

CMake doesn’t know the name of the DLL to search for, so why would it look in PATH in the first place?

file(RUNTIME_DEPENDENCIES) doesn’t know the name of the DLL? How would that be possible?

At least if it doesn’t find a dll it tells me the exact name of the dll that is missing. So it has to know the dll name I assume?


install(TARGETS BeansServer COMPONENT Beans 
      PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
      POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"

Error Message:
file Could not resolve file libpq.dll

And this DLL is on the PATH. If I execute the executable generated by the target everything works fine.

Oh, file(GET_RUNTIME_DEPENDENCIES). For some reason, I kept reading it as the genex, sorry.

It doesn’t search PATH for the same reason that LD_LIBRARY_PATH and DYLD_LIBRARY_PATH are ignored on Linux and macOS. See this answer.

Wrong link? → Xcode indent settings?

So is there any solution to my problem? Do I need to hardcode the path to Postgresql dlls so that file(GET_RUNTIME_DEPENDENCIES) works on Windows? That’s not very nice :confused:

Yep, wrong clipboard; I’ve updated the link. I’d say that FindPostgreSQL should be improved to know that it found a SHARED or STATIC library. Then you can use $<TARGET_DIR> for the relevant targets to get the search paths.

1 Like