[cmake-developers] [Patch] FindPkgConfig: optionally create imported target for the found libraries

Brad King brad.king at kitware.com
Thu May 12 08:59:18 EDT 2016


On 05/11/2016 05:52 PM, Rolf Eike Beer wrote:
> It has always nagged me that the FindPkgConfig module requires people to use 
> link_directories(). Now I created a new optional mode for pkg_check_modules() 
> and pkg_search_modules() which will search the absolute paths of the libraries 
> that are returned by pkg-config, and create an imported target from that 
> information that also contains defines and include directories. It restricts 
> searching to the directories returned by pkg-config, if none are given the 
> normal search rules are used. I have manually tested this and it seems to 
> work. Please have a look and tell me if I have missed something before I put 
> this into next.

Great!  I've long wanted to see this done.

> +    if (flag MATCHES "^-l(.*)")
> +      set(_pkg_search "${CMAKE_MATCH_1}")
> +    else()
> +      continue()
> +    endif()
> +
> +    find_library(${_prefix}-${CMAKE_MATCH_1}
> +                 NAMES ${CMAKE_MATCH_1}
> +                 ${_find_opts})
> +    list(APPEND _libs "${${_prefix}-${CMAKE_MATCH_1}}")

Shouldn't these latter ${CMAKE_MATCH_1} references use ${_pkg_search} instead?

Thanks,
-Brad



More information about the cmake-developers mailing list