# Copyright 2006-2008 The FLWOR Foundation.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# find doxygen and include the doxygen macro
# the macro is used in subdirs to generate doxygen
# documentation
FIND_PACKAGE(Doxygen)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake_modules/CMakeUseDoxygen.cmake)

# add an artificial target 'doc' which will be used for
# - host language api documentation generated by doxygen (c++, c api, swig apis)
# - manually written documentation (also generated by doxygen; build instructions, ...)
# - xquery api documentation generated by zorba (xqdoc; all modules in the modules directory)
# - code documentation
ADD_CUSTOM_TARGET(doc COMMENT "Building Zorba documentation...")
SET_TARGET_PROPERTIES (doc PROPERTIES
  EXCLUDE_FROM_DEFAULT_BUILD 1
  FOLDER "Docs"
)

# generate Zorba Doxygen documentation and XQDoc documentation for Zorba modules
ADD_SUBDIRECTORY(zorba)

FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/zorba/html)

# programming apis
ADD_SUBDIRECTORY(cxx)
ADD_SUBDIRECTORY(c)

IF (SWIG_FOUND)
  ADD_SUBDIRECTORY(java)
  ADD_SUBDIRECTORY(xqj)
  ADD_SUBDIRECTORY(python)
  ADD_SUBDIRECTORY(ruby)
  ADD_SUBDIRECTORY(php)
  ADD_SUBDIRECTORY(csharp)
ENDIF (SWIG_FOUND)

# generate Doxygen code documentation
ADD_SUBDIRECTORY(code)

# workaround: a dir is already needed for the install command.
# the html directory, however, is generated with the make doc call
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/zorba/html)
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cxx/html)
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/c/html)
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/code/html)

# copy all needed images into 'images' folder
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/images)
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/zorba/xquery_jsoniq_venn.png
                ${CMAKE_CURRENT_BINARY_DIR}/images/xquery_jsoniq_venn.png COPYONLY)
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/zorba/store_concepts.png
                ${CMAKE_CURRENT_BINARY_DIR}/images/store_concepts.png COPYONLY)
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/zorba/data_lifecycle.png
                ${CMAKE_CURRENT_BINARY_DIR}/images/data_lifecycle.png COPYONLY)
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/zorba/data-in-out.png
                ${CMAKE_CURRENT_BINARY_DIR}/images/data-in-out.png COPYONLY)
#copy tutorial images
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/zorba/tutorialimages/animated.gif
                ${CMAKE_CURRENT_BINARY_DIR}/images/animated.gif COPYONLY)
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/zorba/tutorialimages/charcoaled.gif
                ${CMAKE_CURRENT_BINARY_DIR}/images/charcoaled.gif COPYONLY)
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/zorba/tutorialimages/exif.jpg
                ${CMAKE_CURRENT_BINARY_DIR}/images/exif.jpg COPYONLY)
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/zorba/tutorialimages/extended.gif
                ${CMAKE_CURRENT_BINARY_DIR}/images/extended.gif COPYONLY)
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/zorba/tutorialimages/painted.png
                ${CMAKE_CURRENT_BINARY_DIR}/images/painted.png COPYONLY)

IF (SWIG_FOUND)
  FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python/html)
  FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/java/html)
  FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/php/html)
  FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ruby/html)
ENDIF (SWIG_FOUND)
