###############################################################################
# 
#  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_ATOMVIZ")

# The header files that need to be processed by the QT meta-object compiler.
SET(AtomViz_MOC_HDRS
	atoms/AtomsObject.h
	atoms/AtomsObjectEditor.h
	atoms/AtomType.h	
	atoms/SimulationCell.h	
	atoms/AtomVizSettingsPage.h
	atoms/datachannels/DataChannel.h
	atoms/datachannels/AtomTypeDataChannel.h
	atoms/datachannels/PositionDataChannel.h
	atoms/datachannels/DisplacementDataChannel.h
	atoms/datachannels/OrientationDataChannel.h
	atoms/datachannels/DeformationGradientDataChannel.h
	atoms/datachannels/BondsDataChannel.h
	modifier/AtomsObjectModifierBase.h		
	modifier/AtomsObjectAnalyzerBase.h		
	modifier/slice/SliceModifier.h		
	modifier/coloring/AssignColorModifier.h		
	modifier/coloring/AtomTypeColorModifier.h		
	modifier/coloring/ColorCodingModifier.h
	modifier/ambientlighting/AmbientLightingModifier.h		
	modifier/analysis/cluster/ClusterAtomsModifier.h
	modifier/analysis/cna/CNAModifier.h
	modifier/analysis/ackland/AcklandAnalysisModifier.h	
	modifier/analysis/coordination/CoordinationNumberModifier.h
	modifier/datachannels/CreateExpressionChannelModifier.h		
	modifier/displacement/CalcDisplacementsModifier.h			
	modifier/selection/SelectAtomTypeModifier.h		
	modifier/selection/InvertSelectionModifier.h			
	modifier/selection/FreezeSelectionModifier.h			
	modifier/selection/SelectExpressionModifier.h
	modifier/selection/SelectionModifierBase.h
	modifier/deleteatoms/DeleteAtomsModifier.h
	modifier/transformation/AffineTransformationModifier.h
	modifier/wrap/WrapPeriodicImagesModifier.h	
	modifier/wrap/ShowPeriodicImagesModifier.h
	utils/NearestNeighborList.h
	utils/DataChannelComboBox.h
	parser/AtomsImportObject.h
	parser/AtomsFileParser.h 
	parser/AbstractFileColumnParser.h
	parser/MultiFileParser.h
	parser/ColumnChannelMapping.h
	parser/ColumnChannelMappingEditor.h
	parser/CompressedTextParserStream.h
	parser/xyz/XYZParser.h
	parser/xyz/XYZParserSettingsDialog.h
	parser/lammps/LAMMPSDataParser.h
	parser/lammps/LAMMPSDumpParser.h
	parser/lammps/LAMMPSDumpParserSettingsDialog.h
	parser/lammps/LAMMPSTextDumpParser.h
	parser/lammps/LAMMPSBinaryDumpParser.h
	parser/vasp/POSCARParser.h
	parser/imd/IMDAtomFileParser.h
	parser/imd/IMDParserSettingsDialog.h
	parser/dxa/DXAFileParser.h
	parser/dxa/DXAParserSettingsDialog.h
#	parser/cfg/CFGParser.h
	writer/AtomsFileWriter.h 
	writer/AbstractFileColumnWriter.h
	writer/MultiFileWriter.h	
	writer/ChannelColumnMapping.h
	writer/ChannelColumnMappingEditor.h
	writer/xyz/XYZWriter.h
	writer/xyz/XYZWriterSettingsDialog.h
	writer/lammps/LAMMPSDumpWriter.h
	writer/lammps/LAMMPSDumpWriterSettingsDialog.h
	writer/lammps/LAMMPSBinaryDumpWriter.h
	writer/lammps/LAMMPSTextDumpWriter.h
	writer/lammps/LAMMPSDataWriter.h
	writer/vasp/POSCARWriter.h
	writer/imd/IMDAtomFileWriter.h
	benchmark/AtomVizBenchmarkUtility.h
	utils/AtomInformationUtility.h
)

