PROJECT(ParaView)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5)

#########################################################################
# Warn about ParaQ
SET(PARAVIEW_WARN_ABOUT_PARAQ)
IF(EXISTS "${ParaView_SOURCE_DIR}/CVS/Root")
  FILE(READ "${ParaView_SOURCE_DIR}/CVS/Root" paraview_cvs_root)
  IF("${paraview_cvs_root}" MATCHES ParaQ)
    SET(PARAVIEW_WARN_ABOUT_PARAQ 1)
  ENDIF("${paraview_cvs_root}" MATCHES ParaQ)
ENDIF(EXISTS "${ParaView_SOURCE_DIR}/CVS/Root")
IF("${ParaView_SOURCE_DIR}" MATCHES "ParaQ")
  SET(PARAVIEW_WARN_ABOUT_PARAQ 1)
ENDIF("${ParaView_SOURCE_DIR}" MATCHES "ParaQ")
IF(PARAVIEW_WARN_ABOUT_PARAQ)
  MESSAGE(SEND_ERROR "ParaView 3 should be checked out from ParaView3 repository. ParaQ repository is deprecated and will be removed")
ENDIF(PARAVIEW_WARN_ABOUT_PARAQ)

#########################################################################
# Disallow in-source build
STRING(COMPARE EQUAL "${ParaView_SOURCE_DIR}" 
  "${ParaView_BINARY_DIR}" INSOURCE)
IF(INSOURCE)
  MESSAGE(FATAL_ERROR "ParaView requires an out of source Build. Please create a separate binary directory and run CMake there.")
ENDIF(INSOURCE)

#########################################################################
SET(PARAVIEW_VERSION_MAJOR 3)
SET(PARAVIEW_VERSION_MINOR 0)
SET(PARAVIEW_VERSION_PATCH 1)
SET(PARAVIEW_VERSION "${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR}")
SET(PARAVIEW_VERSION_FULL "${PARAVIEW_VERSION}.${PARAVIEW_VERSION_PATCH}")

# See VTK/CMakeLists.txt for an explanation of this default selection.
IF(PARAVIEW_VERSION_MINOR MATCHES "[02468]$")
  # This is a release version.  Default to not use rpath.
  SET(VTK_USE_RPATH_DEFAULT OFF)
ELSE(PARAVIEW_VERSION_MINOR MATCHES "[02468]$")
  # This is a development version.  Default to use rpath.
  SET(VTK_USE_RPATH_DEFAULT ON)
ENDIF(PARAVIEW_VERSION_MINOR MATCHES "[02468]$")

#########################################################################
# build VTK/Qt support
OPTION(PARAVIEW_BUILD_QT_GUI "Build ParaView Qt Client. This requires Qt." ON)
MARK_AS_ADVANCED(PARAVIEW_BUILD_QT_GUI)
IF (PARAVIEW_BUILD_QT_GUI)
  SET(VTK_USE_GUISUPPORT ON CACHE BOOL "Build VTK with GUI Support" FORCE)
  SET(VTK_USE_QVTK ON CACHE BOOL "Build VTK with Qt Support" FORCE)
  SET(DESIRED_QT_VERSION 4 CACHE STRING "Use Qt4" FORCE)
  # Mark these Qt variables as advanced. Users don't really have to set them.
  MARK_AS_ADVANCED(DESIRED_QT_VERSION VTK_USE_QVTK VTK_USE_GUISUPPORT)
  MARK_AS_ADVANCED(QT_MKSPECS_DIR QT_PLUGINS_DIR QT_X11_X11_LIBRARY QT_X11_Xext_LIBRARY QT_X11_m_LIBRARY)
ELSE (PARAVIEW_BUILD_QT_GUI)
  SET(VTK_USE_QVTK OFF CACHE BOOL "Build VTK with Qt Support" FORCE)
ENDIF (PARAVIEW_BUILD_QT_GUI)


# Work around CMake 2.2.x FindPythonLibs bug.
# Do not find Python subdirectory as python debug library.
SET(PYTHON_DEBUG_LIBRARY "" CACHE FILEPATH "Purposely empty: work around CMake FindPythonLibs bug")
MARK_AS_ADVANCED(PYTHON_DEBUG_LIBRARY)

