[CMake] looking for 2 features to help pkg-config pc files

P F pfultz2 at yahoo.com
Thu Mar 29 20:08:44 EDT 2018


The BCM(boost cmake modules) has `bcm_auto_pkgconfig` which will generate the pkgconfig file from a target, including the “Require” variable:

http://bcm.readthedocs.io/en/latest/src/BCMPkgConfig.html#bcm-auto-pkgconfig <http://bcm.readthedocs.io/en/latest/src/BCMPkgConfig.html#bcm-auto-pkgconfig>

It utilizes the `INTERFACE_PKG_CONFIG_NAME` property to generate the pkgconfig names for the dependent targets:

http://bcm.readthedocs.io/en/latest/src/BCMProperties.html#interface-pkg-config-name <http://bcm.readthedocs.io/en/latest/src/BCMProperties.html#interface-pkg-config-name>

Currently, it doesn't coordinate with FindPkgConfig’s imported targets yet, so you will need to manually inject the name. However, when using `bcm_auto_export` it will export the property, so that when users finds the dependency with `find_package`, it knows the corresponding pkgconfig module.

> On Mar 27, 2018, at 7:19 AM, suzuki toshiya <mpsuzuki at hiroshima-u.ac.jp <mailto:mpsuzuki at hiroshima-u.ac.jp>> wrote:
> 
> Hi all,
> 
> I'm looking for 2 features to generate pkg-config pc files.
> I already wrote something, but some experts advised that there
> would be many people trying to do such, and there might be existing
> solution. If such functions are already included in cmake's
> official modules, please let me know. Of course, combination
> of existing functions would be OK.
> 
> function 1)
> -----------
> 
> ...is trying to find an available pkg-config module name from a
> list of several candidates. the typical usecase would be a
> search of libjpeg by pkg-config (libjpeg? libjpeg8? libjpeg8-turbo?
> libjpeg9? libjpeg62? ...). getting a name of module is important
> to write "Require" variable of pc file.
> 
> there is already pkg_search_module() searching an available module
> from a list, but it does not return the name of found module.
> thus it cannot help to write "Require" variable.
> 
> what I wrote is something like this.
> 
> #
> # PKG_SEARCH_AVAILABLE_MODULE([var-name-of-found-module] [modules])
> #
> # there is pkg_search_module(), but it does not clarify
> # which module was found.
> #
> # this function does not set xxx_CFLAGS xxx_LIBS etc.
> #
> # use like:
> # PKG_SEARCH_AVAILABLE_MODULE(PC_LIBJPEG
> "libjpeg;libjpeg8-turbo;libjpeg8;libjpeg9;libjpeg62")
> #
> function(PKG_SEARCH_AVAILABLE_MODULE _found_pkg pkg_list)
>  set(_PKG_FOUND FALSE)
>  foreach(_pkg IN LISTS pkg_list)
>    pkg_check_modules(_PKG "${_pkg}")
>    if (_PKG_FOUND)
>      set("${_found_pkg}_FOUND" TRUE PARENT_SCOPE)
>      set("${_found_pkg}_MODULE_NAME" "${_pkg}" PARENT_SCOPE)
>      return()
>    endif()
>  endforeach(_pkg)
> endfunction(PKG_SEARCH_AVAILABLE_MODULE)
> 
> function 2)
> -----------
> ...makes something like LDFLAGS + LIBS from the pathnames of libraries.
> some library finders of cmake do not return "-L/xxx -lyyy" values
> but returns "/xxx/libyyy.so". pkg-config has some difficulties
> to hold such raw pathnames of the libraries (e.g. pkg-config
> use "Libs" variable for both of static and shared linking,
> thus having "libxxx.a" or "libxxx.so" explicitly is not good),
> so, the translation from "/xxx/libyyy.so" to "-L/xxx -lyyy".
> 
> what I wrote is something like this:
> 
> #
> # MAKE_LDFLAGS_FROM_LIBPATH([var-ldflags+libs] [libpath])
> #
> function(MAKE_LDFLAGS_FROM_LIBPATHS _ldflags _libpaths)
>  foreach(_libpath IN LISTS _libpaths)
>    string(REGEX REPLACE "/[^/]*$" "" _libdir "${_libpath}")
> 
>    string(REGEX REPLACE "^.*/" "" _lib "${_libpath}")
>    string(REGEX REPLACE
> "(\\${CMAKE_STATIC_LIBRARY_SUFFIX}|\\${CMAKE_SHARED_LIBRARY_SUFFIX})$" "" _lib
> "${_lib}")
>    string(REGEX REPLACE "^lib" "" _lib "${_lib}")
> 
>    set(__ldflags "${__ldflags} ${CMAKE_LIBRARY_PATH_FLAG}${_libdir}
> ${CMAKE_LINK_LIBRARY_FLAG}${_lib}")
>  endforeach(_libpath)
>  set("${_ldflags}" "${__ldflags}" PARENT_SCOPE)
> endfunction(MAKE_LDFLAGS_FROM_LIBPATH)
> 
> Regards,
> mpsuzuki
> 
> -- 
> 
> Powered by www.kitware.com <http://www.kitware.com/>
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ <http://www.cmake.org/Wiki/CMake_FAQ>
> 
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
> 
> CMake Support: http://cmake.org/cmake/help/support.html <http://cmake.org/cmake/help/support.html>
> CMake Consulting: http://cmake.org/cmake/help/consulting.html <http://cmake.org/cmake/help/consulting.html>
> CMake Training Courses: http://cmake.org/cmake/help/training.html <http://cmake.org/cmake/help/training.html>
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html <http://www.kitware.com/opensource/opensource.html>
> 
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake <https://cmake.org/mailman/listinfo/cmake>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180329/025e23b4/attachment.html>


More information about the CMake mailing list