<div dir="ltr">You most likely want to use the <a href="https://cmake.org/cmake/help/latest/module/FindPkgConfig.html">FindPkgConfig</a> module and also use the IMPORTED_TARGET option with the commands provided therein.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 27, 2018 at 11:19 PM, suzuki toshiya <span dir="ltr"><<a href="mailto:mpsuzuki@hiroshima-u.ac.jp" target="_blank">mpsuzuki@hiroshima-u.ac.jp</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I'm looking for 2 features to generate pkg-config pc files.<br>
I already wrote something, but some experts advised that there<br>
would be many people trying to do such, and there might be existing<br>
solution. If such functions are already included in cmake's<br>
official modules, please let me know. Of course, combination<br>
of existing functions would be OK.<br>
<br>
function 1)<br>
-----------<br>
<br>
...is trying to find an available pkg-config module name from a<br>
list of several candidates. the typical usecase would be a<br>
search of libjpeg by pkg-config (libjpeg? libjpeg8? libjpeg8-turbo?<br>
libjpeg9? libjpeg62? ...). getting a name of module is important<br>
to write "Require" variable of pc file.<br>
<br>
there is already pkg_search_module() searching an available module<br>
from a list, but it does not return the name of found module.<br>
thus it cannot help to write "Require" variable.<br>
<br>
what I wrote is something like this.<br>
<br>
#<br>
# PKG_SEARCH_AVAILABLE_MODULE([<wbr>var-name-of-found-module] [modules])<br>
#<br>
# there is pkg_search_module(), but it does not clarify<br>
# which module was found.<br>
#<br>
# this function does not set xxx_CFLAGS xxx_LIBS etc.<br>
#<br>
# use like:<br>
# PKG_SEARCH_AVAILABLE_MODULE(<wbr>PC_LIBJPEG<br>
"libjpeg;libjpeg8-turbo;<wbr>libjpeg8;libjpeg9;libjpeg62")<br>
#<br>
function(PKG_SEARCH_AVAILABLE_<wbr>MODULE _found_pkg pkg_list)<br>
set(_PKG_FOUND FALSE)<br>
foreach(_pkg IN LISTS pkg_list)<br>
pkg_check_modules(_PKG "${_pkg}")<br>
if (_PKG_FOUND)<br>
set("${_found_pkg}_FOUND" TRUE PARENT_SCOPE)<br>
set("${_found_pkg}_MODULE_<wbr>NAME" "${_pkg}" PARENT_SCOPE)<br>
return()<br>
endif()<br>
endforeach(_pkg)<br>
endfunction(PKG_SEARCH_<wbr>AVAILABLE_MODULE)<br>
<br>
function 2)<br>
-----------<br>
...makes something like LDFLAGS + LIBS from the pathnames of libraries.<br>
some library finders of cmake do not return "-L/xxx -lyyy" values<br>
but returns "/xxx/libyyy.so". pkg-config has some difficulties<br>
to hold such raw pathnames of the libraries (e.g. pkg-config<br>
use "Libs" variable for both of static and shared linking,<br>
thus having "libxxx.a" or "libxxx.so" explicitly is not good),<br>
so, the translation from "/xxx/libyyy.so" to "-L/xxx -lyyy".<br>
<br>
what I wrote is something like this:<br>
<br>
#<br>
# MAKE_LDFLAGS_FROM_LIBPATH([<wbr>var-ldflags+libs] [libpath])<br>
#<br>
function(MAKE_LDFLAGS_FROM_<wbr>LIBPATHS _ldflags _libpaths)<br>
foreach(_libpath IN LISTS _libpaths)<br>
string(REGEX REPLACE "/[^/]*$" "" _libdir "${_libpath}")<br>
<br>
string(REGEX REPLACE "^.*/" "" _lib "${_libpath}")<br>
string(REGEX REPLACE<br>
"(\\${CMAKE_STATIC_LIBRARY_<wbr>SUFFIX}|\\${CMAKE_SHARED_<wbr>LIBRARY_SUFFIX})$" "" _lib<br>
"${_lib}")<br>
string(REGEX REPLACE "^lib" "" _lib "${_lib}")<br>
<br>
set(__ldflags "${__ldflags} ${CMAKE_LIBRARY_PATH_FLAG}${_<wbr>libdir}<br>
${CMAKE_LINK_LIBRARY_FLAG}${_<wbr>lib}")<br>
endforeach(_libpath)<br>
set("${_ldflags}" "${__ldflags}" PARENT_SCOPE)<br>
endfunction(MAKE_LDFLAGS_FROM_<wbr>LIBPATH)<br>
<br>
Regards,<br>
mpsuzuki<br>
<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/<wbr>listinfo/cmake</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div></div></div></div></div></div></div>
</div>