# Definition of ctest for phonons extended example
# This file is included by Geant4 ctest "external" tests defintion file
# This can be found in:
#     <geant4-source>/tests/ctest/CMakeLists.txt

#Check if we are in a MT specific build
set(_MTsuffix "")
if(GEANT4_BUILD_MULTITHREADED)
  # use MATCHES to match also AppleClang
  if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    set(_MTsuffix "-clang-MT")
  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    set(_MTsuffix "-MT")
  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    set(_MTsuffix "-clang-MT")
  elseif(MSVC)
    set(_MTsuffix "-win-MT") 
  endif()
endif()

set(_compareScript ${CMAKE_SOURCE_DIR}/examples/extended/exoticphysics/phonon/ComparePhonon.cmake)
set(_causticRef ${CMAKE_SOURCE_DIR}/examples/extended/exoticphysics/phonon/caustic.out)
set(_timingRef ${CMAKE_SOURCE_DIR}/examples/extended/exoticphysics/phonon/timing.out)

#Check if specific OS references are available, if not use default
if(EXISTS ${_causticRef}${_MTsuffix})
  set(_causticRef ${_causticRef}${_MTsuffix})
else()
  message("-- G4 Examples: example-ext-exoticphysics-phonons, cannot find"
    " caustic.out${_MTsuffix} references, using default caustic.out")
endif()

if(EXISTS ${_timingRef}${_MTsuffix})
  set(_timingRef ${_timingRef}${_MTsuffix})
else()
  message("-- G4 Examples: example-ext-exoticphysics-phonons, cannot find"
    " timing.out${_MTsuffix} references, using default timing.out")
endif()

# Split tests into build, run, then comparison
# 1. Build
geant4_add_test(example-ext-exoticphysics-phonons-build
  SOURCE_DIR ${PROJECT_SOURCE_DIR}/examples/extended/exoticphysics/phonon
  BINARY_DIR ${PROJECT_BINARY_DIR}/examples/extended/exoticphysics/phonon
  BUILD XGeBox
  ENVIRONMENT ${GEANT4_TEST_ENVIRONMENT})

# GF: disable temporarily
if(FALSE)

# 2. Run
geant4_add_test(example-ext-exoticphysics-phonons-run
  COMMAND ${PROJECT_BINARY_DIR}/examples/extended/exoticphysics/phonon/XGeBox
          ${PROJECT_SOURCE_DIR}/examples/extended/exoticphysics/phonon/run.in
  WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/examples/extended/exoticphysics/phonon
  DEPENDS example-ext-exoticphysics-phonons-build
  ENVIRONMENT ${GEANT4_TEST_ENVIRONMENT}
              G4LATTICEDATA=${CMAKE_SOURCE_DIR}/examples/extended/exoticphysics/phonon/CrystalMaps)

# 3. Compare
geant4_add_test(example-ext-exoticphysics-phonons-timecomp
  DEPENDS example-ext-exoticphysics-phonons-run
  WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/examples/extended/exoticphysics/phonon
  COMMAND ${CMAKE_COMMAND} -Dtest_file=timing.ssv -Dreference_file=${_timingRef} -P ${_compareScript})

geant4_add_test(example-ext-exoticphysics-phonons-causticcomp
  DEPENDS example-ext-exoticphysics-phonons-run
  WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/examples/extended/exoticphysics/phonon
  COMMAND ${CMAKE_COMMAND} -Dtest_file=caustic.ssv -Dreference_file=${_causticRef} -P ${_compareScript})

endif()
