Salome HOME
e20113c5ddbe65976d7af02f77e532904ba5a508
[modules/kernel.git] / salome_adm / cmake_files / deprecated / FindMPI.cmake
1 # Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # ------
21 #
22 MESSAGE(STATUS "Check for MPI ...")
23
24 # ------
25
26 SET(MPI_STATUS 1)
27 IF(WITHOUT_MPI OR WITH_MPI STREQUAL 0)
28   SET(MPI_STATUS 0)
29   MESSAGE(STATUS "mpi disabled from command line.")
30 ENDIF(WITHOUT_MPI OR WITH_MPI STREQUAL 0)
31
32 IF(WITH_MPI)
33   SET(MPI_ROOT_USER ${WITH_MPI})
34 ELSE(WITH_MPI)
35   SET(MPI_ROOT_USER $ENV{MPI_ROOT})
36 ENDIF(WITH_MPI)
37
38 IF(NOT MPI_ROOT_USER)
39   FIND_PROGRAM(MPICC mpicc)
40   IF(MPICC)
41     MESSAGE(STATUS "mpicc found: ${MPICC}")
42     SET(MPI_ROOT ${MPICC})
43     GET_FILENAME_COMPONENT(MPI_ROOT ${MPI_ROOT} PATH)
44     GET_FILENAME_COMPONENT(MPI_ROOT ${MPI_ROOT} PATH)
45     IF(MPICC STREQUAL /usr/bin/mpicc)
46     ELSE(MPICC STREQUAL /usr/bin/mpicc)
47       SET(MPI_ROOT_USER ${MPI_ROOT})
48     ENDIF(MPICC STREQUAL /usr/bin/mpicc)
49   ENDIF(MPICC)
50 ELSE(NOT MPI_ROOT_USER)
51   SET(MPI_ROOT ${MPI_ROOT_USER})
52 ENDIF(NOT MPI_ROOT_USER)
53
54 # ------
55
56 IF(NOT MPI_ROOT)
57   MESSAGE(STATUS "MPI not found, try to use WITH_MPI option or MPI_ROOT environment variable.")
58   SET(MPI_STATUS 0)
59 ENDIF(NOT MPI_ROOT)
60
61 # ------
62
63 IF(MPI_STATUS)
64   MESSAGE(STATUS "Check MPI in ${MPI_ROOT}")
65
66   SET(MPI_INCLUDE_TO_FIND mpi.h)
67   
68   IF(MPI_ROOT_USER)
69     SET(MPI_ROOT ${MPI_ROOT_USER})
70     SET(MPI_INCLUDE_PATHS ${MPI_ROOT} ${MPI_ROOT}/include)
71     FIND_PATH(MPI_INCLUDES ${MPI_INCLUDE_TO_FIND} PATHS ${MPI_INCLUDE_PATHS} NO_DEFAULT_PATH)
72     IF(NOT MPI_INCLUDES)
73       MESSAGE(STATUS "MPI include ${MPI_INCLUDE_TO_FIND} not found in ${MPI_INCLUDE_PATHS}, check your MPI installation.")
74       SET(MPI_STATUS 0)
75     ENDIF(NOT MPI_INCLUDES)
76   ELSE(MPI_ROOT_USER)
77     FIND_PATH(MPI_INCLUDES ${MPI_INCLUDE_TO_FIND})
78     IF(NOT MPI_INCLUDES)
79       MESSAGE(STATUS "MPI include ${MPI_INCLUDE_TO_FIND} not found on system, try to use WITH_MPI option or MPI_ROOT environment variable.")
80       SET(MPI_STATUS 0)
81     ENDIF(NOT MPI_INCLUDES)
82     GET_FILENAME_COMPONENT(MPI_ROOT ${MPI_INCLUDES} PATH)
83   ENDIF(MPI_ROOT_USER)
84
85   IF(MPI_INCLUDES)
86     MESSAGE(STATUS "MPI include ${MPI_INCLUDE_TO_FIND} found in ${MPI_INCLUDES}")
87
88     SET(MPI_INCLUDE_DIR ${MPI_INCLUDES})
89     SET(MPI_INCLUDE_DIRS ${MPI_INCLUDES})
90     SET(MPI_INCLUDES -I${MPI_INCLUDES})# to remove
91   ENDIF(MPI_INCLUDES)
92   
93   # ------
94   
95   IF(WINDOWS)
96     FIND_LIBRARY(MPI_LIB_THREAD libboost_thread-vc90-mt-gd-1_35 ${MPI_ROOT}/lib)
97     FIND_LIBRARY(MPI_LIB_DATE_TIME libboost_date_time-vc90-mt-gd-1_35 ${MPI_ROOT}/lib)
98   ELSE(WINDOWS)
99     SET(MPI_LIB_FOUND 0)
100     FOREACH(lib mpi_cxx mpi mpich)
101       FIND_LIBRARY(MPI_LIB_${lib} ${lib} ${MPI_ROOT}/lib)
102       IF(MPI_LIB_${lib})
103         SET(MPI_LIB_FOUND 1)
104       ENDIF(MPI_LIB_${lib})
105     ENDFOREACH(lib mpi_cxx mpi mpich)
106     IF(MPI_LIB_FOUND)
107       IF(MPI_LIB_mpi_cxx AND MPI_LIB_mpi)
108         SET(MPI_LIBS ${MPI_LIB_mpi_cxx} ${MPI_LIB_mpi})
109         SET(MPI_INCLUDES ${MPI_INCLUDES} -DOMPI_IGNORE_CXX_SEEK)# to remove
110         SET(MPI_DEFINITIONS -DOMPI_IGNORE_CXX_SEEK)
111       ELSEIF(MPI_LIB_mpi_cxx)
112         SET(MPI_LIBS ${MPI_LIB_mpi_cxx})
113         SET(MPI_INCLUDES ${MPI_INCLUDES} -DOMPI_IGNORE_CXX_SEEK)# to remove
114         SET(MPI_DEFINITIONS -DOMPI_IGNORE_CXX_SEEK)
115       ELSEIF(MPI_LIB_mpi)
116         SET(MPI_LIBS ${MPI_LIB_mpi})
117         SET(MPI_INCLUDES ${MPI_INCLUDES} -DOMPI_IGNORE_CXX_SEEK)# to remove
118         SET(MPI_DEFINITIONS -DOMPI_IGNORE_CXX_SEEK)
119       ELSEIF(MPI_LIB_mpich)
120         SET(MPI_LIBS ${MPI_LIB_mpich})
121         SET(MPI_INCLUDES ${MPI_INCLUDES} -DMPICH_IGNORE_CXX_SEEK)# to remove
122         SET(MPI_DEFINITIONS -DMPICH_IGNORE_CXX_SEEK)
123       ENDIF()
124     ELSE(MPI_LIB_FOUND)
125       MESSAGE(STATUS "MPI lib not found, check your MPI installation.")
126       SET(MPI_STATUS 0)
127     ENDIF(MPI_LIB_FOUND)
128   ENDIF(WINDOWS)
129   MESSAGE(STATUS "MPI libs: ${MPI_LIBS}")
130 ENDIF(MPI_STATUS)
131   
132 # ------
133
134 IF(MPI_STATUS)
135   include(CheckSymbolExists)
136   SET(CMAKE_REQUIRED_LIBRARIES ${MPI_LIBS})
137   CHECK_SYMBOL_EXISTS(MPI_Publish_name ${MPI_INCLUDE_DIR}/mpi.h MPI2_IS_OK)
138   IF(MPI2_IS_OK)
139     MESSAGE(STATUS "Your mpi implemtentation is compatible with mpi2 ... adding -DHAVE_MPI2")
140     SET(MPI_INCLUDES ${MPI_INCLUDES} -DHAVE_MPI2)# to remove
141     SET(MPI_DEFINITIONS "${MPI_DEFINITIONS} -DHAVE_MPI2")
142   ENDIF(MPI2_IS_OK)
143 ENDIF(MPI_STATUS)
144
145 # ------
146
147 IF(MPI_STATUS)
148   SET(MPI_IS_OK ON)
149 ELSE(MPI_STATUS)
150   IF(MPI_IS_MANDATORY)
151     MESSAGE(FATAL_ERROR "MPI not found but mandatory")
152   ELSE(MPI_IS_MANDATORY)
153     MESSAGE(STATUS "MPI not found. Build procedure depending of mpi will be disable")
154   ENDIF(MPI_IS_MANDATORY)
155 ENDIF(MPI_STATUS)