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

Rolf Eike Beer eike at sf-mail.de
Thu May 12 09:34:09 EDT 2016


Am 2016-05-12 14:59, schrieb Brad King:
> 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?

The whole _pkg_search thing can go away, it's from an earlier version of 
the patch. This should work the same:

if (NOT flag MATCHES "^-l(.*)")
   continue()
endif()

find_library(${_prefix}-${CMAKE_MATCH_1}
              NAMES ${CMAKE_MATCH_1}
              ${_find_opts})
list(APPEND _libs "${${_prefix}-${CMAKE_MATCH_1}}")

Eike


More information about the cmake-developers mailing list