When called with the IMPORTED_TARGET argument, the command pkg_check_modules in the module FindPkgConfig creates an interface library. From the code of FindPkgConfig.cmake:
What is the point of making this an interface library? Why not just create an imported library? Making an interface library is inconvenient because we cannot link it to another target with the PRIVATE keyword.
I know that netcdf-fortran has a private dependency on another library, netcdf-c. So I am tempted to find netcdf-c (I have a find module for it) and declare this dependency:
Just append to its INTERFACE_LINK_LIBRARIES property. IMPORTED targets don’t support being on the left-hand side of target_* commands anyways (INTERFACE or not).
Eh, you sure an imported library can’t be on the left-hand side of target_*() commands with INTERFACE? It seems to be permitted with the following small test project:
I confirm what Craig Scott said. Putting the imported pkg-config target on the left-hand side of target_link_libraries with the INTERFACE keyword seems to work. Also when I try to replace INTERFACE by PRIVATE, the error message is:
INTERFACE library can only be used with the INTERFACE keyword of
target_link_libraries
So it does not say that the problem lies with the IMPORTED property.
Huh. I remember wanting to do that long ago and ended up just using the property modifications directly. Guess something changed at some point? Anyways, yes, INTERFACE is limited to INTERFACE usage requirements; it makes no sense to have PRIVATE or PUBLIC links because there’s the former is completely useless (for non-STATIC libraries, but then if you use $<LINK_ONLY> and you’re the same there too) and the latter is equivalent to INTERFACE since there’s no “self” to apply it to anyways.
Looking back at release notes, this functionality was added in CMake 3.11.