[CMake] exclude a dependency from export

Jack Stalnaker jack.stalnaker at gmail.com
Fri Jan 22 14:38:50 EST 2016


I've found several workarounds, though I'm not sure of the long term
ramifications.

1. I can "install" library A to CMAKE_CURRENT_BINARY_DIR effectively doing
nothing. Since A is never referenced, only consumed, this should be okay?

2. I can remove the export from both A's and B's install, and simply not
include the target.cmake file in my package config prototype. I can just
include my targets as variables the same way a FindXXX.cmake file does.
Makes the syntax slightly uglier in that you cannot refer to B by target
name. It also might break the expectations of a user who thinks a package
should include target names.

I've started several discussions here on convenience libraries, and I think
I'm starting to realize the Cmake team has a different definition than I
do. To me, a convenience lib is not just an archived collection of sources.
The convenience lib is already linked to any external libs and already was
compiled with any special flags--in essence it's fully cooked. The nice
thing about this is that it keeps all the details specific to that part of
the code confined to that code's place on disc and that part of the code's
CMakeLists.txt. Object libraries and source list variables require that
other information to be passed around as well, leaking the convenience
lib's requirements all over the code tree. You could argue that that means
A should be a plain old library, then, but installing it serves no purpose.
It will like never be referenced outside of the code tree, and it pollutes
the system library folder.



On Fri, Jan 22, 2016 at 1:20 PM, Jack Stalnaker <jack.stalnaker at gmail.com>
wrote:

> Private doesn't work because the names in A need to be part of the public
> interface.
>
> On Fri, Jan 22, 2016 at 11:51 AM, Nicholas Braden <
> nicholas11braden at gmail.com> wrote:
>
>> Have you tried using the PRIVATE keyword when linking to A?
>>
>> https://cmake.org/cmake/help/latest/command/target_link_libraries.html#libraries-for-a-target-and-or-its-dependents
>>
>> On Fri, Jan 22, 2016 at 9:14 AM, Jack Stalnaker <omnijack at gmail.com>
>> wrote:
>> > Is there any way to exclude a dependency from an export? If I build a
>> static
>> > library target "A" but do not wish to install it, and then link that
>> target
>> > to another target "B" using target_link_libraries(B A), and then
>> attempt to
>> > export B, I get the error message:
>> >
>> > install (EXPORT "B" ...) includes target "B" which requires target "A"
>> that
>> > is not in the export set.
>> >
>> > I can solve the problem by installing A, but there is no need to. It is
>> a
>> > temporary target that is statically linked. I just need to export for
>> > creating a package config file, so there's no need for the package
>> config to
>> > ever need to worry about statically linked libraries.
>> >
>> > Is there a workaround for this?
>> >
>> > Long story short, I am trying to replicate convenience libraries from
>> > autotools. I'm having a hell of time doing it. I can use lists of
>> sources,
>> > but that requires passing around global variables that include the
>> sources
>> > and others that include the required libraries. This is far messier and
>> far
>> > less convenient. I've tried object libraries, and while they eliminate
>> the
>> > global source variables and prevent rebuilding things, they fail when
>> the
>> > source is nested, and you want to build a "super library" from smaller
>> > object libraries, which I believe is a fairly common working pattern.
>> > Building a static library that is never installed works really well ...
>> > until I go to create a package config file. Then this export fails.
>> >
>> > Thanks,
>> > --Jack
>> >
>> > --
>> >
>> > Powered by www.kitware.com
>> >
>> > Please keep messages on-topic and check the CMake FAQ at:
>> > http://www.cmake.org/Wiki/CMake_FAQ
>> >
>> > Kitware offers various services to support the CMake community. For more
>> > information on each offering, please visit:
>> >
>> > CMake Support: http://cmake.org/cmake/help/support.html
>> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> > CMake Training Courses: http://cmake.org/cmake/help/training.html
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://public.kitware.com/mailman/listinfo/cmake
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160122/d59dcc86/attachment.html>


More information about the CMake mailing list