Fix usage of CMAKE_REQUIRED_*
[alexxy/gromacs.git] / cmake / gmxTestMPI_IN_PLACE.cmake
1 # - Define macro to check if MPI_IN_PLACE exists
2 #
3 #  GMX_TEST_MPI_IN_PLACE(VARIABLE)
4 #
5 #  VARIABLE will be set to true if MPI_IN_PLACE exists
6 #
7
8 include(CheckCSourceCompiles)
9 MACRO(GMX_TEST_MPI_IN_PLACE VARIABLE)
10   if(NOT DEFINED MPI_IN_PLACE_COMPILE_OK)
11     MESSAGE(STATUS "Checking for MPI_IN_PLACE")
12
13     set(CMAKE_REQUIRED_DEFINITIONS ${MPI_COMPILE_FLAGS})
14     set(CMAKE_REQUIRED_INCLUDES ${MPI_INCLUDE_PATH})
15     set(CMAKE_REQUIRED_LIBRARIES ${MPI_LIBRARIES})
16     check_c_source_compiles(
17       "#include <mpi.h>
18 int main(void) {
19   void* buf;
20   MPI_Allreduce(MPI_IN_PLACE, buf, 10, MPI_FLOAT, MPI_SUM, MPI_COMM_WORLD);
21 }" MPI_IN_PLACE_COMPILE_OK)
22
23     if(MPI_IN_PLACE_COMPILE_OK)
24         MESSAGE(STATUS "Checking for MPI_IN_PLACE - yes")
25     else(MPI_IN_PLACE_COMPILE_OK)
26         MESSAGE(STATUS "Checking for MPI_IN_PLACE - no")
27     endif(MPI_IN_PLACE_COMPILE_OK)
28     set(MPI_IN_PLACE_COMPILE_OK "${MPI_IN_PLACE_COMPILE_OK}" CACHE INTERNAL "Result of mpi_in_place check")
29     set(CMAKE_REQUIRED_DEFINITIONS)
30     set(CMAKE_REQUIRED_INCLUDES)
31     set(CMAKE_REQUIRED_LIBRARIES)
32   endif()
33   if (MPI_IN_PLACE_COMPILE_OK)
34     set(${VARIABLE} ${MPI_IN_PLACE_COMPILE_OK} 
35       "Result of test for MPI_IN_PLACE")
36   endif()
37 ENDMACRO(GMX_TEST_MPI_IN_PLACE VARIABLE)
38
39
40