I'm using CMake for a project and googletest for my test cases. Looking around the internet, it seems to be common practise to just copy the googletest source into a subfolder of your repository and include it with "add_subdirectory(googletest)". I did that.
Now I'm using CPack to generate debian packages for my project. Unfortunately, the packages generated by CPack install googletest alongside with my project. This is of course not what I want.
Looking in the googletest directory, I found some INSTALL cmake commands there, so it is clear, why it happens. The question is now - how can I avoid it? I don't like modifying the CMakeLists.txt files from googletest, because I would have to remember re-applying my modifications on an update. Is there another way to disable these installs in CPack?
If you don't need tests in your project's release (which you want to deliver with CPack), then include
googletest
subdirectory conditionally, and set conditional to false when packaging:packaging with
Alternatively, if you want tests, but don't want to install testing infrastructure, you may disable
install
command via defining macro or function with same name:This approach has also been suggested in CMake mailing.
So there is the macro option @Tsyvarev mentioned that was originally suggested here:
Note
${ARGV}
and${ARGN}
are the same but the docs currently suggest using${ARGN}
. Also the fact that macro-overwriting prepends_
to the original macro name is not documented, but it is still the behaviour. See the code here.However, I never got the above code to work properly. It does really weird things and often calls
install()
twice.An alternative - also undocumented - is to use
EXCLUDE_FROM_ALL
:According to some comment I found somewhere this disables
install()
for that subdirectory. I think what it actually does is setEXCLUDE_FROM_ALL
by default for all theinstall()
commands which also probably does what you want. I haven't really tested it, worth a shot though.A bit late reply, but I just spent too long a time figuring this out.
In the specific case of googletests, specifying this in your top level CMakeLists.txt does the trick.
I read on (I think) the CMake mailing list that making installation conditional on a
INSTALL_<package name>
inside your package is sort of a defacto standard (and one I'm certainly going to follow from now on!). But I can't find that link now.