message(STATUS "\nStarting configuring of the ${TARGET}-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}/${TARGET}/user-manual)
	set(CUR_DOC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/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})

	add_custom_command(OUTPUT ${TARGET}-doc.pdf
		COMMAND make noreader 
		WORKING_DIRECTORY ${CUR_DOC_BUILD_DIR}
		COMMENT "Build the ${TARGET} user manual")

	add_custom_target(${TARGET}_user_manual 
		DEPENDS ${TARGET}-doc.pdf)

ENDIF(UNIX AND NOT APPLE)

IF (PEDANTIC)
	ADD_DEFINITIONS (-Werror)
ENDIF (PEDANTIC)


message(STATUS "The doc target is : ${CUR_DOC_DIR}/${TARGET}-doc.pdf")

# Ensure that the manual pdf file is actually compiled using the custom_command
# above.
add_custom_target(${TARGET}-doc.pdf ALL
	DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-doc.pdf)


# Once de pdf file has been generated, copy it to the main source doc directory,
# so that it is available to others even if build is erased (for example when
# copying all the source tree to Windows to build the software there, but not
# the documentation). Note that the git-archive-based tarball creation will
# ignore that file.

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


install(FILES ${CUR_DOC_BUILD_DIR}/${TARGET}-doc.pdf 
	DESTINATION ${MSXPERTSUITE_DOC_DIR})


message(STATUS "\nFinished configuring of the ${TARGET}-user-manual material\n")

