cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(TestFramework)

set(_vtk_not_found_msg "Unable to find the VTK build folder.")
# Display VTK version
find_package(VTK CONFIG QUIET)
if (NOT VTK_FOUND)
  message(FATAL_ERROR "${_vtk_not_found_msg}")
endif()

if(NOT VTK_BINARY_DIR)
  if (NOT VTK_FOUND)
    message("Skipping build: ${_vtk_not_found_msg}")
    return ()
  endif()
endif()

message(STATUS "${CMAKE_PROJECT_NAME}: VTK VERSION ${VTK_VERSION}")

# Display type of build
set(_msg "${CMAKE_PROJECT_NAME}: Building stand-alone testing")
if(VTK_BINARY_DIR)
  message(STATUS "${_msg} - no")
else()
  message(STATUS "${_msg} - yes")
endif()

# Display build properties
set(_msg "${CMAKE_PROJECT_NAME}: Setting executables prefix")
if(VTK_BINARY_DIR)
  set(WIKI "")
  message(STATUS "${_msg} - yes [prefix: ${WIKI}]")
else()
  set(WIKI "")
  message(STATUS "${_msg} - no")
endif()


#-----------------------------------------------------------------------------
# Set the C++ Standard.
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to be used")
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE STRING "C++ standard to be used")

message(STATUS "C++ standard:  C++${CMAKE_CXX_STANDARD}")

#-----------------------------------------------------------------------------
set(CMAKE_MODULE_PATH
  ${TestFramework_SOURCE_DIR}/CMake
  ${CMAKE_MODULE_PATH}
  ${VTK_CMAKE_DIR}
  )

#-----------------------------------------------------------------------------
option(BUILD_TESTING "Build testing" ON)

#-----------------------------------------------------------------------------
# See: https://docs.vtk.org/en/latest/release_details/9.4/image-testing-framework.html
option(DEFAULT_USE_SSIM_IMAGE_COMP "SSIM comparison" ON)
if(DEFAULT_USE_SSIM_IMAGE_COMP)
  set(VTK_TESTING_IMAGE_COMPARE_METHOD "TIGHT_VALID" CACHE STRING "SSIM comparison method")
  message(STATUS "SSIM comparison method: ${VTK_TESTING_IMAGE_COMPARE_METHOD}")
endif()

#-----------------------------------------------------------------------------
include(EgOutputDirectories)
include(EgPlatformSpecificChecks)
include(EgPolicies)
include(EgTestingConfig)
include(EgLoadMacros)

#-----------------------------------------------------------------------------
# Mac specific
if(APPLE)
  set(EXECUTABLE_FLAG MACOSX_BUNDLE)
endif()

#-----------------------------------------------------------------------------
add_subdirectory(src/Cxx/MyCode)

# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")

configure_file(
  "${PROJECT_SOURCE_DIR}/CMake/CTestCustom.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake"
  @ONLY)
message(STATUS "")
