[CMake] actually using cmake alternative to convenience libraries

Jack Stalnaker jack.stalnaker at gmail.com
Tue Nov 17 10:37:25 EST 2015


I'm trying to figure out the best way to handle something that was a
convenience lib under autotools. I realize that there's a FAQ entry here:

https://cmake.org/Wiki/CMake_FAQ#Does_CMake_support_.22convenience.22_libraries.3F

But its terse 2 paragraphs don't say how to actually do what it suggests.
My problem is this. I have this source tree:

lib
|--foo.c
|--foo.h
|--bar.c
|--bar.h
|--baz.c
src
|--goo.c

In lib, I need to somehow collectively refer to foo and bar. Okay, so I can
create a variable:

set(foobarSRCS foo.c bar.c)
set(foobarLIBS ${externalLibFound})

which is what the FAQ entry seems to suggest. However, this variable is not
visible to goo.c. Okay, so as an alternative, I can do this:

set(foobarSRCS foo.c bar.c PARENT_SCOPE), etc.

but now the variable is not visible to baz.c, which also must include the
srcs to create a module library called _baz! I can of course do something
like this:

set(foobarSRCSLOC foo.c bar.c)
set(foobarSRCS ${foobarSRCSLOC} PARENT_SCOPE)

but this feels dirty and repetitive.

I also realize that I can just create the variables in src, but that kind
of defeats the entire purpose of walling of the common libs and their
dependencies in the first place.

Is this the right way to work, or am I missing something simple?

--Jack
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151117/59d0e061/attachment.html>


More information about the CMake mailing list