#########################################################################
# Define a PARAVIEW_USE_MPI that is not advanced
SET(PARAVIEW_USE_MPI OFF CACHE BOOL "Build ParaView with MPI support")
SET(VTK_USE_MPI ${PARAVIEW_USE_MPI} CACHE INTERNAL "Build VTK with MPI support" FORCE)
# define this variable so that VTK_DEPENDENT_OPTION in the VTK 
# CMakeLists.txt does not turn VTK_USE_MPI back to a regular cache
# variable
# set it to PARAVIEW_USE_MPI so that VTK_USE_MPI is slaved to it.
SET(VTK_USE_MPI_ISSET ${PARAVIEW_USE_MPI})

#########################################################################
# Force Infovis support on
SET(VTK_USE_INFOVIS ON CACHE BOOL "Build VTK with Infovis Support" FORCE)
MARK_AS_ADVANCED(VTK_USE_INFOVIS)

#########################################################################
# Configure Testing
OPTION(BUILD_TESTING "Build ParaView Testing" ON)
IF(BUILD_TESTING)
  SET(PARAVIEW_TEST_DIR    ${ParaView_BINARY_DIR}/Testing/Temporary)
  MAKE_DIRECTORY(${PARAVIEW_TEST_DIR})
  ENABLE_TESTING()
  INCLUDE (CTest)
ENDIF(BUILD_TESTING)

#########################################################################
# Configure data directory
IF(NOT PARAVIEW_DATA_ROOT AND PARAQ_DATA_ROOT)
  SET(PARAVIEW_DATA_ROOT "${PARAQ_DATA_ROOT}")
ENDIF(NOT PARAVIEW_DATA_ROOT AND PARAQ_DATA_ROOT)
FIND_PATH(PARAVIEW_DATA_ROOT ParaViewData.readme
  ${ParaView_SOURCE_DIR}/ParaViewData
  ${ParaView_SOURCE_DIR}/../ParaViewData
  ${ParaView_SOURCE_DIR}/ParaQData
  ${ParaView_SOURCE_DIR}/../ParaQData
  $ENV{PARAVIEW_DATA_ROOT}
  )

#########################################################################
# Configure Python
OPTION(PARAVIEW_ENABLE_PYTHON "Enable/Disable Python scripting support." OFF)

# PARAVIEW_TESTING_WITH_PYTHON must be used only when PARAVIEW_ENABLE_PYTHON 
# is ON. If PARAVIEW_ENABLE_PYTHON is OFF, PARAVIEW_TESTING_WITH_PYTHON 
# is ignored and treated as disabled.
OPTION(PARAVIEW_TESTING_WITH_PYTHON 
    "Build Python Testing support if PARAVIEW_ENABLE_PYTHON is ON"  
    ON)
MARK_AS_ADVANCED(PARAVIEW_TESTING_WITH_PYTHON)

IF (PARAVIEW_TESTING_WITH_PYTHON AND PARAVIEW_ENABLE_PYTHON)
  SET (QT_TESTING_WITH_PYTHON ON)
ELSE (PARAVIEW_TESTING_WITH_PYTHON AND PARAVIEW_ENABLE_PYTHON)
  SET (QT_TESTING_WITH_PYTHON OFF)
ENDIF (PARAVIEW_TESTING_WITH_PYTHON AND PARAVIEW_ENABLE_PYTHON)

IF (PARAVIEW_ENABLE_PYTHON)
  SET(BUILD_SHARED_LIBS ON CACHE BOOL "Build ParaView using shared libraries" FORCE)
ENDIF (PARAVIEW_ENABLE_PYTHON)

#########################################################################
IF(BUILD_SHARED_LIBS)
  ADD_DEFINITIONS(-DPARAVIEW_BUILD_SHARED_LIBS)
ENDIF(BUILD_SHARED_LIBS)


#########################################################################
# Set the ServerManager test data dir,
SET(PVServerManagerTestData ${PARAVIEW_DATA_ROOT})

