[CMake] Disabling INSTALL target for subdirectory

Milan Ziegler milan at fastmail.com
Thu Feb 16 01:59:48 EST 2017


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


More information about the CMake mailing list