# The regular source files of this library.
SET(AtomViz_SRCS
	atoms/AtomsObject.cpp
	atoms/AtomsObjectEditor.cpp
	atoms/AtomType.cpp	
	atoms/SimulationCell.cpp		
	atoms/AtomsRenderer.cpp	
	atoms/AtomVizSettingsPage.cpp
	atoms/datachannels/DataChannel.cpp
	atoms/datachannels/AtomTypeDataChannel.cpp
	atoms/datachannels/PositionDataChannel.cpp
	atoms/datachannels/DisplacementDataChannel.cpp
	atoms/datachannels/OrientationDataChannel.cpp
	atoms/datachannels/DeformationGradientDataChannel.cpp
	atoms/datachannels/BondsDataChannel.cpp
	modifier/AtomsObjectModifierBase.cpp
	modifier/AtomsObjectAnalyzerBase.cpp
	modifier/slice/SliceModifier.cpp		
	modifier/coloring/AssignColorModifier.cpp		
	modifier/coloring/AtomTypeColorModifier.cpp		
	modifier/coloring/ColorCodingModifier.cpp
	modifier/ambientlighting/AmbientLightingModifier.cpp		
	modifier/analysis/cluster/ClusterAtomsModifier.cpp	
	modifier/analysis/cna/CNAModifier.cpp	
	modifier/analysis/ackland/AcklandAnalysisModifier.cpp	
	modifier/analysis/coordination/CoordinationNumberModifier.cpp
	modifier/datachannels/CreateExpressionChannelModifier.cpp		
	modifier/displacement/CalcDisplacementsModifier.cpp			
	modifier/selection/SelectAtomTypeModifier.cpp		
	modifier/selection/FreezeSelectionModifier.cpp			
	modifier/selection/InvertSelectionModifier.cpp			
	modifier/selection/SelectExpressionModifier.cpp			
	modifier/selection/SelectionModifierBase.cpp	
	modifier/deleteatoms/DeleteAtomsModifier.cpp				
	modifier/transformation/AffineTransformationModifier.cpp
	modifier/wrap/WrapPeriodicImagesModifier.cpp
	modifier/wrap/ShowPeriodicImagesModifier.cpp
	utils/ChemicalElements.cpp
	utils/NearestNeighborList.cpp
	utils/OnTheFlyNeighborList.cpp
	utils/AtomPicker.cpp
	utils/AtomInformationUtility.cpp
	parser/AtomsImportObject.cpp
	parser/AtomsFileParser.cpp
	parser/AbstractFileColumnParser.cpp
	parser/MultiFileParser.cpp
	parser/ColumnChannelMapping.cpp
	parser/ColumnChannelMappingEditor.cpp
	parser/xyz/XYZParser.cpp
	parser/xyz/XYZParserSettingsDialog.cpp
	parser/lammps/LAMMPSDataParser.cpp
	parser/lammps/LAMMPSDumpParser.cpp
	parser/lammps/LAMMPSDumpParserSettingsDialog.cpp
	parser/lammps/LAMMPSTextDumpParser.cpp
	parser/lammps/LAMMPSBinaryDumpParser.cpp
	parser/vasp/POSCARParser.cpp
	parser/imd/IMDAtomFileParser.cpp
	parser/imd/IMDParserSettingsDialog.cpp
	parser/dxa/DXAFileParser.cpp
	parser/dxa/DXAParserSettingsDialog.cpp
#	parser/cfg/CFGParser.cpp
	writer/AtomsFileWriter.cpp
	writer/AbstractFileColumnWriter.cpp
	writer/MultiFileWriter.cpp	
	writer/ChannelColumnMapping.cpp
	writer/ChannelColumnMappingEditor.cpp
	writer/xyz/XYZWriter.cpp
	writer/xyz/XYZWriterSettingsDialog.cpp
	writer/lammps/LAMMPSDumpWriter.cpp
	writer/lammps/LAMMPSDumpWriterSettingsDialog.cpp
	writer/lammps/LAMMPSBinaryDumpWriter.cpp
	writer/lammps/LAMMPSTextDumpWriter.cpp
	writer/lammps/LAMMPSDataWriter.cpp
	writer/vasp/POSCARWriter.cpp
	writer/imd/IMDAtomFileWriter.cpp
	benchmark/AtomVizBenchmarkUtility.cpp
)

