4

I'm currently trying to setup CMake to automatically generate my Doxygen documentation. I currently use the following code.

find_package(Doxygen)
if (DOXYGEN_FOUND)
    configure_file("docs/Doxyfile.in" "${PROJECT_BINARY_DIR}/Doxyfile")
    add_custom_target(docs
                      COMMAND ${DOXYGEN_EXECUTABLE}
                              "${PROJECT_BINARY_DIR}/Doxyfile"
                      SOURCES "${PROJECT_BINARY_DIR}/Doxyfile")
    install(DIRECTORY "${PROJECT_BINARY_DIR}/docs/"
            DESTINATION "docs")
endif()

It works fine in when you enter make docs it generates the documentation in PROJECT_BINARY_DIR/docs. When you enter make install it copies the docs subdirectory to CMAKE_INSTALL_PREFIX. However when the user does not wish to generate documentation and just types make install the following error occurs:

CMake Error at cmake_install.cmake:36 (FILE):
  file INSTALL cannot find "/home/lukas/workspace/TheGame/build/docs".

How can one instruct the install command to only be executed if a custom target (docs) is built (or if the subdirectory docs exists in PROJECT_BINARY_DIR)?

Lukas Schmelzeisen
  • 2,934
  • 4
  • 24
  • 30

1 Answers1

8

Have you tried using the OPTIONAL flag?

install(DIRECTORY "${PROJECT_BINARY_DIR}/docs/" DESTINATION "docs" OPTIONAL)
sakra
  • 62,199
  • 16
  • 168
  • 151
  • 1
    This works, but is there really not a way to make it depend on a specific target? – pattivacek Feb 08 '18 at 11:02
  • 1
    @patrickvacek see https://stackoverflow.com/questions/8636479/postpone-making-custom-target-until-install for an alternate solution – sakra Feb 10 '18 at 09:21