1 # - Try to find OpenTURNS
2 # Once done this will define
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
15 # Copyright (c) 2009 Mathieu Lapointe <lapointe@phimeca.com>
16 # Copyright (c) 2010 Julien Schueller <schueller@phimeca.com>
18 # Redistribution and use is allowed according to the terms of the New
20 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
23 include (CheckFunctionExists)
24 include (CheckIncludeFile)
25 include (CheckIncludeFileCXX)
26 include (FindPackageHandleStandardArgs)
29 find_package(LibXml2 2.6.27)
30 find_package(PythonLibs ${PYTHON_VERSION})
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
37 AND OpenTURNS_LIBRARIES
38 AND OpenTURNS_WRAPPER_DIR
39 AND OpenTURNS_PYTHON_MODULE_DIR
40 AND OpenTURNS_MODULE_DIR))
43 if (NOT OpenTURNS_INCLUDE_DIR)
44 find_path (OpenTURNS_INCLUDE_DIR
55 "OpenTURNS include directory"
59 # set swig include dir
60 if (NOT OpenTURNS_SWIG_INCLUDE_DIR)
61 set(OpenTURNS_SWIG_INCLUDE_DIR "${OpenTURNS_INCLUDE_DIR}/swig")
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})
71 # check for library directory
72 if (NOT OpenTURNS_LIBRARY)
73 find_library (OpenTURNS_LIBRARY
84 "OpenTURNS library location"
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})
95 # retrieve path to lib
96 get_filename_component (OpenTURNS_LIBRARY_PATH ${OpenTURNS_LIBRARY} PATH)
98 # retrieve install path
99 set (OpenTURNS_INSTALL_PATH "${OpenTURNS_LIBRARY_PATH}/../..")
102 if (NOT OpenTURNS_WRAPPER_DIR)
103 find_path (OpenTURNS_WRAPPER_DIR
105 wrapper.xml wrapper.dtd
108 ${OpenTURNS_INSTALL_PATH}
113 share/openturns/wrappers
115 "OpenTURNS wrappers location"
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)
124 list (APPEND OpenTURNS_WRAPPER_DEFINITIONS -DHAVE_PTHREAD_H)
128 # find python module dir
129 if (NOT OpenTURNS_PYTHON_MODULE_DIR)
130 find_path (OpenTURNS_PYTHON_MODULE_DIR
135 ${OpenTURNS_INSTALL_PATH}
140 lib/python${PYTHON_VERSION}/site-packages
142 "OpenTURNS python module location"
147 # find module directory
148 if (NOT OpenTURNS_MODULE_DIR)
149 set (OpenTURNS_MODULE_DIR
150 ${OpenTURNS_LIBRARY_PATH}/module
154 # set module definitions
155 if (NOT OpenTURNS_MODULE_DEFINITIONS)
156 set (OpenTURNS_MODULE_DEFINITIONS)
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)
169 list (APPEND OpenTURNS_MODULE_DEFINITIONS -DSTDC_HEADERS_H=0)
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})
179 check_include_file(${header_file} ${macro_name})
182 list (APPEND OpenTURNS_MODULE_DEFINITIONS -D${macro_name}=1)
184 list (APPEND OpenTURNS_MODULE_DEFINITIONS -D${macro_name}=0)
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)
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
210 OpenTURNS_INCLUDE_DIR
211 OpenTURNS_SWIG_INCLUDE_DIR
212 OpenTURNS_INCLUDE_DIRS
214 OpenTURNS_WRAPPER_DIR
215 OpenTURNS_PYTHON_MODULE_DIR
221 OpenTURNS_INCLUDE_DIR
222 OpenTURNS_SWIG_INCLUDE_DIR
223 OpenTURNS_INCLUDE_DIRS
225 OpenTURNS_WRAPPER_DIR
226 OpenTURNS_WRAPPER_DEFINITIONS
228 OpenTURNS_PYTHON_MODULE_DIR
229 OpenTURNS_MODULE_DEFINITIONS