if(BUILD_USER_MANUAL)

  message("")
  message(STATUS "${BoldGreen}Starting configuration for the user manual for ${CMAKE_PROJECT_NAME} ${ColourReset}")
  message("")

  # The version of the program needs to be set in the user manual front
  # matter.
  CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/CMakeStuff/user-manual-version-entity.ent.cmake.in
    ${CMAKE_SOURCE_DIR}/doc/user-manual/xml/user-manual-version-entity.ent @ONLY)

  # The location of the main user manual config file (set fop.xconf file
  # location)
  set(FOP_XCONF_DIR ${CMAKE_SOURCE_DIR}/doc/user-manual)
  CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/CMakeStuff/DC-user-manual.cmake.in
    ${CMAKE_SOURCE_DIR}/doc/user-manual/DC-user-manual @ONLY)

    
    
  # Command to make ${CMAKE_PROJECT_NAME}-doc
  # Will generate HTML and PDF documentation in the build directory

  # Note that TARGET needs to be lowercase. Since we build the documentation
  # only on UNIX, that target is set in
  # CMakeStuff/toolchains/unix-toolchain.cmake.

  
  add_custom_target(html
    daps -d DC-user-manual --verbosity=3 html --static
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Building the user manual (HTML)" VERBATIM
    )
  message("\tBuild the user manual (HTML) with make html.")
    
  add_custom_target(pdf
    daps -d DC-user-manual --verbosity=3 pdf
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Building the user manual (PDF)" VERBATIM
    )
  message("\tBuild the user manual (PDF) with make pdf.")
    
  add_custom_target(${TARGET}-doc
    DEPENDS pdf html
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Building the ${TARGET} documentation" VERBATIM
    )
  message("\tBuild the user manual (HTML and PDF) with make ${TARGET}-doc.")

  add_custom_command( TARGET pdf PRE_BUILD
        COMMAND ${CMAKE_COMMAND} -E touch
                ${CMAKE_SOURCE_DIR}/doc/user-manual/DC-user-manual
        COMMENT "Force the rebuild of the user manual")
                
  # Beware, need to use the RENAME clause !
  install(FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/build/user-manual/user-manual_color_en.pdf
    DESTINATION share/doc/${CMAKE_PROJECT_NAME} RENAME ${TARGET}-doc.pdf)

  install(DIRECTORY 
    ${CMAKE_CURRENT_SOURCE_DIR}/build/user-manual/html/user-manual/
    DESTINATION share/doc/${CMAKE_PROJECT_NAME}/html)

  message("")
  message(STATUS "${BoldGreen}Finished configuring the ${CMAKE_PROJECT_NAME} user manual.${ColourReset}")
  message("")
  
  add_custom_target(wdoc DEPENDS pdf COMMENT "wdoc target copies the user manual into the wbuild directory (needed for Windows innosetup)")
  add_custom_command( TARGET wdoc POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy
                ${CMAKE_CURRENT_SOURCE_DIR}/build/user-manual/user-manual_color_en.pdf
                ${CMAKE_SOURCE_DIR}/wbuild/xtpcpp_user_manual.pdf)


else()

  message(STATUS "User manual build skipped")

endif()


