SET(python_runtime "@PYTHON_EXECUTABLE@")
SET(python_binary_dir "@CMAKE_CURRENT_BINARY_DIR@")

SET(ENV{PYTHONPATH} "${PYTHONPATH}${SEPARATOR}$ENV{PYTHONPATH}")
SET(ENV{PATH} "${PATH}${SEPARATOR}$ENV{PATH}")

set(XDMF_DSM_IS_CRAY "@XDMF_DSM_IS_CRAY@")
if (XDMF_DSM_IS_CRAY)
#  message("Cray Style")
  SET(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}${SEPARATOR}${LDPATH}")
else (XDMF_DSM_IS_CRAY)
#  message("Normal Style")
  SET(ENV{LD_LIBRARY_PATH} "${LDPATH}${SEPARATOR}$ENV{LD_LIBRARY_PATH}")
endif (XDMF_DSM_IS_CRAY)

SET(ENV{PYTHON_EXECUTABLE} "${python_runtime}")
SET(ENV{MPIEXEC} "@MPIEXEC@")

MESSAGE("| Calling:\t ${EXECUTABLE} ${ARGUMENTS}")
EXECUTE_PROCESS(
        COMMAND "${EXECUTABLE}" ${ARGUMENTS}
                WORKING_DIRECTORY "${python_binary_dir}"
                RESULT_VARIABLE python_result
                OUTPUT_VARIABLE python_output
                ERROR_VARIABLE python_error
)

MESSAGE("| Call Result:\t${python_result}")
MESSAGE("| Call Output: Begin\n${python_output}")
MESSAGE("| Call Output: End")
IF(python_error)
        MESSAGE("Call Error: Begin\n${python_error}")
        MESSAGE("Call Error: End")
ENDIF()
MESSAGE("| Call Ended")
MESSAGE("----------------------------------------------------------")

# Let's make sure that if the test failed, it failed with CTest too
IF(python_result)
        MESSAGE(SEND_ERROR "${python_result}")
ENDIF()
