###############################################################################
# 
#  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/>.
#
###############################################################################

# Find GNU Scientific Library (GSL)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
FIND_PACKAGE(GSL)
IF(NOT GSL_FOUND)
	MESSAGE(FATAL_ERROR "The GNU Scientific Library (GSL) was not found on your system but is required for the Crystal Analysis plugin. Please install this library on your system or specify the location of the library manually.")
ENDIF(NOT GSL_FOUND)
INCLUDE_DIRECTORIES(${GSL_INCLUDE_DIR})

# Find Computational Geometry Algorithms Library (CGAL)
#FIND_PACKAGE(CGAL)
#IF(NOT CGAL_FOUND)
#	MESSAGE(FATAL_ERROR "The Computational Geometry Algorithms Library (CGAL) was not found on your system but is required for the Crystal Analysis plugin. Please install this library on your system or specify the location of the library manually.")
#ENDIF(NOT CGAL_FOUND)
#INCLUDE_DIRECTORIES(${CGAL_INCLUDE_DIR})

# The header files that need to be processed by the QT meta-object compiler.
SET(CrystalAnalysis_MOC_HDRS
	grains/AnalyzeMicrostructureModifier.h
	deformation/CalculateExtrinsicStrainModifier.h
	deformation/CalculateIntrinsicStrainModifier.h
)

# The regular source files of this library.
SET(CrystalAnalysis_SRCS
	grains/AnalyzeMicrostructureModifier.cpp
	grains/FindGrains.cpp
	deformation/CalculateExtrinsicStrainModifier.cpp
	deformation/CalculateIntrinsicStrainModifier.cpp
)

# Add optional source files needed for scripting of the plugin.
IF(OVITO_BUILD_PLUGIN_SCRIPTING)
	LIST(APPEND CrystalAnalysis_SRCS python/PythonInterface.cpp)
ENDIF(OVITO_BUILD_PLUGIN_SCRIPTING)

# Use the QT meta-object compiler to generate additional code.
QT4_WRAP_CPP(CrystalAnalysis_MOC_SRCS ${CrystalAnalysis_MOC_HDRS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED)

# Generate plugin module.
OVITO_PLUGIN(CrystalAnalysis
	SOURCES PrecompiledHeader.cpp ${CrystalAnalysis_SRCS} ${CrystalAnalysis_MOC_SRCS}
	LIB_DEPENDENCIES Mesh
	PLUGIN_DEPENDENCIES AtomViz
	OPTIONAL_PLUGIN_DEPENDENCIES Scripting
	RESOURCE crystalanalysis.rcc resources/crystalanalysis.qrc
	PCH "${CMAKE_SOURCE_DIR}/src/core/Core.h"
)

# Add GSL library
TARGET_LINK_LIBRARIES(CrystalAnalysis ${GSL_LIBRARIES})

# Add CGAL library
#TARGET_LINK_LIBRARIES(CrystalAnalysis ${CGAL_LIBRARIES})

# Install script files for this plugin.
IF(OVITO_BUILD_PLUGIN_SCRIPTING)
	COPY_DIRECTORY_WITHOUT_SVN("${CMAKE_CURRENT_SOURCE_DIR}/resources/scripts" "${OVITO_SHARE_DIRECTORY}/scripts/crystalanalysis")
	INSTALL(DIRECTORY "${OVITO_SHARE_DIRECTORY}/scripts/crystalanalysis" DESTINATION "${OVITO_RELATIVE_SHARE_DIRECTORY}/scripts/" PATTERN ".svn" EXCLUDE)
ENDIF(OVITO_BUILD_PLUGIN_SCRIPTING)

