16

I've got the following problem using cmake. I use UseDoxygen from http://tobias.rautenkranz.ch/cmake/doxygen/ to generate the documentation for my library. This works fine, but know I want to realize the following: When I call "make install" I want to build to Documentation and install it too. Therefore I add

install(DIRECTORY ${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_HTML_DIR} DESTINATION share/doc/mylib/)
add_dependencies(install doc) 

to my CMakeLists.txt. This results in an error:

  CMake Error at CMakeModules/UseDoxygen.cmake:145 (add_dependencies):
  add_dependencies Adding dependency to non-existent target: install
Call Stack (most recent call first):
  CMakeLists.txt:141 (include)

Is it possible to get a easy workaround for this? Because if the targets are not connected the install step installs nothing unless "make doc" is done manually befor calling "make install".

regards Grisu

M.K. aka Grisu
  • 2,338
  • 5
  • 17
  • 32
  • 1
    See the answer to [this question](http://stackoverflow.com/questions/8636479/postpone-making-custom-target-until-install/8643015#8643015). – sakra Feb 06 '12 at 16:53

3 Answers3

5

We build our documentation by adding it with add_custom_target with the ALL option specified so it builds with the all target.

Then to install, it's just the install command. There is no need to add anything to the install target.

If you add the documentation to the all target, then doing make install will also build the documentation.

tpg2114
  • 14,112
  • 6
  • 42
  • 57
  • This works fine. I achieved the right order ( documentation after build) using an additional add_dependencies. – M.K. aka Grisu Feb 06 '12 at 17:09
  • This also works for other builtin targets such as `package` or `install`. – Lars Bilke Dec 12 '13 at 13:53
  • 2
    This is not an acceptable solution. The question remains unanswered, how to add a dependency to the install target only. – andrewrk Sep 26 '19 at 04:01
  • 1
    @andrewrk If you have a better answer, by all means post it. However, 7 years ago when this was asked and answered, this approach worked based on what was available in CMake and what we could accomplish. – tpg2114 Sep 26 '19 at 04:19
2

Building documentation via add_custom_target( ALL ...) is not an ideal solution, as it means the documentation gets built redundantly for all configurations (Debug, Release, RelWithDebInfo, MinSizeRel).

I'd like to build the documentation once regardless of the build config, then use the CONFIGURATIONS option of the install() command to install it only for the Release and RelWithDebInfo configs. install() should depend on the documentation target but, as I said, only build it for one config. There doesn't appear to be an way to add a dependency from install() onto the documentation that meets these requirements.

Paul Martz
  • 166
  • 2
  • 4
2

If you generate code documentation, isn't it a better idea to execute that command after the build command? In this way it will be available at install time.

You can add a custom command at POST_BUILD and execute the doxygen commands there. See more at http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_custom_command

Cristian Bidea
  • 679
  • 4
  • 12