message("\n${BoldGreen}Configuring subdirectory doc/user-manual${ColourReset}\n")

message("")
message("\n${BoldYellow}Configuring the user manual compilation${ColourReset}\n")
message("")

# The file driving the user manual build is DC-user-manual.
# This file contains a config bit that points to the directory
# that contains de fop.xconf configuration file needed by
# the FOP utility that crafts the user manual pdf file.

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
)

message("\tConfiguring the user manual compilation")

# The output of Daps will be in BUILD_DIR.
add_custom_target(
    user-manual ALL
    COMMAND make BUILD_DIR=${CMAKE_BINARY_DIR}/doc -f usermanual-makefile all_f
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/doc/user-manual
    COMMENT "Build of the DocBook-based user manual \
      documentation in ${CMAKE_BINARY_DIR}/doc"
)

set(DOC_STORE_PATH "${HOME_DEVEL_DIR}/msxpertsuite-store/docs/${LOWCASE_PROJECT_NAME_NO_VER}")

if(DEFINED ENV{DEB_BUILD_OPTIONS})

    message("Building debian package: not synchronizing documentation to doc store.")

else()

    # We want to store a local copy of the documentation so that we do not mess around
    # with build in unix that destroy the documentation if the build user manual switch
    # is not set and then MXE fails to find the doc pdf file.
    add_custom_command(
        TARGET user-manual
        POST_BUILD
        COMMAND rsync -avpP --delete ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-doc.pdf ${CMAKE_CURRENT_BINARY_DIR}/html
                ${DOC_STORE_PATH}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        COMMENT "Copy the documentation to ${DOC_STORE_PATH}"
    )

endif()


install(
    FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-doc.pdf
    DESTINATION ${PROJECT_INSTALL_DOC_DIR}
)

install(
    DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/user-manual/
    DESTINATION ${PROJECT_INSTALL_DOC_DIR}/html
)

message("")
message(STATUS "${BoldGreen}Finished configuring the ${CMAKE_PROJECT_NAME} user manual.${ColourReset}")
message("")

message("\n${BoldGreen}Done configuring subdirectory doc/user-manual${ColourReset}\n")
