#
# Logic taken from SIRIUS distribution
#
# FORD version of the documentation
#
# Some modern versions of FORD are unable to process correctly the
# inter-page links. Treat this as work-in-progress
#
message(STATUS "Configuring docs")
find_program(FORD_EXE ford
  ENV FORD_PROGRAM
  DOC "path to the ford executable (required to generate the documentation)"
  )
  
if(FORD_EXE AND LIBGRIDXC_BUILD_DOCS_FORD)

  # for ford pre-processing
  if(WITH_LIBXC)
    set(INCLUDE_LIBXC "HAVE_LIBXC")
  else()
    set(INCLUDE_LIBXC "_DUMMY")
  endif()
 # Copy the FORD project-file into the build directory
 set (FORD_PROJECT_FILE "${CMAKE_CURRENT_BINARY_DIR}/ford.md")
 set(FORD_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc-ford-build")
 configure_file(ford.cfg.in "${FORD_PROJECT_FILE}" @ONLY)

 message(STATUS "Done generating ford.md")

 add_custom_target(doc-ford ALL
  COMMENT "Generating FORD API documentation"
  COMMAND "${FORD_EXE}" "${FORD_PROJECT_FILE}"
  WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  VERBATIM
  )
 message(STATUS "Done generating documentation")
 
  install(DIRECTORY "${FORD_OUTPUT_DIR}/" DESTINATION ${CMAKE_INSTALL_PREFIX}/doc)
endif()
