[CMake] Disabling INSTALL target for subdirectory

Craig Scott craig.scott at crascit.com
Thu Feb 16 02:29:18 EST 2017


You can use the COMPONENT option to install() for your own project and then
select a component-based package if you are packaging with CPack. We
currently do this with builds that incorporate other projects with
add_subdirectory() similar to your case.

If you are using install as a build target (ie make install or equivalent),
I don't think the above will help you. I don't recall if the
EXCLUDE_FROM_ALL option to add_subdirectory() affects install or not. I
believe there was some discussion about this in one of the mailing lists or
gitlab issues recently, so maybe someone else can chime in to clarify this
part.


On Thu, 16 Feb 2017 at 3:59 pm, Milan Ziegler <milan at fastmail.com> wrote:

> Hi,
>
> we are using the CMake install mechanism "install(...)" to copy all
> relevant files and target binaries of the product into the CMake install
> prefix folder, for further packaging. So far so good.
>
> We are also using several thirdparty libraries, hosting them inside our
> own repository and building them along with our own code, usually using
> add_subdirectory utilizing their native CMake buildsystem.
>
> Turns out, other developers also like the CMake install mechanism.
>
> So now the INSTALL target of our whole project also installs thirdparty
> components, which we do not want to deliver with our own product (think
> static libraries, which are already linked into our executable).
>
> After a lot of googling, here's my question: Is there a clean way to
> disable the install target for a subdirectory _without_ also disabling
> it completely for the remaining project?
>
> What we already tried:
> * Setting CMAKE_INSTALL_PREFIX to a temporary directory for the
> subdirectory (doesn't work)
> * "function(install) endfunction()" to disable the install function for
> the subdirectory (breaks CMake in hilarious ways)
>
> What we now do:
> Using a custom target, we patch the cmake_install.cmake files in the
> build directories before installing (works, but it's an  abomination of
> a hack)
>
> Any help? I think it's a valid usecase for CMake but there doesn't seem
> to be an easy way to do it.
>
> We are using CMake 3.5.
>
>
> Thank you :)
>
> --
>   Milan
>   milan at fastmail.com
> --
>
> 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

-- 
Craig Scott
Melbourne, Australia
https://crascit.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170216/dfa01830/attachment-0001.html>


More information about the CMake mailing list