<div dir="ltr"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">Hello,</span><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
Is there a convenient way to have CMake detect at build time additional libraries that need to be linked for an external project to work? For example, suppose I have</div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
<br></div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">ExternalProject_Add(Foo ...args...)</div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
which builds libfoo.a (which is an autotools package). Depending on the system on which libfoo is built, sometimes linking against it also requires -labc, and other times it requires -lxyz. For normal users of libfoo, it writes out a pkg-config file that sets an appropriate "Libs: ..." line. I'm trying to figure out how to handle this in CMake. Possible options:</div>
<div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">1. Have my project repeat the checks that libfoo does to discover whether -labc or -lxyz is required. This is clearly doable but doesn't seem like the right answer (duplicated checks, what if they change in the future, etc.).</div>
<div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">2. Use FindPkgConfig *after* Foo is built. I don't know if this is possible.</div>
<div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">3. Use file(STRINGS ...) on the .pc file that Foo writes out and parse out the Libs line "manually".</div>
<div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">Does anyone have any suggestions on the right thing to do here?</div>
<div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">Thanks,</div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
John</div></div>