cmake_minimum_required(VERSION 2.6)

set(ASCIIDOC_FILES
	activities
	manual
	mod_collage_xml_help
)

# Generate list of html files
foreach(ASCIIDOC_FILE ${ASCIIDOC_FILES})
	set (ASCIIDOC_FILES_HTML
		${ASCIIDOC_FILES_HTML}
		${ASCIIDOC_FILE}.html
	)
endforeach(ASCIIDOC_FILE ${ASCIIDOC_FILES})	

if (NOT WIN32)
	# We do not expect to find asciidoc on Windows systems
	find_program(ASCIIDOC_EXECUTABLE asciidoc)
	set(ASCIIDOC_OPTIONS
        -a toc
	)
	if(NOT ASCIIDOC_EXECUTABLE)
		message(WARNING "asciidoc not found")
	else(NOT ASCIIDOC_EXECUTABLE)
		foreach(ASCIIDOC_FILE ${ASCIIDOC_FILES})
			#set (ASCIIDOC_FILES_TXT 
			#	${ASCIIDOC_FILES_TXT}
			#	${ASCIIDOC_FILE}.txt.dummy
			#)
		
			# Generate html file from ascii files
			add_custom_command(
				# misses bug address
				OUTPUT ${PROJECT_SOURCE_DIR}/doc/${ASCIIDOC_FILE}.html
								
				COMMAND ${ASCIIDOC_EXECUTABLE} ${ASCIIDOC_OPTIONS} ${ASCIIDOC_FILE}.txt
						
				# replace the chartype
				DEPENDS ${PROJECT_SOURCE_DIR}/doc/${ASCIIDOC_FILE}.txt
				
				WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/doc
				COMMENT "doc-update [${ASCIIDOC_FILE}]: Generated html doc file."
			)
			
		endforeach(ASCIIDOC_FILE ${ASCIIDOC_FILES})
		
		add_custom_target(doc-update
			COMMENT "doc-update: Done."
			DEPENDS ${ASCIIDOC_FILES_HTML}
		)
	endif(NOT ASCIIDOC_EXECUTABLE)
endif (NOT WIN32)

# Install html files

install(FILES ${ASCIIDOC_FILES_HTML} DESTINATION "${DOCDIR}")
install(DIRECTORY images DESTINATION "${DOCDIR}")