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