# Find hints file for the client/server wrapping
FIND_FILE(VTK_WRAP_HINTS hints ${ParaView_SOURCE_DIR}/VTK/Wrapping)
MARK_AS_ADVANCED(VTK_WRAP_HINTS)

#########################################################################
# Include the file that most of the environment setup (except GUI).
SET(ParaView_SOURCE_DIR ${ParaView_SOURCE_DIR})
SET(ParaView_BINARY_DIR ${ParaView_BINARY_DIR})
INCLUDE(${ParaView_SOURCE_DIR}/CMake/ParaViewCommon.cmake)

#########################################################################
IF(BUILD_DOCUMENTATION)
  ADD_SUBDIRECTORY(Utilities/Doxygen)
ENDIF(BUILD_DOCUMENTATION)
ADD_SUBDIRECTORY(Documentation)

#########################################################################
CONFIGURE_FILE(${ParaView_SOURCE_DIR}/vtkPQConfig.h.in
  ${ParaView_BINARY_DIR}/vtkPQConfig.h
  ESCAPE_QUOTES)

#########################################################################
IF (PARAVIEW_BUILD_QT_GUI)
  ADD_SUBDIRECTORY(Qt)
ENDIF (PARAVIEW_BUILD_QT_GUI)

#########################################################################
IF (PARAVIEW_BUILD_QT_GUI)
  ADD_SUBDIRECTORY(Applications)
ENDIF (PARAVIEW_BUILD_QT_GUI)

#########################################################################
OPTION(BUILD_EXAMPLES "Build ParaView examples." OFF)
IF (BUILD_EXAMPLES)
  ADD_SUBDIRECTORY(Examples)
ENDIF (BUILD_EXAMPLES)

# If the cmake version includes cpack, use it
INCLUDE(InstallRequiredSystemLibraries)
SET(CPACK_INSTALL_CMAKE_PROJECTS "${ParaView_BINARY_DIR};ParaView;Runtime;/;${ParaView_BINARY_DIR};VTK Runtime Libs;RuntimeLibraries;/;${ParaView_BINARY_DIR};VTK Executables;RuntimeExecutables;/")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ParaView is a scientific visualization tool")
SET(CPACK_PACKAGE_VENDOR "Kitware Inc.")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/License_v1.1.txt")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License_v1.1.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "${PARAVIEW_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${PARAVIEW_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${PARAVIEW_VERSION_PATCH}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "ParaView ${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR}.${PARAVIEW_VERSION_PATCH}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME
  "paraview-${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR}.${PARAVIEW_VERSION_PATCH}")
IF (CMAKE_SYSTEM_PROCESSOR MATCHES "unknown")
  SET (CMAKE_SYSTEM_PROCESSOR "x86")
ENDIF (CMAKE_SYSTEM_PROCESSOR MATCHES "unknown")
IF(NOT DEFINED CPACK_SYSTEM_NAME)
  SET(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR})
ENDIF(NOT DEFINED CPACK_SYSTEM_NAME)
IF(${CPACK_SYSTEM_NAME} MATCHES Windows)
  IF(CMAKE_CL_64)
    SET(CPACK_SYSTEM_NAME win64-${CMAKE_SYSTEM_PROCESSOR})
  ELSE(CMAKE_CL_64)
    SET(CPACK_SYSTEM_NAME win32-${CMAKE_SYSTEM_PROCESSOR})
  ENDIF(CMAKE_CL_64)
ENDIF(${CPACK_SYSTEM_NAME} MATCHES Windows)
IF(NOT DEFINED CPACK_PACKAGE_FILE_NAME)
  SET(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}-${CPACK_SYSTEM_NAME}")
ENDIF(NOT DEFINED CPACK_PACKAGE_FILE_NAME)
SET(CPACK_PACKAGE_EXECUTABLES "paraview" "ParaView")
IF(WIN32 AND NOT UNIX)
  # There is a bug in NSI that does not handle full unix paths properly. Make
  # sure there is at least one set of four (4) backlasshes.
  SET(CPACK_PACKAGE_ICON "${ParaView_SOURCE_DIR}/Applications/Client\\\\ParaViewLogo.png")
  SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\paraview.exe")
  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} a cross-platform, open-source visualization system")
  SET(CPACK_NSIS_HELP_LINK "http://www.paraview.org")
  SET(CPACK_NSIS_URL_INFO_ABOUT "http://www.kitware.com")
  SET(CPACK_NSIS_CONTACT "webmaster@paraview.org")
  #    SET(CPACK_NSIS_MODIFY_PATH ON)
ELSE(WIN32 AND NOT UNIX)
  SET(CPACK_STRIP_FILES "")
  SET(CPACK_SOURCE_STRIP_FILES "")
  IF (NOT APPLE)
    SET(CPACK_GENERATOR TGZ)
  ENDIF (NOT APPLE)
ENDIF(WIN32 AND NOT UNIX)
INCLUDE(CPack)

#########################################################################
# Additional definitions for ParaViewConfig.cmake

SET(PARAVIEW_USE_FILE "${ParaView_SOURCE_DIR}/ParaViewUse.cmake")
SET(PARAVIEW_VTK_DIR "${ParaView_BINARY_DIR}/VTK")

SET(PARAVIEW_CMAKE_EXTENSIONS "${ParaView_SOURCE_DIR}/VTK/CMake")
SET(PARAVIEW_CMAKE_CLIENT_SERVER_EXTENSION 
  "${ParaView_SOURCE_DIR}/Utilities/VTKClientServer/CMake/vtkWrapClientServer.cmake")
SET(VTK_WRAP_ClientServer_EXE_CONFIG ${VTK_WRAP_ClientServer_EXE})
SET(PARAVIEW_LIBRARY_DIRS 
  ${LIBRARY_OUTPUT_PATH} ${PARAVIEW_EXTRA_LINK_DIRECTORIES})

SET(PARAVIEW_GUI_INCLUDE_DIRS ${ParaView_SOURCE_DIR}/Qt/Widgets
                              ${ParaView_SOURCE_DIR}/Qt/Core
                              ${ParaView_SOURCE_DIR}/Qt/Components )
SET(PARAVIEW_KWSYS_INCLUDE_DIRS ${PARAVIEW_INCLUDE_DIRS})

GET_TARGET_PROPERTY(PARAVIEW_GUI_CLIENT_EXECUTABLE paraview${PV_EXE_SUFFIX} LOCATION)
GET_TARGET_PROPERTY(PARAVIEW_BATCH_EXECUTABLE pvbatch${PV_EXE_SUFFIX} LOCATION)
GET_TARGET_PROPERTY(PARAVIEW_PROCESS_XML_EXECUTABLE kwProcessXML LOCATION)
SET(PARAVIEW_SERVER_MANAGER_RESOURCES_DIRECTORY 
  "${ParaView_SOURCE_DIR}/Servers/ServerManager/Resources")
SET(VTKCS_SOURCE_DIR 
  "${ParaView_SOURCE_DIR}/Utilities/VTKClientServer")

# The ParaView library dependencies.
SET(PARAVIEW_LIBRARY_DEPENDS_FILE
  "${ParaView_BINARY_DIR}/ParaViewLibraryDepends.cmake")
EXPORT_LIBRARY_DEPENDENCIES(${PARAVIEW_LIBRARY_DEPENDS_FILE})

# Perform configuration.
CONFIGURE_FILE(${ParaView_SOURCE_DIR}/ParaViewConfig.cmake.in
               ${ParaView_BINARY_DIR}/ParaViewConfig.cmake @ONLY IMMEDIATE)

# Mark certain VTK variables as advanced. Users do not really have to set these.
IF (APPLE)
  MARK_AS_ADVANCED(CMAKE_OSX_ARCHITECTURES CMAKE_OSX_SYSROOT VTK_USE_CARBON VTK_USE_COCOA VTK_APPLE_RESOURCE)
ENDIF(APPLE)
MARK_AS_ADVANCED(VTK_USE_MPEG2_ENCODER QT_PLUGINS_DIR QT_MKSPECS_DIR)
