Skip to content

FindPkgConfig pkg_check_modules() does not create imported target if module properties are empty

Consider this line: https://gitlab.kitware.com/cmake/cmake/blob/6f7b68e7f969ae39622492b27a6f4bbb79d25117/Modules/FindPkgConfig.cmake#L227

If all module properties returned by pkg-config are empty, the imported target isn't created. However, this still can happen for valid PkgConfig modules. Such an example is HexChat's hexchat-plugin.pc:

prefix=@prefix@
exec_prefix=${prefix}
includedir=@includedir@
hexchatlibdir=@hexchatlibdir@

Name: HexChat plugins
Description: Header and path for HexChat plugins
Version: @VERSION@
Cflags: -I${includedir}

When configured with @includedir@=/usr/include and used with pkgconf, the output of pkg-config --cflags --libs hexchat-plugin is empty, because pkgconf omits the default system paths (see the --keep-system-cflags option).

This doesn't mean that the output will be empty on other systems with different configurations, however, the above imported target check prevents writing CMake code that just links the imported library without additional ifs.

I suggest that if the user specifies IMPORTED_TARGET when calling pkg_check_modules(), then the target is always created, even when there are no explicit modules properties.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information