[CMake] COMPONENT question
iosif neitzke
iosif.neitzke+cmake at gmail.com
Mon Oct 31 13:57:41 EDT 2016
On 10/31/2016 11:42 AM, Dave Flogeras wrote:
> Hi, are static libraries able to be added to a component?
Yes!
>
> The following minimal example doesn't work as I expected:
>
> CMAKE_MINIMUM_REQUIRED( VERSION 3.0.0 )
> PROJECT( foo )
>
> ADD_LIBRARY( foo foo.c )
> INSTALL( TARGETS foo ARCHIVE DESTINATION lib
> RUNTIME DESTINATION bin
> LIBRARY DESTINATION bin
> COMPONENT bar )
>
> INCLUDE( CPack )
>
> If I run "make list_install_components" it says "Unspecified"
>
> However, if I add "SHARED" to the ADD_LIBRARY call (or set
> BUILD_SHARED_LIBS), it lists the component as "bar" which is what I'd
> expect.
>
Try something like:
INSTALL( TARGETS foo ARCHIVE DESTINATION lib COMPONENT bar
RUNTIME DESTINATION bin COMPONENT bar
LIBRARY DESTINATION bin COMPONENT bar )
The nesting of brackets "[]" in docs [0], requires a COMPONENT keyword
and argument (should you choose to use components) for each kind of
target file keyword (ARCHIVE, RUNTIME, LIBRARY, etc..) you use.
I believe you get the puzzling behavior varying with STATIC versus
SHARED library type because of the way the command is parsed. When
building a STATIC library, there is only an ARCHIVE, which has no
COMPONENT listed, so you get "Unspecified" when listing components.
When building a SHARED library on non-DLL platforms, the binary is a
LIBRARY target, which has the COMPONENT "bar" listed.
Each kind of target file keyword (ARCHIVE, RUNTIME, LIBRARY, etc..) has
its own list of subsequent properties.
[0]
https://cmake.org/cmake/help/v3.7/command/install.html#installing-targets
[1] example in ParaView:
https://github.com/Kitware/ParaView/blob/6714c5c4d1e643f451421dd1004d9540d8607524/CMakeLists.txt#L710
> Is this a bug, or by design? I'm attempting to figure out how I can
> separate shared/static libraries in my project for different install
> types. For example, if I am packaging a binary only install, I don't
> need to install static libraries, but I would need the runtime libraries.
>
> Dave
>
>
More information about the CMake
mailing list