Salome HOME
New version of cmake tools completely re-written
[modules/kernel.git] / salome_adm / cmake_files / FindPTHREADS.cmake
1 #  Copyright (C) 2007-2008  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 MESSAGE(STATUS "Check for pthreads ...")
25
26 # ------
27
28 IF(PTHREADS_IS_MANDATORY STREQUAL 0)
29   SET(PTHREADS_IS_MANDATORY 0)
30   SET(PTHREADS_IS_OPTIONAL 1)
31 ENDIF(PTHREADS_IS_MANDATORY STREQUAL 0)
32 IF(PTHREADS_IS_OPTIONAL STREQUAL 0)
33   SET(PTHREADS_IS_MANDATORY 1)
34   SET(PTHREADS_IS_OPTIONAL 0)
35 ENDIF(PTHREADS_IS_OPTIONAL STREQUAL 0)
36 IF(NOT PTHREADS_IS_MANDATORY AND NOT PTHREADS_IS_OPTIONAL)
37   SET(PTHREADS_IS_MANDATORY 1)
38   SET(PTHREADS_IS_OPTIONAL 0)
39 ENDIF(NOT PTHREADS_IS_MANDATORY AND NOT PTHREADS_IS_OPTIONAL)
40
41 # ------
42
43 SET(PTHREADS_STATUS 1)
44 IF(WITHOUT_PTHREADS OR WITH_PTHREADS STREQUAL 0)
45   SET(PTHREADS_STATUS 0)
46   MESSAGE(STATUS "pthreads disabled from command line.")
47 ENDIF(WITHOUT_PTHREADS OR WITH_PTHREADS STREQUAL 0)
48
49 # ------
50
51 IF(PTHREADS_STATUS)
52   IF(WITH_PTHREADS)
53     SET(PTHREADS_ROOT_USER ${WITH_PTHREADS})
54   ELSE(WITH_PTHREADS)
55     SET(PTHREADS_ROOT_USER $ENV{PTHREADS_ROOT})
56   ENDIF(WITH_PTHREADS)
57 ENDIF(PTHREADS_STATUS)
58
59 # -----
60
61 IF(PTHREADS_STATUS)
62   IF(PTHREADS_ROOT_USER)
63     SET(PTHREADS_FIND_PATHS_OPTION NO_DEFAULT_PATH)
64   ELSE(PTHREADS_ROOT_USER)
65     SET(PTHREADS_FIND_PATHS_OPTION)
66   ENDIF(PTHREADS_ROOT_USER)
67 ENDIF(PTHREADS_STATUS)
68
69 # -----
70
71 IF(PTHREADS_STATUS)
72   IF(PTHREADS_ROOT_USER)
73     SET(PTHREADS_INCLUDE_PATHS ${PTHREADS_ROOT_USER}/include)
74   ELSE(PTHREADS_ROOT_USER)
75     SET(PTHREADS_INCLUDE_PATHS)
76   ENDIF(PTHREADS_ROOT_USER)
77   SET(PTHREADS_INCLUDE_TO_FIND pthread.h)
78   FIND_PATH(PTHREADS_INCLUDE_DIR ${PTHREADS_INCLUDE_TO_FIND} PATHS ${PTHREADS_INCLUDE_PATHS} ${PTHREADS_FIND_PATHS_OPTION})
79   IF(PTHREADS_INCLUDE_DIR)
80     IF(PTHREADS_ROOT_USER)
81       SET(PTHREAD_CFLAGS -I${PTHREADS_INCLUDE_DIR})
82     ENDIF(PTHREADS_ROOT_USER)
83     MESSAGE(STATUS "${PTHREADS_INCLUDE_TO_FIND} found in ${PTHREADS_INCLUDE_DIR}")
84   ELSE(PTHREADS_INCLUDE_DIR)
85     SET(PTHREADS_STATUS 0)
86     IF(PTHREADS_ROOT_USER)
87       MESSAGE(STATUS "${PTHREADS_INCLUDE_TO_FIND} not found in ${PTHREADS_INCLUDE_PATHS}, check your PTHREADS installation.")
88     ELSE(PTHREADS_ROOT_USER)
89       MESSAGE(STATUS "${PTHREADS_INCLUDE_TO_FIND} not found on system, try to use WITH_PTHREADS option or PTHREADS_ROOT environment variable.")
90     ENDIF(PTHREADS_ROOT_USER)
91   ENDIF(PTHREADS_INCLUDE_DIR)
92 ENDIF(PTHREADS_STATUS)
93
94 # ----
95
96 IF(PTHREADS_STATUS)
97   IF(PTHREADS_ROOT_USER)
98     SET(PTHREADS_LIB_PATHS ${PTHREADS_ROOT_USER}/lib)
99   ELSE(PTHREADS_ROOT_USER)
100     SET(PTHREADS_LIB_PATHS)
101   ENDIF(PTHREADS_ROOT_USER)
102 ENDIF(PTHREADS_STATUS)
103
104 IF(PTHREADS_STATUS)
105   IF(WINDOWS)
106     IF(CMAKE_BUILD_TYPE STREQUAL Release)
107       FIND_LIBRARY(PTHREAD_LIB pthreadVSE2 PATHS ${PTHREADS_LIB_PATHS} ${PTHREADS_FIND_PATHS_OPTION})
108     ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
109       FIND_LIBRARY(PTHREAD_LIB pthreadVSE2d PATHS ${PTHREADS_LIB_PATHS} ${PTHREADS_FIND_PATHS_OPTION})
110     ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
111   ELSE(WINDOWS)
112     FIND_LIBRARY(PTHREAD_LIB pthread PATHS ${PTHREADS_LIB_PATHS} ${PTHREADS_FIND_PATHS_OPTION})
113   ENDIF(WINDOWS)
114   SET(PTHREAD_LIBS)
115   IF(PTHREAD_LIB)
116     SET(PTHREAD_LIBS ${PTHREAD_LIBS} ${PTHREAD_LIB})
117     MESSAGE(STATUS "pthread lib found: ${PTHREAD_LIB}")
118   ELSE(PTHREAD_LIB)
119     SET(PTHREADS_STATUS 0)
120     IF(PTHREADS_ROOT_USER)
121       MESSAGE(STATUS "pthread lib not found in ${PTHREADS_LIB_PATHS}, check your PTHREADS installation.")
122     ELSE(PTHREADS_ROOT_USER)
123       MESSAGE(STATUS "pthread lib not found on system, try to use WITH_PTHREADS option or PTHREADS_ROOT environment variable.")
124     ENDIF(PTHREADS_ROOT_USER)
125   ENDIF(PTHREAD_LIB)
126 ENDIF(PTHREADS_STATUS)
127
128 # ----
129
130 IF(PTHREADS_STATUS)
131 ELSE(PTHREADS_STATUS)
132   IF(PTHREADS_IS_MANDATORY)
133     MESSAGE(FATAL_ERROR "pthreads not found ... mandatory ... abort")
134   ELSE(PTHREADS_IS_MANDATORY)
135     MESSAGE(STATUS "pthreads not found ... optional ... disabled")
136   ENDIF(PTHREADS_IS_MANDATORY)
137 ENDIF(PTHREADS_STATUS)