[CMake] Sub dependencies?

Doug douglas.linder at gmail.com
Sun Aug 14 21:10:50 EDT 2011


I did actually get that working.

However, I also found a _much simpler_ way of doing this.

In liba/CMakeLists.txt:

# Self
set(A_INCLUDE_DIRS ${A_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/include")
set(A_LIBRARIES ${A_LIBRARIES} "${PROJECT_BINARY_DIR}/liba.a")

# Libpng
FIND_PACKAGE(libpng REQUIRED)
set(A_INCLUDE_DIRS ${A_INCLUDE_DIRS} ${LIBPNG_INCLUDE_DIRS})
set(A_LIBRARIES ${A_LIBRARIES} ${LIBPNG_LIBRARIES})

ADD_LIBRARY(a ${SOURCES})

# Includes
INCLUDE_DIRECTORIES(${A_INCLUDE_DIRS})

# Allow other projects to use this
configure_file(AConfig.cmake.in "${PROJECT_BINARY_DIR}/AConfig.cmake")

In liba/AConfig.cmake:
set(A_LIBRARIES @A_LIBRARIES@)
set(A_INCLUDE_DIRS @A_INCLUDE_DIRS@)

In dummy/CMakeLists.txt:
FIND_PACKAGE(A REQUIRED)
INCLUDE_DIRECTORIES(${A_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(dummy ${A_LIBRARIES})

This yields an AConfig.cmake that reads:
set(A_LIBRARIES
/home/doug/projects/dummy/deps/liba/build/liba.a;/usr/lib/libpng.so)
set(A_INCLUDE_DIRS /home/doug/projects/dummy/deps/liba/include;/usr/include)

And a verbose compile that reads:
/usr/bin/gcc  -std=c99 -g   CMakeFiles/dummy.dir/src/main.c.o  -o dummy
-rdynamic ../deps/liba/build/liba.a -lpng

Which is exactly what I was looking for.

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.

Thanks for all your help~

Cheers,
Doug.

On Sat, Aug 13, 2011 at 3:35 PM, Michael Wild <themiwi at gmail.com> wrote:

> On Sat 13 Aug 2011 03:55:06 AM CEST, Doug wrote:
> > I see.
> >
> > I've tried this approach and I get the error:
> > -- Found LIBPNG
> > CMake Error at CMakeLists.txt:49 (export):
> >   export given target "/usr/lib/libpng.so" which is not built by this
> >   project.
> >
> >
> > -- Configuring incomplete, errors occurred!
> >
> > ~
> > Doug.
> >
> > On Fri, Aug 12, 2011 at 4:57 PM, Michael Wild <themiwi at gmail.com
> > <mailto:themiwi at gmail.com>> wrote:
> >
> >     On Fri 12 Aug 2011 10:49:45 AM CEST, Doug wrote:
> >     > I'm sorry if I'm being dumb here, but I fail to see how that helps.
> >     >
> >     > That example is one where foobar depends explicitly on foo and bar.
> >     >
> >     > What if foo depends on bar2?
> >     >
> >     > How do I inherit that dependency from foo in foobar?
> >     >
> >     > _that's_ what I'm looking for.
> >     >
> >     > (If that example somehow explains that, I'm sorry, I can't see it.
> Can
> >     > you point to a specific point in the page?)
> >     >
> >     > ~
> >     > Doug.
> >     >
> >     > On Fri, Aug 12, 2011 at 2:34 PM, Michael Wild <themiwi at gmail.com
> >     <mailto:themiwi at gmail.com>
> >     > <mailto:themiwi at gmail.com <mailto:themiwi at gmail.com>>> wrote:
> >     >
> >     >     If the projects are independent, you might want to take a look
> >     at this
> >     >     Wiki page:
> >     >
> >
> http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file
> .
> >     >
> >     >     HTH
> >     >
> >     >     Michael
> >     >
> >
> >     And that is what the example is *about*. The FooBar project *exports*
> >     its targets, along with their dependencies, so that when other
> projects
> >     do find_package(FooBar), they will be able to link against the foo
> >     library without having to know any of the dependencies of it. E.g.
> the
> >     project "hello" might look like this:
> >
> >     project(hello)
> >     find_package(FooBar REQUIRED)
> >     include_directories(${FOOBAR_INCLUDE_DIRS})
> >     add_executable(hello hello.c)
> >     target_link_libraries(hello ${FOOBAR_LIBRARIES})
> >
> >
> >     Michael
>
> Did you do something like this?
>
> export(TARGETS /usr/lib/libpng.so)
>
> That would be wrong... You do it like this
>
> find_package(PNG REQUIRED)
> add_library(foo SHARED foo.c)
> target_link_libraries(foo ${PNG_LIBRARIES})
> install(TARGETS foo EXPORT FooLibraryDepends
>  RUNTIME DESTINATION bin
>  LIBRARY DESTINATION lib)
> export(TARGETS foo FILE "${PROJECT_BINARY_DIR}/FooLibraryDepends.cmake")
>
>
> Michael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110815/8a1a4bf4/attachment.htm>


More information about the CMake mailing list