[CMake] Excluding targets from install set

Craig Scott craig.scott at crascit.com
Mon Sep 2 07:14:34 EDT 2019


On Tue, Jul 23, 2019 at 7:04 PM Gordon Koefner <gordon.koefner at vires.com>
wrote:

> Hi all!
>
> We have been migrating our buildsystem to CMake and are trying to use
> the `install` command to deploy different parts of the software.
> However `make install` also installs artifacts from our dependencies,
> internal as well as 3rd party, that are unnecessary/unwanted.
>
> Is there a native way to exclude certain subdirectories or build targets
> from the install set? The only solution I could think of is to manually
> add an option, e.g.:
>
> option(${TARGET_NAME}_INSTALL on "") # on by default
> if(${TARGET_NAME}_INSTALL)
>     install(...)
> endif()
>
> Maybe the culprit is also that we are using find_path and
> add_subdirectory to add any internal dependencies we have to the build
> tree - I am starting to think that this is a mistake.
>
> I have read about ExternalProject - but I am unsure whether this is the
> correct way to go about it but it does allow modification of another build.
>
> How do you guys solve this issue, how can I define which dependencies I
> want installed?
>
> I really want to avoid writing a shellscript to filter out any unwanted
> stuff.
>


A bit late, but clearing my inbox and found this one still unanswered. ;) I
typically handle this situation by defining install components for my own
part of the build (i.e. including COMPONENT options with my install()
commands). Then when I want to make packages, I populate
CPACK_COMPONENTS_ALL with just those components I want included. All
dependencies are part of the build (using FetchContent), it's just that I
don't add their install components to my list so they are left out. I don't
do a bare "make install", I always create packages, so this works for me.
If you did want to do an install directly, you could use the new "cmake
--install" functionality added in CMake 3.15 which supports specifying the
component to install. The end of the documentation page for the install()
command also shows another way to install components selectively (under the
heading Generated Installation Script).

-- 
Craig Scott
Melbourne, Australia
https://crascit.com

Get the hand-book for every CMake user: Professional CMake: A Practical
Guide <https://crascit.com/professional-cmake/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190902/51bd14e3/attachment.html>


More information about the CMake mailing list