diff --git a/cmake/unit_test.cmake b/cmake/unit_test.cmake index 2636d4e993e..2d652c90466 100644 --- a/cmake/unit_test.cmake +++ b/cmake/unit_test.cmake @@ -1,3 +1,13 @@ +if(EXISTS ${MPIEXEC}) + # OpenMPI 3.0 and higher checks the number of processes against the number of CPUs + execute_process(COMMAND ${MPIEXEC} --version RESULT_VARIABLE mpi_version_result OUTPUT_VARIABLE mpi_version_output ERROR_VARIABLE mpi_version_output) + if (mpi_version_result EQUAL 0 AND mpi_version_output MATCHES "\\(Open(RTE| MPI)\\) ([3-9]\\.|1[0-9])") + set(MPIEXEC_OVERSUBSCRIBE "-oversubscribe") + else() + set(MPIEXEC_OVERSUBSCRIBE "") + endif() +endif() + # unit_test function function(UNIT_TEST) cmake_parse_arguments(TEST "" "NAME;NUM_PROC" "SRC;DEPENDS" ${ARGN}) @@ -31,13 +41,6 @@ function(UNIT_TEST) endif() endif() - # OpenMPI 3.0 and higher checks the number of processes against the number of CPUs - execute_process(COMMAND ${MPIEXEC} --version RESULT_VARIABLE mpi_version_result OUTPUT_VARIABLE mpi_version_output ERROR_VARIABLE mpi_version_output) - if (mpi_version_result EQUAL 0 AND mpi_version_output MATCHES "\\(Open(RTE| MPI)\\) ([3-9]\\.|1[0-9])") - set(MPIEXEC_OVERSUBSCRIBE "-oversubscribe") - else() - set(MPIEXEC_OVERSUBSCRIBE "") - endif() add_test(${TEST_NAME} ${MPIEXEC} ${MPIEXEC_OVERSUBSCRIBE} ${MPIEXEC_NUMPROC_FLAG} ${TEST_NUM_PROC} ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} ${MPIEXEC_POSTFLAGS}) else( ) add_test(${TEST_NAME} ${TEST_NAME})