###############################################################################
# 
#  Copyright (2008) Alexander Stukowski
#
#  This file is part of OVITO (Open Visualization Tool).
#
#  OVITO is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  OVITO is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

# Enable precompiled headers when using the GCC compiler.
IF(OVITO_USE_PRECOMPILED_HEADERS AND CMAKE_COMPILER_IS_GNUCXX)
	INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ENDIF(OVITO_USE_PRECOMPILED_HEADERS AND CMAKE_COMPILER_IS_GNUCXX)

# This is needed to export the symbols in this shared library.
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMAKING_MODULE_POVRAY")

# The header files that need to be processed by the QT meta-object compiler.
SET(POVRay_MOC_HDRS
	export/POVRayExporter.h
	export/POVRayExportInterface.h
	export/MeshExportInterface.h	
	
	renderer/POVRayRenderer.h
	renderer/POVRayRendererEditor.h
)

# The regular source files of this library.
SET(POVRay_SRCS
	export/POVRayExporter.cpp
	export/MeshExportInterface.cpp	
	
	renderer/POVRayRenderer.cpp
	renderer/POVRayRendererEditor.cpp
)

# Generate precompiled header
IF(OVITO_USE_PRECOMPILED_HEADERS AND MSVC)
	SET_SOURCE_FILES_PROPERTIES(${POVRay_SRCS} PROPERTIES COMPILE_FLAGS "/Yucore/Core.h /Fppovray.pch")
	SET_SOURCE_FILES_PROPERTIES(PrecompiledHeader.cpp PROPERTIES COMPILE_FLAGS "/Yccore/Core.h /Fppovray.pch")
ENDIF(OVITO_USE_PRECOMPILED_HEADERS AND MSVC)

# Add optional source files needed for scripting of the plugin.
IF(OVITO_BUILD_PLUGIN_SCRIPTING)
	SET(POVRay_SRCS ${POVRay_SRCS} 
		python/PythonInterface.cpp	
	)
ENDIF(OVITO_BUILD_PLUGIN_SCRIPTING)

# Use the QT meta-object compiler to generate additional code.
QT4_WRAP_CPP(POVRay_MOC_SRCS ${POVRay_MOC_HDRS})

# Create plugin library.
ADD_LIBRARY(POVRay
	PrecompiledHeader.cpp
	${POVRay_SRCS}
	${POVRay_MOC_SRCS}	
)

IF(OVITO_USE_PRECOMPILED_HEADERS AND CMAKE_COMPILER_IS_GNUCXX)
	ADD_PRECOMPILED_HEADER(POVRay ${CMAKE_SOURCE_DIR}/src/core/Core.h)
ENDIF(OVITO_USE_PRECOMPILED_HEADERS AND CMAKE_COMPILER_IS_GNUCXX)

# Link required libraries
TARGET_LINK_LIBRARIES(POVRay Base Core Mesh)

# Link the target against the Qt libraries. 
TARGET_LINK_LIBRARIES(POVRay ${QT_LIBRARIES})

# Add Python libraries for scripting
IF(OVITO_BUILD_PLUGIN_SCRIPTING)
	TARGET_LINK_LIBRARIES(POVRay Scripting ${Boost_PYTHON_LIBRARY} ${PYTHON_UTIL_LIBRARY} ${PYTHON_LIBRARIES})
ENDIF(OVITO_BUILD_PLUGIN_SCRIPTING)

# Assign an absolute install path to this dynamic link library.
IF(APPLE)
	SET_TARGET_PROPERTIES(POVRay PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OVITO_RELATIVE_PLUGINS_DIRECTORY}")
ENDIF(APPLE)

# Copy Plugin manifest to destination directory.
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/POVRay.manifest.xml" 
               "${OVITO_PLUGINS_DIRECTORY}/POVRay.manifest.xml")
 
# This plugin will be part of the installation package.
IF(NOT OVITO_MONOLITHIC_BUILD)
	INSTALL(TARGETS POVRay DESTINATION "${OVITO_RELATIVE_PLUGINS_DIRECTORY}")
ENDIF(NOT OVITO_MONOLITHIC_BUILD)
INSTALL(FILES "${OVITO_PLUGINS_DIRECTORY}/POVRay.manifest.xml" DESTINATION "${OVITO_RELATIVE_PLUGINS_DIRECTORY}")
              
