Skip to content

FindPkgConfig: Fix IMPORTED_TARGET NO...PATH option handling

Calls to _pkg_create_imp_target() were being given values for its _no_cmake_path and _no_cmake_environment_path arguments which would always have evaluated to boolean true (all the call sites were passing the variable names instead of variable values). In addition, the internal handling of these options was incorrectly building up the find options as a single string rather than a list, resulting in every call to find_library() being given the string NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH which is interpreted as an additional library name to search for instead of two separate options to prevent default path locations. The result of this behaviour is that for any .pc file that was found, any NO_CMAKE_PATH or NO_CMAKE_ENVIRONMENT_PATH option would have been ignored in the search for the library when the IMPORTED_TARGET option was given.

The two test cases intended to test the logic of the NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH options do not use the IMPORTED_TARGET option, so the above problems were not being detected. This merge request updates the IMPORTED_TARGET test first in its own commit so that it is easy to verify that the problem is now caught. The second commit then contains the necessary fixes.

Merge request reports