#=============================================================================
#
#  Copyright (c) Kitware, Inc.
#  All rights reserved.
#  See LICENSE.txt for details.
#
#  This software is distributed WITHOUT ANY WARRANTY; without even
#  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#  PURPOSE.  See the above copyright notice for more information.
#
#=============================================================================

set (unit_tests)

set (unit_tests_which_require_data)

set (extra_libs)

if (ENABLE_MCC3_BINDINGS)
  add_library(mcc3_flags INTERFACE)
  target_compile_definitions(mcc3_flags INTERFACE "MCC3_EXE=\"${MCC3_EXE}\"")
  list(APPEND extra_libs mcc3_flags)

  list(APPEND unit_tests_which_require_data
    TestGenerateCrossSections.cxx)
endif ()

if (ENABLE_CUBIT_BINDINGS)
add_library(cubit_flags INTERFACE)
target_compile_definitions(cubit_flags INTERFACE
  "ASSYGEN_EXE=\"${ASSYGEN_EXE}\""
  "COREGEN_EXE=\"${COREGEN_EXE}\""
  "CUBIT_EXE=\"${CUBIT_EXE}\"")
  list(APPEND extra_libs cubit_flags)
endif ()

if (ENABLE_PYARC_BINDINGS)

  list(APPEND extra_libs smtkRGGSimulationPyARC)

  list(APPEND unit_tests_which_require_data
    ExportToPyARCOp.cxx
    TestDIF3DSimulationWorkflow.cxx)

  if (ENABLE_MCC3_BINDINGS)
    list(APPEND unit_tests_which_require_data
      TestPyARCGenerateCrossSections.cxx)

    if (ENABLE_CUBIT_BINDINGS)
      list(APPEND unit_tests
        TestProteusSNSimulationWorkflow.cxx)
    endif()

  endif()

endif()

unit_tests(
  LABEL "RGGSimulation"
  SOURCES ${unit_tests}
  SOURCES_REQUIRE_DATA ${unit_tests_which_require_data}
  LIBRARIES smtkCore smtkRGGSession smtkRGGSimulationProteus Boost::boost Boost::filesystem ${extra_libs})

set(smtk_module_dir ${smtk_DIR}/${SMTK_PYTHON_MODULEDIR})
if(NOT IS_ABSOLUTE ${smtk_module_dir})
  get_filename_component(smtk_module_dir
    ${PROJECT_BINARY_DIR}/${smtk_DIR}/${SMTK_PYTHON_MODULEDIR} ABSOLUTE)
endif()

foreach (test IN LISTS unit_tests unit_tests_which_require_data)
  get_filename_component(tname ${test} NAME_WE)
  set_tests_properties(${tname}
    PROPERTIES
    ENVIRONMENT "PYTHONPATH=${PROJECT_BINARY_DIR}:${smtk_module_dir}:${CMAKE_INSTALL_PREFIX}/${PYTHON_MODULEDIR}:$ENV{PYTHONPATH}"
    TIMEOUT 600
    SKIP_RETURN_CODE 125
    )
endforeach ()
