message(STATUS "\nStarting configuring of the massxpert-user-manual material\n")

#############################################################
# There are warning issued during the compilation of almost
# any LaTeX source, but we want the compilation not to stop...
# Because the build process has -Werror set globally we want to
# disable it here specifically.
if(PEDANTIC)
  REMOVE_DEFINITIONS (-Werror)
endif(PEDANTIC)

if(UNIX AND NOT APPLE)

  set(CUR_DOC_DIR ${CMAKE_SOURCE_DIR}/massxpert/user-manual)
  set(CUR_DOC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/build-user-manual)

  message(STATUS "Current doc directory: ${CUR_DOC_DIR}")
  message(STATUS "Current doc build directory: ${CUR_DOC_BUILD_DIR}")

  # Copy the directory to a build directory. This will also copy as "hard"
  # files, following the various symbolic links,  to other files in other places
  # in the source tree (preface.tex is an example, images/splashscreen.png or
  # images/addresses.png are two other examples; the files in
  # user-manual-common/figures that are linked in the local figures directory
  # also).
  execute_process(COMMAND cp -rpL ${CUR_DOC_DIR} ${CUR_DOC_BUILD_DIR}
    WORKING_DIRECTORY	${CMAKE_CURRENT_BINARY_DIR})

  # Make sure we use the Makefile that is located in the new directory, copy 
  # of the original user-manual directory. 
  add_custom_command(OUTPUT massxpert-doc.pdf
    COMMAND make -f ${CUR_DOC_BUILD_DIR}/Makefile usermanual
    WORKING_DIRECTORY ${CUR_DOC_BUILD_DIR}
    COMMENT "LaTeX-build the massXpert user manual")

  if(BUILD_USER_MANUALS)

    # Command:
    # make massxpert-user-manual
    add_custom_target(massxpert-user-manual ALL
      DEPENDS massxpert-doc.pdf
      COMMENT "Make massxpert-user-manual")

    # Command:
    # make copy-massxpert-doc.pdf
    add_custom_target(copy-massxpert-doc.pdf ALL
      COMMAND ${CMAKE_COMMAND} -E copy ${CUR_DOC_BUILD_DIR}/massxpert-doc.pdf
      ${CMAKE_SOURCE_DIR}/massxpert/user-manual
      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/massxpert-doc.pdf
      COMMENT "Copy the pdf file to the source doc dir.")

  endif()

endif()

if(PEDANTIC)
  ADD_DEFINITIONS (-Werror)
endif(PEDANTIC)

if(UNIX AND NOT APPLE)

install(FILES ${CUR_DOC_BUILD_DIR}/massxpert-doc.pdf 
	DESTINATION ${MASSXPERT_DOC_DIR})

elseif(APPLE)

	install(FILES ${CMAKE_SOURCE_DIR}/massxpert/user-manual/massxpert-doc.pdf
		DESTINATION ${MASSXPERT_DOC_DIR})

endif()

message(STATUS "\nFinished configuring of the massxpert-user-manual material.\n")

