# Build file for CMake in order to generate the documentation.
#

option(PML_DOC_CREATE_PDF "Create PDF reference manual" ON)

option(PML_DOC_WITH_STATIC "Create documentation for static members" ON)
option(PML_DOC_WITH_PRIVATE "Create documentation for private members" ON)
option(PML_DOC_WITH_LOCAL "Create documentation for local members" ON)
option(PML_DOC_WITH_INTERNAL "Create documentation for internal features" ON)

mark_as_advanced(
	PML_DOC_WITH_PRIVATE
	PML_DOC_WITH_STATIC
	PML_DOC_WITH_LOCAL
	PML_DOC_WITH_INTERNAL
)

# ---------------------------------
# Cmake modules needed
# ---------------------------------
find_package(HTMLHelp)
find_package(LATEX)

if(HTML_HELP_COMPILER)
  set(DOXYGEN_HTMLHELP YES)
else()
  set(DOXYGEN_HTMLHELP NO)
endif()

#if(LATEX_COMPILER OR PDFLATEX_COMPILER)
#  set(DOXYGEN_LATEX YES)
#else()
  set(DOXYGEN_LATEX NO)
#endif()

#if(PDFLATEX_COMPILER AND PML_DOC_CREATE_PDF)
#  set(DOXYGEN_PDFLATEX YES)
#else()
  set(DOXYGEN_PDFLATEX NO)
#endif()

if(PML_DOC_CREATE_PDF)
  set(DOXYGEN_PDF_HYPERLINKS YES)
else()
  set(DOXYGEN_PDF_HYPERLINKS NO)
endif()

if(PML_DOC_WITH_PRIVATE)
  set(DOXYGEN_EXTRACT_PRIVATE YES)
else()
  set(DOXYGEN_EXTRACT_PRIVATE NO)
endif()

if(PML_DOC_WITH_STATIC)
  set(DOXYGEN_EXTRACT_STATIC YES)
else()
  set(DOXYGEN_EXTRACT_STATIC NO)
endif()

if(PML_DOC_WITH_LOCAL)
  set(DOXYGEN_EXTRACT_LOCAL YES)
else()
  set(DOXYGEN_EXTRACT_LOCAL NO)
endif()

if(PML_DOC_WITH_INTERNAL)
  set(DOXYGEN_EXTRACT_INTERNAL YES)
else()
  set(DOXYGEN_EXTRACT_INTERNAL NO)
endif()

if(DOT)
  set(HAVE_DOT YES)
else()
  set(HAVE_DOT NO)
endif()

set(DOXYGEN_LANGUAGE "English" CACHE STRING "Language used by doxygen")
mark_as_advanced(DOXYGEN_LANGUAGE)

set(DOXYGEN_SOURCE_DIR
  ${physicalModel_SOURCE_DIR}/TODO
  ${physicalModel_SOURCE_DIR}/ChangeLog
	${physicalModel_SOURCE_DIR}
	${physicalModelProperties_DIR}
	${physicalModel_SOURCE_DIR}/test
)
set(DOXYGEN_OUTPUT_DIR ${physicalModel_SOURCE_DIR}/api-doc)
string(REGEX REPLACE ";" " " DOXYGEN_INPUT_LIST "${DOXYGEN_SOURCE_DIR}")

configure_file(doxygen.conf.in ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf)
#set(HTML_TARGET ${DOXYGEN_OUTPUT_DIR}/html/index.html)
add_custom_target(api-doc ALL
		      ${DOXYGEN} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
		      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf)

set_target_properties(api-doc PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)

if(DOXYGEN_PDFLATEX)
  add_custom_target(api-doc-pdf ALL
		      COMMAND ${PERL_EXECUTABLE} 
				${CMAKE_CURRENT_SOURCE_DIR}/CompileLatex.pl
				"${PDFLATEX_COMPILER}"
				"${DOXYGEN_OUTPUT_DIR}/refman-latex"
				refman.tex
				refman.pdf
				"${DOXYGEN_OUTPUT_DIR}/refman.pdf"
		      DEPENDS ${HTML_TARGET})
endif()

