I did actually get that working.<div><br></div><div>However, I also found a _much simpler_ way of doing this.</div><div><br></div><div>In liba/CMakeLists.txt:</div><div><br></div><div><div># Self</div><div>set(A_INCLUDE_DIRS ${A_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/include")</div>
<div>set(A_LIBRARIES ${A_LIBRARIES} "${PROJECT_BINARY_DIR}/liba.a")</div><div><br></div><div># Libpng</div><div>FIND_PACKAGE(libpng REQUIRED)</div><div>set(A_INCLUDE_DIRS ${A_INCLUDE_DIRS} ${LIBPNG_INCLUDE_DIRS})</div>
<div>set(A_LIBRARIES ${A_LIBRARIES} ${LIBPNG_LIBRARIES})</div><div><br></div><div>ADD_LIBRARY(a ${SOURCES})</div><div><br></div><div># Includes</div><div>INCLUDE_DIRECTORIES(${A_INCLUDE_DIRS})</div><div><br></div><div># Allow other projects to use this</div>
<div>configure_file(<a href="http://AConfig.cmake.in">AConfig.cmake.in</a> "${PROJECT_BINARY_DIR}/AConfig.cmake")</div></div><div><br></div><div>In liba/AConfig.cmake:</div><div><div>set(A_LIBRARIES @A_LIBRARIES@)</div>
<div>set(A_INCLUDE_DIRS @A_INCLUDE_DIRS@)</div><div><br></div><div>In dummy/CMakeLists.txt:</div><div>FIND_PACKAGE(A REQUIRED)</div><div>INCLUDE_DIRECTORIES(${A_INCLUDE_DIRS})</div><div>TARGET_LINK_LIBRARIES(dummy ${A_LIBRARIES})</div>
<div><br></div><div>This yields an AConfig.cmake that reads:</div><div><div>set(A_LIBRARIES /home/doug/projects/dummy/deps/liba/build/liba.a;/usr/lib/libpng.so)</div><div>set(A_INCLUDE_DIRS /home/doug/projects/dummy/deps/liba/include;/usr/include)</div>
</div><div><br></div><div>And a verbose compile that reads:</div><div>/usr/bin/gcc -std=c99 -g CMakeFiles/dummy.dir/src/main.c.o -o dummy -rdynamic ../deps/liba/build/liba.a -lpng </div><div> </div>
</div><div>Which is exactly what I was looking for.</div><div><br></div><div>I'm sure there are lots of things wrong with this (specifically; installing won't work) but for a library that is never going to installed, it's great.</div>
<div><br></div><div>Thanks for all your help~</div><div><br></div><div>Cheers,</div><div>Doug.<br><br><div class="gmail_quote">On Sat, Aug 13, 2011 at 3:35 PM, Michael Wild <span dir="ltr"><<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Sat 13 Aug 2011 03:55:06 AM CEST, Doug wrote:<br>
> I see.<br>
><br>
> I've tried this approach and I get the error:<br>
> -- Found LIBPNG<br>
> CMake Error at CMakeLists.txt:49 (export):<br>
> export given target "/usr/lib/libpng.so" which is not built by this<br>
> project.<br>
><br>
><br>
> -- Configuring incomplete, errors occurred!<br>
><br>
> ~<br>
> Doug.<br>
><br>
> On Fri, Aug 12, 2011 at 4:57 PM, Michael Wild <<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a><br>
</div><div class="im">> <mailto:<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>>> wrote:<br>
><br>
> On Fri 12 Aug 2011 10:49:45 AM CEST, Doug wrote:<br>
> > I'm sorry if I'm being dumb here, but I fail to see how that helps.<br>
> ><br>
> > That example is one where foobar depends explicitly on foo and bar.<br>
> ><br>
> > What if foo depends on bar2?<br>
> ><br>
> > How do I inherit that dependency from foo in foobar?<br>
> ><br>
> > _that's_ what I'm looking for.<br>
> ><br>
> > (If that example somehow explains that, I'm sorry, I can't see it. Can<br>
> > you point to a specific point in the page?)<br>
> ><br>
> > ~<br>
> > Doug.<br>
> ><br>
> > On Fri, Aug 12, 2011 at 2:34 PM, Michael Wild <<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a><br>
> <mailto:<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>><br>
</div><div class="im">> > <mailto:<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a> <mailto:<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>>>> wrote:<br>
> ><br>
> > If the projects are independent, you might want to take a look<br>
> at this<br>
> > Wiki page:<br>
> ><br>
> <a href="http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file" target="_blank">http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file</a>.<br>
> ><br>
> > HTH<br>
> ><br>
> > Michael<br>
> ><br>
><br>
> And that is what the example is *about*. The FooBar project *exports*<br>
> its targets, along with their dependencies, so that when other projects<br>
> do find_package(FooBar), they will be able to link against the foo<br>
> library without having to know any of the dependencies of it. E.g. the<br>
> project "hello" might look like this:<br>
><br>
> project(hello)<br>
> find_package(FooBar REQUIRED)<br>
> include_directories(${FOOBAR_INCLUDE_DIRS})<br>
> add_executable(hello hello.c)<br>
> target_link_libraries(hello ${FOOBAR_LIBRARIES})<br>
><br>
><br>
> Michael<br>
<br>
</div>Did you do something like this?<br>
<br>
export(TARGETS /usr/lib/libpng.so)<br>
<br>
That would be wrong... You do it like this<br>
<br>
find_package(PNG REQUIRED)<br>
add_library(foo SHARED foo.c)<br>
target_link_libraries(foo ${PNG_LIBRARIES})<br>
install(TARGETS foo EXPORT FooLibraryDepends<br>
RUNTIME DESTINATION bin<br>
LIBRARY DESTINATION lib)<br>
export(TARGETS foo FILE "${PROJECT_BINARY_DIR}/FooLibraryDepends.cmake")<br>
<font color="#888888"><br>
<br>
Michael<br>
</font></blockquote></div><br></div>