Salome HOME
Small fix for check_openmpi.m4
[modules/kernel.git] / salome_adm / cmake_files / FindPTHREADS.cmake
1 #  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 # ------
24
25 MESSAGE(STATUS "Check for pthreads ...")
26
27 # ------
28
29 IF(PTHREADS_IS_MANDATORY STREQUAL 0)
30   SET(PTHREADS_IS_MANDATORY 0)
31   SET(PTHREADS_IS_OPTIONAL 1)
32 ENDIF(PTHREADS_IS_MANDATORY STREQUAL 0)
33 IF(PTHREADS_IS_OPTIONAL STREQUAL 0)
34   SET(PTHREADS_IS_MANDATORY 1)
35   SET(PTHREADS_IS_OPTIONAL 0)
36 ENDIF(PTHREADS_IS_OPTIONAL STREQUAL 0)
37 IF(NOT PTHREADS_IS_MANDATORY AND NOT PTHREADS_IS_OPTIONAL)
38   SET(PTHREADS_IS_MANDATORY 1)
39   SET(PTHREADS_IS_OPTIONAL 0)
40 ENDIF(NOT PTHREADS_IS_MANDATORY AND NOT PTHREADS_IS_OPTIONAL)
41
42 # ------
43
44 SET(PTHREADS_STATUS 1)
45 IF(WITHOUT_PTHREADS OR WITH_PTHREADS STREQUAL 0)
46   SET(PTHREADS_STATUS 0)
47   MESSAGE(STATUS "pthreads disabled from command line.")
48 ENDIF(WITHOUT_PTHREADS OR WITH_PTHREADS STREQUAL 0)
49
50 # ------
51
52 IF(PTHREADS_STATUS)
53   IF(WITH_PTHREADS)
54     SET(PTHREADS_ROOT_USER ${WITH_PTHREADS})
55   ELSE(WITH_PTHREADS)
56     SET(PTHREADS_ROOT_USER $ENV{PTHREADS_ROOT})
57   ENDIF(WITH_PTHREADS)
58 ENDIF(PTHREADS_STATUS)
59
60 # -----
61
62 IF(PTHREADS_STATUS)
63   IF(PTHREADS_ROOT_USER)
64     SET(PTHREADS_FIND_PATHS_OPTION NO_DEFAULT_PATH)
65   ELSE(PTHREADS_ROOT_USER)
66     SET(PTHREADS_FIND_PATHS_OPTION)
67   ENDIF(PTHREADS_ROOT_USER)
68 ENDIF(PTHREADS_STATUS)
69
70 # -----
71
72 IF(PTHREADS_STATUS)
73   IF(PTHREADS_ROOT_USER)
74     SET(PTHREADS_INCLUDE_PATHS ${PTHREADS_ROOT_USER}/include)
75   ELSE(PTHREADS_ROOT_USER)
76     SET(PTHREADS_INCLUDE_PATHS)
77   ENDIF(PTHREADS_ROOT_USER)
78   SET(PTHREADS_INCLUDE_TO_FIND pthread.h)
79   FIND_PATH(PTHREADS_INCLUDE_DIR ${PTHREADS_INCLUDE_TO_FIND} PATHS ${PTHREADS_INCLUDE_PATHS} ${PTHREADS_FIND_PATHS_OPTION})
80   IF(PTHREADS_INCLUDE_DIR)
81     IF(PTHREADS_ROOT_USER)
82       SET(PTHREAD_CFLAGS -I${PTHREADS_INCLUDE_DIR})
83     ENDIF(PTHREADS_ROOT_USER)
84     MESSAGE(STATUS "${PTHREADS_INCLUDE_TO_FIND} found in ${PTHREADS_INCLUDE_DIR}")
85   ELSE(PTHREADS_INCLUDE_DIR)
86     SET(PTHREADS_STATUS 0)
87     IF(PTHREADS_ROOT_USER)
88       MESSAGE(STATUS "${PTHREADS_INCLUDE_TO_FIND} not found in ${PTHREADS_INCLUDE_PATHS}, check your PTHREADS installation.")
89     ELSE(PTHREADS_ROOT_USER)
90       MESSAGE(STATUS "${PTHREADS_INCLUDE_TO_FIND} not found on system, try to use WITH_PTHREADS option or PTHREADS_ROOT environment variable.")
91     ENDIF(PTHREADS_ROOT_USER)
92   ENDIF(PTHREADS_INCLUDE_DIR)
93 ENDIF(PTHREADS_STATUS)
94
95 # ----
96
97 IF(PTHREADS_STATUS)
98   IF(PTHREADS_ROOT_USER)
99     SET(PTHREADS_LIB_PATHS ${PTHREADS_ROOT_USER}/lib)
100   ELSE(PTHREADS_ROOT_USER)
101     SET(PTHREADS_LIB_PATHS)
102   ENDIF(PTHREADS_ROOT_USER)
103 ENDIF(PTHREADS_STATUS)
104
105 IF(PTHREADS_STATUS)
106   IF(WINDOWS)
107     IF(CMAKE_BUILD_TYPE STREQUAL Release)
108       FIND_LIBRARY(PTHREAD_LIB pthreadVSE2 pthreadVC2 PATHS ${PTHREADS_LIB_PATHS} ${PTHREADS_FIND_PATHS_OPTION})
109     ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
110       FIND_LIBRARY(PTHREAD_LIB pthreadVSE2d pthreadVC2d PATHS ${PTHREADS_LIB_PATHS} ${PTHREADS_FIND_PATHS_OPTION})
111     ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
112   ELSE(WINDOWS)
113     FIND_LIBRARY(PTHREAD_LIB pthread PATHS ${PTHREADS_LIB_PATHS} ${PTHREADS_FIND_PATHS_OPTION})
114   ENDIF(WINDOWS)
115   SET(PTHREAD_LIBS)
116   IF(PTHREAD_LIB)
117     SET(PTHREAD_LIBS ${PTHREAD_LIBS} ${PTHREAD_LIB})
118     MESSAGE(STATUS "pthread lib found: ${PTHREAD_LIB}")
119   ELSE(PTHREAD_LIB)
120     SET(PTHREADS_STATUS 0)
121     IF(PTHREADS_ROOT_USER)
122       MESSAGE(STATUS "pthread lib not found in ${PTHREADS_LIB_PATHS}, check your PTHREADS installation.")
123     ELSE(PTHREADS_ROOT_USER)
124       MESSAGE(STATUS "pthread lib not found on system, try to use WITH_PTHREADS option or PTHREADS_ROOT environment variable.")
125     ENDIF(PTHREADS_ROOT_USER)
126   ENDIF(PTHREAD_LIB)
127 ENDIF(PTHREADS_STATUS)
128
129 # ----
130
131 IF(PTHREADS_STATUS)
132 ELSE(PTHREADS_STATUS)
133   IF(PTHREADS_IS_MANDATORY)
134     MESSAGE(FATAL_ERROR "pthreads not found ... mandatory ... abort")
135   ELSE(PTHREADS_IS_MANDATORY)
136     MESSAGE(STATUS "pthreads not found ... optional ... disabled")
137   ENDIF(PTHREADS_IS_MANDATORY)
138 ENDIF(PTHREADS_STATUS)