message(STATUS "\nStarting configuring of the minexpert-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}/minexpert/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 minexpert-doc.pdf
		COMMAND make -f ${CUR_DOC_BUILD_DIR}/Makefile usermanual
		WORKING_DIRECTORY ${CUR_DOC_BUILD_DIR}
		COMMENT "Build the mineXpert user manual")

	if(BUILD_USER_MANUALS)

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

		# Command:
		# make copy-minexpert-doc.pdf
		add_custom_target(copy-minexpert-doc.pdf ALL
			COMMAND ${CMAKE_COMMAND} -E copy ${CUR_DOC_BUILD_DIR}/minexpert-doc.pdf
			${CMAKE_SOURCE_DIR}/minexpert/user-manual
			DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/minexpert-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}/minexpert-doc.pdf
		DESTINATION ${MINEXPERT_DOC_DIR})

elseif(APPLE)

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

endif()

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