# The source files of the muParser library.
SET(AtomViz_muParser_SRCS
	utils/muparser/muParser.cpp
	utils/muparser/muParserBytecode.cpp
	utils/muparser/muParserTest.cpp
	utils/muparser/muParserDLL.cpp
	utils/muparser/muParserInt.cpp
	utils/muparser/muParserTokenReader.cpp
	utils/muparser/muParserError.cpp
	utils/muparser/muParserCallback.cpp
	utils/muparser/muParserBase.cpp
)

# Add optional source file needed for POV-Ray export of atoms.
IF(OVITO_BUILD_PLUGIN_POVRAY)
	SET(AtomViz_SRCS ${AtomViz_SRCS} writer/Atoms2POVRay.cpp)
	SET(AtomViz_MOC_HDRS ${AtomViz_MOC_HDRS} writer/Atoms2POVRay.h)
ENDIF(OVITO_BUILD_PLUGIN_POVRAY)

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

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

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

# Generate plugin module.
ADD_LIBRARY(AtomViz 
	PrecompiledHeader.cpp	 
	${AtomViz_SRCS}
	${AtomViz_MOC_SRCS}	
	${AtomViz_muParser_SRCS}
)

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

# Link required libraries
TARGET_LINK_LIBRARIES(AtomViz Base Core Mesh)

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

# Link the target against the OpenGL libraries. 
TARGET_LINK_LIBRARIES(AtomViz ${OPENGL_glu_LIBRARY})

# Link to Boost IOStreams library
TARGET_LINK_LIBRARIES(AtomViz ${Boost_LIBRARIES})

# On Mac OS, we must explicitely link the Boost zlib library.
IF(APPLE)
	FIND_LIBRARY(BOOST_ZLIB_LIBRARY NAMES "boost_zlib" PATHS ${Boost_LIBRARY_DIRS})	
	TARGET_LINK_LIBRARIES(AtomViz ${BOOST_ZLIB_LIBRARY})
ENDIF(APPLE)

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

# Link to POV-Ray plugin when POV-Ray export is enabled.
IF(OVITO_BUILD_PLUGIN_POVRAY)
	TARGET_LINK_LIBRARIES(AtomViz POVRay)
ENDIF(OVITO_BUILD_PLUGIN_POVRAY)

# Build the resource files for this plugin.
QT4_COMPILE_RESOURCES(AtomViz ${OVITO_PLUGINS_DIRECTORY}/atomviz.rcc resources/atomviz.qrc)

# Assign an absolute install path to this dynamic link library.
IF(APPLE)
	SET_TARGET_PROPERTIES(AtomViz 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/AtomViz.manifest.xml" 
               "${OVITO_PLUGINS_DIRECTORY}/AtomViz.manifest.xml")

# 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/atomviz")
	INSTALL(DIRECTORY "${OVITO_SHARE_DIRECTORY}/scripts/atomviz" DESTINATION "${OVITO_RELATIVE_SHARE_DIRECTORY}/scripts/" PATTERN ".svn" EXCLUDE)
ENDIF(OVITO_BUILD_PLUGIN_SCRIPTING)

# This plugin will be part of the installation package.
IF(NOT OVITO_MONOLITHIC_BUILD)
	INSTALL(TARGETS AtomViz DESTINATION "${OVITO_RELATIVE_PLUGINS_DIRECTORY}")
ENDIF(NOT OVITO_MONOLITHIC_BUILD)
INSTALL(FILES "${OVITO_PLUGINS_DIRECTORY}/AtomViz.manifest.xml" DESTINATION "${OVITO_RELATIVE_PLUGINS_DIRECTORY}")
INSTALL(FILES "${OVITO_PLUGINS_DIRECTORY}/atomviz.rcc" DESTINATION "${OVITO_RELATIVE_PLUGINS_DIRECTORY}")
