[CMake] Pre-install targets?

David Thompson david.thompson at kitware.com
Wed Oct 17 11:28:26 EDT 2018


Hi all,

After some hallway conversation, here is a follow-up:

The consensus was that there were 2 options for the documentation target:

+ Leave documentation out of the install step when documentation is not built as part of the ALL target.
+ Change the configuration option for documentation from a boolean to a tri-state enum, i.e.,

    set(${PROJECT}_BUILD_DOCUMENTATION "never" CACHE STRING "When to build documentation.")
    set_property(CACHE ${PROJECT}_BUILD_DOCUMENTATION PROPERTY STRINGS never manual always)

 so that automated builds for continuous integration can function (using "always" or "never")
 while developers can enable documentation but not be forced to refresh it every time they
 modify source code (using "manual").

For the latter, a recent change[1] to CMake has made the execution of install-rules consistently ordered when processing subdirectories, so it is possible to make the INSTALL target build documentation as needed with something like:

   if (${PROJECT}_BUILD_DOCUMENTATION STREQUAL "manual")
     install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" cmake --build \"${CMAKE_BINARY_DIR}\" --target docs --config $<CONFIG>)")
   endif()

so long as care is taken within each directory's CMakeLists.txt to place the above before any install() directives related to the generated documentation.

	David

[1]: https://gitlab.kitware.com/cmake/cmake/merge_requests/2434

> On Oct 11, 2018, at 09:09, David Thompson <david.thompson at kitware.com> wrote:
> 
> Hi all,
> 
> Is there a way to force a custom target (i.e., ADD_CUSTOM_TARGET) to be built just before installation?
> 
> We have documentation added as a custom target that is **not** passed the "ALL" keyword because generating the documentation is slow. However, that target creates files that have a matching INSTALL, so "make install" or "ninja install" will fail unless the target is built before installation. We want to encourage developers to configure with documentation turned on, but want buildbot/dashboard builds to work without magic options or special configuration.
> 
> Along those lines:
> 
> 1. Is there any ordering of INSTALL(CODE ...) relative to INSTALL(FILES ...)? If it is guaranteed to run first, we could force the target to build that way.
> 
> 2. Is there really nothing to replace the deprecated PRE_INSTALL_SCRIPT property?
> 
> 	Thanks,
> 	David



More information about the CMake mailing list