rapidcheck icon indicating copy to clipboard operation
rapidcheck copied to clipboard

Give parent projects better control over cmake install

Open david-pikas opened this issue 4 months ago • 0 comments

Rationale

Right now rapidcheck uses cmake install functionality to install some files. This isn't always desirable, for example if someone includes rapidcheck in their project with cmakes add_subdirectory, this will cause rapidcheck to be installed alongside their files. Projects including rapidcheck might not want to install rapidcheck since testing is often only relevant for people working on that project, and not their consumers. Additionally, this also includes rapidcheck in packages generated with cpack.

Currently this can be worked around by re-defining install before including rapidcheck to a no-op and then setting it to the default value, however this is rather hacky and will break if the parent project doesn't use the standard install. ~~One can also use the EXCLUDE_FROM_ALL keyword argument when including rapidcheck, but this will also change when rapidcheck is built and not just installed. Furthermore, this fix doesn't adress the cpack case.~~

Edit: Actually I was wrong about EXCLUDE_FROM_ALL, it does seem to prevent it from being included in cpack case. This means that this change isn't as valuable as I first thought but I'll still leave this pull request up.

Solution

This pull request does two things, broken up in separate commits:

  • Adds an option, RC_ENABLE_INSTALL. If set to on (default value), everything will be installed just as before. Setting this to off will disable all install commands (including in extras).
  • Adds an installation component which is equal to ${PROJECT_NAME} to all install commands (so extras will have components like e.g. rapidcheck_gtest while the main gtest module will have rapidcheck). This allows users to leave install on for rapidcheck for local development but filter it from cpack with the following cmake code:
get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
list(FILTER CPACK_COMPONENTS_ALL EXCLUDE REGEX "^rapidcheck")

The changes are inspired by google test: it has the INSTALL_GTEST cache variable which works in the same way and also sets COMPONENT to ${PROJECT_NAME} on its installs.

david-pikas avatar Oct 11 '24 10:10 david-pikas