install(TARGETS): Installing only some artifact types
Hi,
I have an external lib that I'm building using add_subdirectory(externallib)
.
I want to install only the runtime dependencies that my application needs, so only DLLs and .so files but not static libraries archives.
So I'm doing this:
add_subdirectory(externallib)
# When building the library as a shared library, we want the RUNTIME lib, but we never want the static lib.
# So install only the shared lib
install(TARGETS externallib
RUNTIME # DLLs
LIBRARY # .so
# ARCHIVE is not set here as we don't want to install static libs
)
But when running the install target, the externallib's static library file (externallib.lib
) is still installed even if ARCHIVE
is not mentioned in the install(TARGETS) of the root CMakeLists.txt
.
When moving the install(TARGETS) code without modification to the externallib/CMakeLists.txt, CMake doesn't install the static lib (externallib.lib
) as expected.
See attachment for a small test case that reproduce the issue: install_target_test.zip
This is using CMake v3.23.2.
Edited by Brad King