enable_testing()

if (EZTRACE_ENABLE_MPI)
  set(CMAKE_C_COMPILER ${MPICC})
  set(CMAKE_Fortran_COMPILER ${MPIF90})

  add_executable(mpi_ping mpi_ping.c)
  add_test (build_mpi_ping "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target mpi_ping)

  add_executable(mpi_pthread mpi_pthread.c)
  TARGET_LINK_LIBRARIES(mpi_pthread pthread)
  add_test (build_mpi_pthread "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target mpi_pthread)

  add_executable(waitall waitall.c)
  add_test (build_waitall "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target waitall)

  add_test (NAME mpi_tests COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" "${CMAKE_CURRENT_BINARY_DIR}")
  set_tests_properties(mpi_tests PROPERTIES DEPENDS "build_mpi_ping;build_mpi_pthread;build_waitall")

  set(EZTRACE_LIBRARY_PATH "${EZTRACE_LIBRARY_PATH}:${CMAKE_BINARY_DIR}/src/modules/mpi")

  # Get the list of tests, and set environment variables
  get_property(test_list DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
  set_property(TEST ${test_list}
    PROPERTY ENVIRONMENT
    "EZTRACE_LIBRARY_PATH=${EZTRACE_LIBRARY_PATH}"
    ${TEST_ENVIRONMENT}
  )
endif()
