Salome HOME
mise a jour de la liste des .ui
[tools/eficas.git] / CMakeModules / FindOpenTURNS.cmake
1 # - Try to find OpenTURNS
2 # Once done this will define
3 #
4 #  OpenTURNS_FOUND - system has OT
5 #  OpenTURNS_INCLUDE_DIR - the OT include directory
6 #  OpenTURNS_INCLUDE_DIRS - the OT include directory and dependencies include directories
7 #  OpenTURNS_LIBRARY - Where to find the OT library
8 #  OpenTURNS_LIBRARIES - Link these to use OT
9 #  OpenTURNS_WRAPPER_DIR - Wrappers directory
10 #  OpenTURNS_WRAPPER_DEFINITIONS - Compiler switches required for using OT wrapper
11 #  OpenTURNS_MODULE_DIR - OT module directory
12 #  OpenTURNS_MODULE_DEFINITIONS - Compiler switches required for using OT module
13 #  OpenTURNS_SWIG_INCLUDE_DIR - the OT include directory to swig interface
14 #
15 #  Copyright (c) 2009 Mathieu Lapointe <lapointe@phimeca.com>
16 #  Copyright (c) 2010 Julien Schueller <schueller@phimeca.com>
17 #
18 #  Redistribution and use is allowed according to the terms of the New
19 #  BSD license.
20 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
21 #
22
23 include (CheckFunctionExists)
24 include (CheckIncludeFile)
25 include (CheckIncludeFileCXX)
26 include (FindPackageHandleStandardArgs)
27
28 # check dependencies
29 find_package(LibXml2 2.6.27)
30 find_package(PythonLibs ${PYTHON_VERSION})
31
32 # test if variables are not already in cache
33 if (NOT (OpenTURNS_INCLUDE_DIR
34           AND OpenTURNS_SWIG_INCLUDE_DIR
35           AND OpenTURNS_INCLUDE_DIRS
36           AND OpenTURNS_LIBRARY
37           AND OpenTURNS_LIBRARIES
38           AND OpenTURNS_WRAPPER_DIR
39           AND OpenTURNS_PYTHON_MODULE_DIR
40           AND OpenTURNS_MODULE_DIR))
41
42   # set include dir
43   if (NOT OpenTURNS_INCLUDE_DIR)
44     find_path (OpenTURNS_INCLUDE_DIR
45       NAMES
46         OT.hxx
47       HINTS
48         ${OPENTURNS_DIR}
49         /usr
50         /usr/local
51         /opt
52       PATH_SUFFIXES
53         include/openturns
54       DOC
55         "OpenTURNS include directory"
56     )
57   endif ()
58
59   # set swig include dir
60   if (NOT OpenTURNS_SWIG_INCLUDE_DIR)
61     set(OpenTURNS_SWIG_INCLUDE_DIR "${OpenTURNS_INCLUDE_DIR}/swig")
62   endif ()
63
64   # dependencies includes
65   if (NOT OpenTURNS_INCLUDE_DIRS)
66     set (OpenTURNS_INCLUDE_DIRS ${OpenTURNS_INCLUDE_DIR})
67     list (APPEND OpenTURNS_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR})
68     list (APPEND OpenTURNS_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
69   endif ()
70
71   # check for library directory
72   if (NOT OpenTURNS_LIBRARY)
73     find_library (OpenTURNS_LIBRARY
74       NAMES
75         OT
76       HINTS
77         ${OPENTURNS_DIR}
78         /usr
79         /usr/local
80         /opt
81       PATH_SUFFIXES
82         lib/openturns
83       DOC
84         "OpenTURNS library location"
85     )
86   endif ()
87
88   # find dependent libraries
89   if (NOT OpenTURNS_LIBRARIES)
90     set (OpenTURNS_LIBRARIES ${OpenTURNS_LIBRARY} ${LIBXML2_LIBRARIES} ${PYTHON_LIBRARIES})
91     list (APPEND OpenTURNS_LIBRARIES ${LIBXML2_LIBRARIES})
92     list (APPEND OpenTURNS_LIBRARIES ${PYTHON_LIBRARIES})
93   endif ()
94
95   # retrieve path to lib
96   get_filename_component (OpenTURNS_LIBRARY_PATH ${OpenTURNS_LIBRARY} PATH)
97
98   # retrieve install path
99   set (OpenTURNS_INSTALL_PATH "${OpenTURNS_LIBRARY_PATH}/../..")
100
101   # find wrappers dir
102   if (NOT OpenTURNS_WRAPPER_DIR)
103     find_path (OpenTURNS_WRAPPER_DIR
104       NAMES
105         wrapper.xml wrapper.dtd
106       HINTS
107         ${OPENTURNS_DIR}
108         ${OpenTURNS_INSTALL_PATH}
109         /usr
110         /usr/local
111         /opt
112       PATH_SUFFIXES
113         share/openturns/wrappers
114       DOC
115         "OpenTURNS wrappers location"
116     )
117   endif ()
118
119   # set wrapper definitions
120   if (NOT OpenTURNS_WRAPPER_DEFINITIONS)
121     set(OpenTURNS_WRAPPER_DEFINITIONS)
122     check_include_file_cxx (pthread.h HAVE_PTHREAD_H)
123     if (HAVE_PTHREAD_H)
124       list (APPEND OpenTURNS_WRAPPER_DEFINITIONS -DHAVE_PTHREAD_H)
125     endif ()
126   endif ()
127
128   # find python module dir
129   if (NOT OpenTURNS_PYTHON_MODULE_DIR)
130     find_path (OpenTURNS_PYTHON_MODULE_DIR
131       NAMES
132         openturns.pth
133       HINTS
134         ${OPENTURNS_DIR}
135         ${OpenTURNS_INSTALL_PATH}
136         /usr
137         /usr/local
138         /opt
139       PATH_SUFFIXES
140         lib/python${PYTHON_VERSION}/site-packages
141       DOC
142         "OpenTURNS python module location"
143     )
144   endif ()
145
146
147   # find module directory
148   if (NOT OpenTURNS_MODULE_DIR)
149     set (OpenTURNS_MODULE_DIR
150       ${OpenTURNS_LIBRARY_PATH}/module
151     )
152   endif ()
153
154   # set module definitions
155   if (NOT OpenTURNS_MODULE_DEFINITIONS)
156     set (OpenTURNS_MODULE_DEFINITIONS)
157
158     # check for STDC_HEADERS
159     check_include_file (stdlib.h HAVE_STDLIB_H)
160     check_include_file (stdarg.h HAVE_STDARG_H)
161     check_include_file (string.h HAVE_STRING_H)
162     check_include_file (float.h HAVE_FLOAT_H)
163     check_function_exists (memchr HAVE_MEMCHR)
164     check_function_exists (free HAVE_FREE)
165     check_include_file (ctype.h HAVE_CTYPE_H)
166     if(HAVE_STDLIB_H AND HAVE_STDARG_H AND HAVE_STRING_H AND HAVE_FLOAT_H AND HAVE_MEMCHR AND HAVE_FREE AND HAVE_CTYPE_H)
167       list (APPEND OpenTURNS_MODULE_DEFINITIONS -DSTDC_HEADERS_H=1)
168     else ()
169       list (APPEND OpenTURNS_MODULE_DEFINITIONS -DSTDC_HEADERS_H=0)
170     endif ()
171
172     # this macro checks a header and defines the corresponding macro
173     macro(check_include_files_define_macro header_file)
174       # get macro name from header_file
175       string(TOUPPER ${header_file} macro_name)
176       string(REGEX REPLACE "[/.]" "_" macro_name ${macro_name})
177       set(macro_name HAVE_${macro_name})
178       # check for header
179       check_include_file(${header_file} ${macro_name})
180       # define macro
181       if(${macro_name})
182         list (APPEND OpenTURNS_MODULE_DEFINITIONS -D${macro_name}=1)
183       else()
184         list (APPEND OpenTURNS_MODULE_DEFINITIONS -D${macro_name}=0)
185       endif()
186     endmacro()
187
188     # check for some headers
189     check_include_files_define_macro(sys/types.h)
190     check_include_files_define_macro(sys/stat.h)
191     check_include_files_define_macro(stdlib.h)
192     check_include_files_define_macro(string.h)
193     check_include_files_define_macro(memory.h)
194     check_include_files_define_macro(strings.h)
195     check_include_files_define_macro(inttypes.h)
196     check_include_files_define_macro(stdint.h)
197     check_include_files_define_macro(unistd.h)
198     check_include_files_define_macro(dlfcn.h)
199     check_include_files_define_macro(stdbool.h)
200     check_include_files_define_macro(regex.h)
201
202   endif ()
203
204 endif ()
205
206 # handle the QUIETLY and REQUIRED arguments and set OpenTURNS_FOUND to TRUE if
207 # all listed variables are TRUE
208 find_package_handle_standard_args (OpenTURNS DEFAULT_MSG
209   OpenTURNS_LIBRARY
210   OpenTURNS_INCLUDE_DIR
211   OpenTURNS_SWIG_INCLUDE_DIR
212   OpenTURNS_INCLUDE_DIRS
213   OpenTURNS_LIBRARIES
214   OpenTURNS_WRAPPER_DIR
215   OpenTURNS_PYTHON_MODULE_DIR
216   OpenTURNS_MODULE_DIR
217 )
218
219 mark_as_advanced (
220   OpenTURNS_LIBRARY
221   OpenTURNS_INCLUDE_DIR
222   OpenTURNS_SWIG_INCLUDE_DIR
223   OpenTURNS_INCLUDE_DIRS
224   OpenTURNS_LIBRARIES
225   OpenTURNS_WRAPPER_DIR
226   OpenTURNS_WRAPPER_DEFINITIONS
227   OpenTURNS_MODULE_DIR
228   OpenTURNS_PYTHON_MODULE_DIR
229   OpenTURNS_MODULE_DEFINITIONS
230 )
231
232
233 ### Local Variables:
234 ### mode: cmake
235 ### End: