cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
if (POLICY CMP0057)
  cmake_policy(SET CMP0057 NEW)
endif()

PROJECT(WikiExamples)

if (Module_WikiExamples)
  message(STATUS "VTKWikiExamples: Building VTKWikiExamples as a Remote VTK Module")
  message(STATUS "VTKWikiExamples: All executables will have a \"wiki\" prefix")
  set(WIKI wiki)
  vtk_module_impl()
  if(NOT EXISTS "${VTK_BINARY_DIR}/VTKConfig.cmake")
    return()
  endif()
  find_package(VTK PATHS ${VTK_BINARY_DIR})
  include(${VTK_USE_FILE})
else()
  message(STATUS "VTKWikiExamples: Building VTKWikiExamples stand-alone")
# See if VTK is using OpenGL or OpenGL2
  find_package(VTK CONFIG)
  if (NOT VTK_RENDERING_BACKEND)
    set(VTK_RENDERING_BACKEND OpenGL)
  endif()
  find_package(VTK REQUIRED)
  include(${VTK_USE_FILE})
endif()
set(WikiExamples_TEST_LABELS "foo")
message(STATUS "VTKWikiExamples: VTK VERSION: ${VTK_VERSION}(${VTK_RENDERING_BACKEND})")

set(CMAKE_MODULE_PATH ${WikiExamples_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH})

option(BUILD_TESTING "Build the testing tree." OFF)
if (BUILD_TESTING)
  ENABLE_TESTING()
  INCLUDE(CTest)
  CONFIGURE_FILE(
    ${WikiExamples_SOURCE_DIR}/CMake/SampleBuildTest.cmake.in
    ${WikiExamples_BINARY_DIR}/SampleBuildTest.cmake @ONLY)
  message(STATUS "VTKWikiExamples: Tests will be built with label \"WikiExamples\"")
else()
  message(STATUS "VTKWikiExamples: Tests will not be built")
endif ()

include(PlatformSpecificChecks)

include(WikiPolicies)
# Set the CMake Policies
WikiPolicies()

#
# Mac specific
IF(APPLE)
  SET(EXECUTABLE_FLAG MACOSX_BUNDLE)
ENDIF(APPLE)

#-----------------------------------------------------------------------------
# Output directories.
if(NOT Module_WikiExamples)
  IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
    SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${WikiExamples_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all libraries.")
  ENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  IF(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
    SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${WikiExamples_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all executables.")
  ENDIF(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  MARK_AS_ADVANCED(CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_RUNTIME_OUTPUT_DIRECTORY)
else()
    SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${VTK_BINARY_DIR}/bin)
endif()
message(STATUS "VTKWikiExamples: Example executables are stored in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")

ADD_SUBDIRECTORY(src/Cxx/Animation)
ADD_SUBDIRECTORY(src/Cxx/CompositeData)
IF(VTK_USE_MYSQL)
  ADD_SUBDIRECTORY(src/Cxx/Databases)
ENDIF(VTK_USE_MYSQL)
ADD_SUBDIRECTORY(src/Cxx/DataStructures)
if(${VTK_VERSION} VERSION_GREATER "6.10")
  ADD_SUBDIRECTORY(src/Cxx/Developers)
endif()
ADD_SUBDIRECTORY(src/Cxx/Filtering)
ADD_SUBDIRECTORY(src/Cxx/GeometricObjects)
IF(VTK_USE_INFOVIS)
  IF(VTK_USE_BOOST)
    ADD_SUBDIRECTORY(src/Cxx/Graphs)
  ENDIF(VTK_USE_BOOST)
ENDIF(VTK_USE_INFOVIS)
ADD_SUBDIRECTORY(src/Cxx/ImageData)
  ADD_SUBDIRECTORY(src/Cxx/Geovis)
ADD_SUBDIRECTORY(src/Cxx/Images)
ADD_SUBDIRECTORY(src/Cxx/ImplicitFunctions)
ADD_SUBDIRECTORY(src/Cxx/InfoVis)
ADD_SUBDIRECTORY(src/Cxx/Interaction)
ADD_SUBDIRECTORY(src/Cxx/IO)
ADD_SUBDIRECTORY(src/Cxx/Lighting)
ADD_SUBDIRECTORY(src/Cxx/Math)
ADD_SUBDIRECTORY(src/Cxx/Medical)
ADD_SUBDIRECTORY(src/Cxx/Meshes)
ADD_SUBDIRECTORY(src/Cxx/Modelling)
IF(VTK_USE_PARALLEL)
  ADD_SUBDIRECTORY(src/Cxx/Parallel)
ENDIF(VTK_USE_PARALLEL)
ADD_SUBDIRECTORY(src/Cxx/Picking)
ADD_SUBDIRECTORY(src/Cxx/Plotting)
ADD_SUBDIRECTORY(src/Cxx/PolyData)
ADD_SUBDIRECTORY(src/Cxx/Points)
ADD_SUBDIRECTORY(src/Cxx/RectilinearGrid)
ADD_SUBDIRECTORY(src/Cxx/Remote)
ADD_SUBDIRECTORY(src/Cxx/Rendering)
ADD_SUBDIRECTORY(src/Cxx/RenderMan)
ADD_SUBDIRECTORY(src/Cxx/SimpleOperations)
ADD_SUBDIRECTORY(src/Cxx/StructuredGrid)
IF(VTK_USE_TEXT_ANALYSIS)
  ADD_SUBDIRECTORY(src/Cxx/TextAnalysis)
ENDIF(VTK_USE_TEXT_ANALYSIS)
ADD_SUBDIRECTORY(src/Cxx/Texture)
ADD_SUBDIRECTORY(src/Cxx/Utilities)
ADD_SUBDIRECTORY(src/Cxx/Video)
IF(VTK_USE_VIEWS)
  ADD_SUBDIRECTORY(src/Cxx/Views)
ENDIF(VTK_USE_VIEWS)
ADD_SUBDIRECTORY(src/Cxx/Visualization)
ADD_SUBDIRECTORY(src/Cxx/VisualizationAlgorithms)
ADD_SUBDIRECTORY(src/Cxx/VolumeRendering)
ADD_SUBDIRECTORY(src/Cxx/Widgets)

# ADD_SUBDIRECTORY(Python/GeometricObjects)

if(vtkGUISupportQt_LOADED)
  message(STATUS "VTKWikiExamples: Building Qt examples")
  if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
    # Instruct CMake to run moc automatically when needed.
    set(CMAKE_AUTOMOC ON)
    # We have ui files, this will bring in the macro: qt5_wrap_ui
    find_package(Qt5Widgets REQUIRED QUIET)
  else()
    FIND_PACKAGE(Qt4 REQUIRED)
    INCLUDE(${QT_USE_FILE})
  endif()
  ADD_SUBDIRECTORY(src/Cxx/Qt)
else()
  message(STATUS "VTKWikiExamples: Not building Qt examples")
endif()

OPTION(RUN_ADMIN_TESTS "Run the admin tests" OFF)
IF( BUILD_TESTING AND RUN_ADMIN_TESTS )
  ADD_TEST(CheckPagesForImages ${WikiExamples_SOURCE_DIR}/Admin/CheckPagesForImages)
  SET_TESTS_PROPERTIES(CheckPagesForImages PROPERTIES TIMEOUT 2000)
ENDIF()
