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}/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 ${TARGET}-doc.pdf
		COMMAND make -f ${CUR_DOC_BUILD_DIR}/Makefile usermanual
		WORKING_DIRECTORY ${CUR_DOC_BUILD_DIR}
		COMMENT "LaTeX-build the ${TARGET} user manual")

	# Command:
	# make ${TARGET}-user-manual
	add_custom_target(${TARGET}-user-manual 
		DEPENDS ${TARGET}-doc.pdf
		COMMENT "Make ${TARGET}-user-manual")

ENDIF(UNIX AND NOT APPLE)

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

# Command:
# make copy-${TARGET}-doc.pdf
add_custom_target(copy-${TARGET}-doc.pdf
	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")

