File: CMakeLists.txt

package info (click to toggle)
openturns 1.3-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 33,916 kB
  • ctags: 22,419
  • sloc: cpp: 127,986; python: 20,274; ansic: 4,188; fortran: 2,421; sh: 1,103; xml: 839; makefile: 344; yacc: 123; lex: 44
file content (493 lines) | stat: -rw-r--r-- 18,976 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
#                                               -*- cmake -*-

cmake_minimum_required ( VERSION 2.8 )

option ( USE_BISON                    "Looks for Bison if true and then build parser"                         ON )
option ( USE_FLEX                     "Looks for Flex if true and then build lexer"                           ON )
option ( USE_TBB                      "Use Intel Threading Building Blocks library for multithreading"        ON )
option ( USE_SYSTEM_LAPACK            "Use system LAPACK libraries"                                           ON )
option ( USE_MUPARSER                 "Use muParser libraries"                                                ON )
option ( USE_MUPARSER2                "Use muParser2 features"                                                OFF )
option ( USE_LIBXML2                  "Use LibXml2 for XML support"                                           ON )
option ( USE_R                        "Use R for graph output support"                                        ON )
option ( USE_OPENMP                   "Use OpenMP for multithreading"                                         OFF )
option ( USE_BOOST                    "Use Boost for distribution computation"                                ON )
option ( SYSTEM_INSTALL               "True if Open TURNS is installed in a system directory. RPATH removed." OFF )
option ( BUILD_LIB                    "Build the library"                                                     ON )
option ( BUILD_PYTHON                 "Build the python module for the library"                               ON )
option ( BUILD_VALIDATION             "Build the validation files of the library"                             ON )
option ( LINK_PYTHON_LIBRARY          "Link python modules against python library"                            ON )
option ( INSTALL_TESTS                "Install compiled tests for native platform testing"                    OFF )
option ( BUILD_SHARED_LIBS            "build shared libraries"                                                ON )

# By default, build in Release mode. Must appear before project() command
if ( NOT DEFINED CMAKE_BUILD_TYPE )
  set( CMAKE_BUILD_TYPE Release CACHE STRING "Build type" )
endif ()

project ( OpenTURNS CXX )

# Defines our own module path
list ( APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake )


set ( OPENTURNS_HOME_ENV_VAR OPENTURNS_HOME     )

if ( NOT DEFINED CMAKE_INSTALL_LIBDIR )
  set ( CMAKE_INSTALL_LIBDIR lib${LIB_SUFFIX} )
endif ()

set ( OPENTURNS_LIBRARY_PATH
      ${CMAKE_INSTALL_LIBDIR}
      CACHE PATH "The directory where the library is installed"
    )
set ( OPENTURNS_INCLUDE_PATH
      include/openturns
      CACHE PATH "The directory where the header files are installed"
    )
set ( OPENTURNS_CONFIG_CMAKE_PATH
      ${CMAKE_INSTALL_LIBDIR}/cmake/openturns
      CACHE PATH "The directory where the CMake files are installed"
    )
set ( OPENTURNS_SYSCONFIG_PATH
      etc
      CACHE PATH "The directory where the configuration file is installed"
    )
set ( OPENTURNS_DATA_PATH
      share
      CACHE PATH "The directory where the common files are installed"
    )
set ( OPENTURNS_WRAPPER_PATH
      ${CMAKE_INSTALL_LIBDIR}/openturns/wrappers
      CACHE PATH "The directory where the wrapper files are installed"
    )
set ( OPENTURNS_EXAMPLE_PATH
      share/openturns/examples
      CACHE PATH "The directory where the example files are installed"
    )
set ( OPENTURNS_SAMPLE_PATH
      share/openturns/examples
      CACHE PATH "The directory where the sample files are installed"
    )
set ( OPENTURNS_VALIDATION_PATH
      share/openturns/validation
      CACHE PATH "The directory where validation files are installed"
    )
set ( OPENTURNS_DOC_PATH
      share/openturns/doc
      CACHE PATH "The directory where the license files are installed"
    )

if ( MINGW )
  set ( DEFAULT_TMP TEMP )
else ( MINGW )
  set( DEFAULT_TMP /tmp )
endif( MINGW ) 

set ( OPENTURNS_TEMPDIR
      ${DEFAULT_TMP}
      CACHE PATH "The directory for temporary files. /tmp by default."
    )
set ( TEMPDIR ${OPENTURNS_TEMPDIR} )

# WARNING: This is where variables without OPENTURNS_ prefix are defined !
foreach ( _var INSTALL_PATH LIBRARY_PATH INCLUDE_PATH CONFIG_CMAKE_PATH SYSCONFIG_PATH DATA_PATH WRAPPER_PATH EXAMPLE_PATH SAMPLE_PATH VALIDATION_PATH DOC_PATH )
  if ( IS_ABSOLUTE ${OPENTURNS_${_var}} )
    set(${_var} ${OPENTURNS_${_var}})
  else ( IS_ABSOLUTE ${OPENTURNS_${_var}} )
    set(${_var} ${CMAKE_INSTALL_PREFIX}/${OPENTURNS_${_var}})
  endif ( IS_ABSOLUTE ${OPENTURNS_${_var}} )
endforeach ( _var )


if ( BUILD_LIB )

enable_language ( C Fortran )

if ( USE_BISON )
  find_package ( BISON 2.4 )
  if ( BISON_FOUND )
    set ( HAVE_BISON TRUE )
  endif ()
endif ()

if ( USE_FLEX )
  find_package ( FLEX )
  if ( FLEX_FOUND )
    set ( HAVE_FLEX TRUE )
  endif ()
endif ()

find_program ( BC_EXECUTABLE NAMES bc )

if ( USE_TBB )
  find_package ( TBB )
endif ()

if ( USE_SYSTEM_LAPACK )
  find_package ( LAPACK REQUIRED )
endif ()
if ( NOT LAPACK_FOUND )
  include ( ExternalProject )
  set ( LAPACK_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/lapack-prefix )
  ExternalProject_Add ( lapack
    URL http://www.netlib.org/lapack/lapack-3.5.0.tgz
    URL_MD5 b1d3e3e425b2e44a06760ff173104bdf
    CMAKE_ARGS
      -DCMAKE_INSTALL_PREFIX=${LAPACK_PREFIX}
      -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
      -DBUILD_TESTING=OFF
      "-DCMAKE_Fortran_FLAGS=-g -O2 -fPIC"
  )
  list ( APPEND OPENTURNS_PRIVATE_LIBRARIES ${LAPACK_PREFIX}/lib/libblas.a )
  list ( APPEND OPENTURNS_PRIVATE_LIBRARIES ${LAPACK_PREFIX}/lib/liblapack.a )
endif ()

if ( USE_MUPARSER )
  find_package ( muParser 1.32 )
  if ( MUPARSER_FOUND )
    set ( OPENTURNS_HAVE_MUPARSER TRUE )
    if ( USE_MUPARSER2 AND NOT MUPARSER_VERSION_STRING VERSION_LESS 2 )
      set ( OPENTURNS_HAVE_MUPARSER2 TRUE )
    endif ()
  endif ()
endif ()
  
find_package ( Doxygen )

if ( USE_LIBXML2 )
  find_package ( LibXml2 )
endif ()

find_package ( Threads )
find_package ( Libdl )
find_package ( Regex )

if ( USE_BOOST )
  # doesn't pass all tests with boost <=1.42 (debian6)
  find_package ( Boost 1.46 )
endif ()

if ( USE_R )
  find_package ( R COMPONENTS base rot )
endif ()

if ( USE_OPENMP )
  find_package ( OpenMP )
endif ()
if ( OPENMP_FOUND )
  set ( CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" )
endif ()

include ( TestBigEndian )
test_big_endian ( __BIG_ENDIAN__ ) 

try_compile(OPENTURNS_UNSIGNEDLONG_SAME_AS_UINT64
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UnsignedLong_same_as_uint64_t.cxx )

# Find system prerequisites
include ( CheckIncludeFile )
check_include_file ( arpa/inet.h   OPENTURNS_HAVE_ARPA_INET_H   )
check_include_file ( assert.h      OPENTURNS_HAVE_ASSERT_H      )
check_include_file ( dirent.h      OPENTURNS_HAVE_DIRENT_H      )
check_include_file ( errno.h       OPENTURNS_HAVE_ERRNO_H       )
check_include_file ( inttypes.h    OPENTURNS_HAVE_INTTYPES_H    )
check_include_file ( malloc.h      OPENTURNS_HAVE_MALLOC_H      )
check_include_file ( math.h        OPENTURNS_HAVE_MATH_H        )
check_include_file ( netdb.h       OPENTURNS_HAVE_NETDB_H       )
check_include_file ( netinet/in.h  OPENTURNS_HAVE_NETINET_IN_H  )
check_include_file ( netinet/tcp.h OPENTURNS_HAVE_NETINET_TCP_H )
check_include_file ( pthread.h     OPENTURNS_HAVE_PTHREAD_H     )
check_include_file ( regex.h       OPENTURNS_HAVE_REGEX_H       )
check_include_file ( semaphore.h   OPENTURNS_HAVE_SEMAPHORE_H   )
check_include_file ( signal.h      OPENTURNS_HAVE_SIGNAL_H      )
check_include_file ( stdbool.h     OPENTURNS_HAVE_STDBOOL_H     )
check_include_file ( stdint.h      OPENTURNS_HAVE_STDINT_H      )
check_include_file ( stdlib.h      OPENTURNS_HAVE_STDLIB_H      )
check_include_file ( string.h      OPENTURNS_HAVE_STRING_H      )
check_include_file ( strings.h     OPENTURNS_HAVE_STRINGS_H     )
check_include_file ( sys/socket.h  OPENTURNS_HAVE_SYS_SOCKET_H  )
check_include_file ( sys/stat.h    OPENTURNS_HAVE_SYS_STAT_H    )
check_include_file ( sys/time.h    OPENTURNS_HAVE_SYS_TIME_H    )
check_include_file ( sys/types.h   OPENTURNS_HAVE_SYS_TYPES_H   )
check_include_file ( sys/un.h      OPENTURNS_HAVE_SYS_UN_H      )
check_include_file ( unistd.h      OPENTURNS_HAVE_UNISTD_H      )

else ()
  find_package ( OpenTURNS NO_MODULE REQUIRED )
endif ()

# Some useful macros to ease CMakeLists.txt file writing
set ( SOURCEFILES "" CACHE INTERNAL "List of source files to compile" )
macro ( ot_add_source_file FILENAME )
  set ( sf ${SOURCEFILES} ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} )
  set ( SOURCEFILES ${sf} CACHE INTERNAL "List of source files to compile" )
endmacro ( ot_add_source_file )

set ( BUILT_SOURCEFILES "" CACHE INTERNAL "List of source files to compile" )
macro ( ot_add_built_source_file FILENAME )
  set ( sf ${BUILT_SOURCEFILES} ${FILENAME} )
  set ( BUILT_SOURCEFILES ${sf} CACHE INTERNAL "List of built source files to compile" )
endmacro ( ot_add_built_source_file )

set ( HEADERFILES "" CACHE INTERNAL "List of header files to install" )
macro ( ot_install_header_file FILENAME )
  set ( hf ${HEADERFILES} ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} )
  set ( HEADERFILES ${hf} CACHE INTERNAL "List of header files to install" )
endmacro ( ot_install_header_file )

set ( SWIGFILES "" CACHE INTERNAL "List of SWIG files to install" )
macro ( ot_install_swig_file FILENAME )
  set ( hf ${SWIGFILES} ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} )
  set ( SWIGFILES ${hf} CACHE INTERNAL "List of SWIG files to install" )
endmacro ( ot_install_swig_file )

set ( INTERNAL_INCLUDE_DIRS "" CACHE INTERNAL "List of directories with header files needed for build" )
macro ( ot_add_current_dir_to_include_dirs )
  set ( inc_dirs ${INTERNAL_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} )
  set ( INTERNAL_INCLUDE_DIRS ${inc_dirs} CACHE INTERNAL "List of directories with header files needed for build" )
endmacro ( ot_add_current_dir_to_include_dirs )
macro ( ot_add_build_dir_to_include_dirs DIR )
  set ( inc_dirs ${INTERNAL_INCLUDE_DIRS} ${DIR} )
  set ( INTERNAL_INCLUDE_DIRS ${inc_dirs} CACHE INTERNAL "List of directories with header files needed for build" )
endmacro ( ot_add_build_dir_to_include_dirs )

if ( MINGW )
  list ( APPEND OPENTURNS_LIBRARIES ws2_32 )
  set ( CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-auto-import ${CMAKE_EXE_LINKER_FLAGS}" )
endif ()

# Add definitions according to the prerequisites found
add_definitions( -DHAVE_CONFIG_H )

# CMake makefiles don't link against stdc++ on OSX
if ( APPLE )
  list ( APPEND OPENTURNS_LIBRARIES stdc++ )
endif ()

if ( LIBXML2_FOUND )
  set ( HAVE_LIBXML2 TRUE )
  set ( OPENTURNS_HAVE_LIBXML2 TRUE )
  list ( APPEND OPENTURNS_DEFINITIONS ${LIBXML2_DEFINITIONS} )
  list ( APPEND OPENTURNS_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} )
  list ( APPEND OPENTURNS_LIBRARIES ${LIBXML2_LIBRARIES} )
endif ()

if ( LAPACK_FOUND )
  list ( APPEND OPENTURNS_LIBRARIES ${LAPACK_LIBRARIES} )
endif ()

if ( MUPARSER_FOUND )
  list ( APPEND OPENTURNS_LIBRARIES ${MUPARSER_LIBRARIES} )
  list ( APPEND OPENTURNS_INCLUDE_DIRS ${MUPARSER_INCLUDE_DIRS} )
endif ()

if ( Threads_FOUND )
  list ( APPEND OPENTURNS_INCLUDE_DIRS ${THREADS_INCLUDE_DIRS} )
  list ( APPEND OPENTURNS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} )
endif ()

if ( TBB_FOUND )
  set ( HAVE_TBB TRUE )
  set ( HAVE_TBB_TBB_H TRUE )
  set ( OPENTURNS_HAVE_TBB TRUE )
  list ( APPEND OPENTURNS_INCLUDE_DIRS ${TBB_INCLUDE_DIRS} )
  list ( APPEND OPENTURNS_LIBRARIES ${TBB_LIBRARIES} )
endif ()

if ( LIBDL_FOUND )
  set ( OPENTURNS_HAVE_LIBDL TRUE )
  list ( APPEND OPENTURNS_INCLUDE_DIRS ${LIBDL_INCLUDE_DIR} )
  list ( APPEND OPENTURNS_LIBRARIES ${LIBDL_LIBRARIES} )
endif ()

if ( REGEX_FOUND )
  set ( HAVE_REGEX TRUE )
  list ( APPEND OPENTURNS_INCLUDE_DIRS ${REGEX_INCLUDE_DIR} )
  list ( APPEND OPENTURNS_LIBRARIES ${REGEX_LIBRARIES} )
endif ()

if ( OPENMP_FOUND ) 
  list ( APPEND OPENTURNS_LIBRARIES ${OpenMP_CXX_FLAGS} )
endif ()

if ( Boost_FOUND )
  set ( HAVE_BOOST TRUE )
  list ( APPEND OPENTURNS_PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} )
endif ()

add_definitions ( ${OPENTURNS_DEFINITIONS} )
if ( OPENTURNS_INCLUDE_DIRS )
  list ( REMOVE_DUPLICATES OPENTURNS_INCLUDE_DIRS )
endif ( OPENTURNS_INCLUDE_DIRS )
include_directories ( ${OPENTURNS_INCLUDE_DIRS} )
include_directories ( ${OPENTURNS_PRIVATE_INCLUDE_DIRS} )

set ( CPACK_PACKAGE_NAME          openturns      )
set ( CPACK_PACKAGE_VERSION_MAJOR 1              )
set ( CPACK_PACKAGE_VERSION_MINOR 3 )
set ( CPACK_PACKAGE_VERSION_PATCH                )
set ( CPACK_SOURCE_GENERATOR      "TGZ;TBZ2"     )
set ( CPACK_BINARY_STGZ           "OFF"          )
set ( CPACK_BINARY_TBZ2           "ON"           )
set ( CPACK_BINARY_TGZ            "ON"           )
set ( CPACK_BINARY_TZ             "OFF"          )
set ( CPACK_SOURCE_IGNORE_FILES "/.svn;/build;.*~;${CPACK_SOURCE_IGNORE_FILES}" )
#set ( CPACK_INSTALL_CMAKE_PROJECTS "lib;OpenTURNSLib;ALL;/" "python;OpenTURNSPython;ALL;/" )


# Set global definitions
# TODO: remove PACKAGE_<XX> from source code. Needed for compatibility with autotools
set ( PACKAGE_NAME           ${CPACK_PACKAGE_NAME} )
set ( PACKAGE_VERSION        ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR} )
if ( CPACK_PACKAGE_VERSION_PATCH )
  set ( PACKAGE_VERSION       ${PACKAGE_VERSION}.${CPACK_PACKAGE_VERSION_PATCH} )
endif ( CPACK_PACKAGE_VERSION_PATCH )
set ( PACKAGE_BUGREPORT      bugs@openturns.org )
set( CPACK_SOURCE_PACKAGE_FILE_NAME ${PACKAGE_NAME}-${PACKAGE_VERSION} )

# uninstall target
configure_file (
  ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
  ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
  IMMEDIATE @ONLY
)

add_custom_target ( uninstall
  COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)

# distcheck target
find_program( TAR_PROGRAM tar ) 
get_filename_component( BUILD_TOOL_NAME ${CMAKE_BUILD_TOOL} NAME )
if ( TAR_PROGRAM AND BUILD_TOOL_NAME MATCHES ".*make" )
  set ( DISTCHECK_BINARY_DIR ${CMAKE_BINARY_DIR}/${CPACK_SOURCE_PACKAGE_FILE_NAME}/_build )
  set ( DISTCHECK_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/${CPACK_SOURCE_PACKAGE_FILE_NAME}/_inst )
  add_custom_target ( distcheck 
    COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} "$(MAKE)" package_source
    COMMAND ${CMAKE_COMMAND} -E remove_directory ${DISTCHECK_BINARY_DIR}
    COMMAND ${CMAKE_COMMAND} -E remove_directory ${DISTCHECK_INSTALL_PREFIX}
    COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} ${TAR_PROGRAM} xvfz ${CMAKE_BINARY_DIR}/${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
    COMMAND ${CMAKE_COMMAND} -E make_directory ${DISTCHECK_BINARY_DIR}
    COMMAND ${CMAKE_COMMAND} -E make_directory ${DISTCHECK_INSTALL_PREFIX}
    COMMAND ${CMAKE_COMMAND} -E chdir ${DISTCHECK_BINARY_DIR} ${CMAKE_COMMAND} .. -DCMAKE_INSTALL_PREFIX=${DISTCHECK_INSTALL_PREFIX}
    COMMAND ${CMAKE_COMMAND} -E chdir ${DISTCHECK_BINARY_DIR} "$(MAKE)"
    COMMAND ${CMAKE_COMMAND} -E chdir ${DISTCHECK_BINARY_DIR} "$(MAKE)" check
    COMMAND ${CMAKE_COMMAND} -E chdir ${DISTCHECK_BINARY_DIR} "$(MAKE)" install
    COMMAND ${CMAKE_COMMAND} -E chdir ${DISTCHECK_BINARY_DIR} "$(MAKE)" cppinstallcheck
    COMMAND ${CMAKE_COMMAND} -E chdir ${DISTCHECK_BINARY_DIR} "$(MAKE)" pyinstallcheck
    COMMAND ${CMAKE_COMMAND} -E chdir ${DISTCHECK_BINARY_DIR} "$(MAKE)" uninstall
    COMMAND ${CMAKE_COMMAND} -E chdir ${DISTCHECK_BINARY_DIR} "$(MAKE)" clean
  )
endif ()

# Selectively add or remove RPATH from executable
if ( NOT SYSTEM_INSTALL )
  set ( CMAKE_INSTALL_RPATH ${LIBRARY_PATH}
                            ${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}
      )
  set ( CMAKE_BUILD_WITH_INSTALL_RPATH    TRUE )
  set ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
endif ()

set ( OPENTURNS_SWIG_INCLUDE_DIRS ${INCLUDE_PATH}/swig )
set ( OPENTURNS_SWIG_DEFINITIONS -DSWIG_TYPE_TABLE=openturns )

# The tests can't be run if this function is absent
enable_testing ()
add_custom_target ( tests COMMENT "Build tests" )
add_custom_target ( check COMMENT "Run pre-installation tests" )
add_custom_target ( installcheck COMMENT "Run post-installation tests" )

# Recurse in subdirectories
add_subdirectory ( wrappers )

if ( BUILD_PYTHON )
  # workaround for cmake bug #0013449
  if ( NOT DEFINED CMAKE_FIND_ROOT_PATH )
    find_package ( SWIG )
  else ()
    find_program ( SWIG_EXECUTABLE NAMES swig2.0 swig )
    if ( SWIG_EXECUTABLE )
      set ( SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake )
      set ( SWIG_FOUND TRUE )
    endif ()
  endif ()
  if ( SWIG_FOUND )
    include ( ${SWIG_USE_FILE} )
    mark_as_advanced ( SWIG_VERSION SWIG_DIR )
  endif ()
  find_package ( PythonInterp )
  find_package ( PythonLibs )
  include ( FindPythonModule )
  find_python_module ( numpy )
  find_python_module ( scipy )
  find_python_module ( matplotlib 1.1 )

  if ( PYTHONINTERP_FOUND )
    execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print( sysconfig.get_python_lib( plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}' ) )"
                      OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
                      RESULT_VARIABLE _PYTHON_pythonlib_result
                      OUTPUT_STRIP_TRAILING_WHITESPACE )
    
    if (NOT _PYTHON_pythonlib_result)
      get_filename_component ( _ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE )
      file ( RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH} )                   
                          
      set ( OPENTURNS_PYTHON_MODULE_PATH
            ${_REL_PYTHON_MODULE_PATH}
            CACHE PATH "The directory where the python modules are installed"
          )

      if ( IS_ABSOLUTE ${OPENTURNS_PYTHON_MODULE_PATH} )
        set( PYTHON_MODULE_PATH ${OPENTURNS_PYTHON_MODULE_PATH} )
      else ()
        set( PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/${OPENTURNS_PYTHON_MODULE_PATH} )
      endif ()
      
    else ()
      message ( SEND_ERROR "Could not run ${PYTHON_EXECUTABLE}" )
    endif ()
  endif ()
endif ()


if ( BUILD_LIB )
  add_subdirectory ( lib )
  if ( NOT LAPACK_FOUND )
    add_dependencies ( OT lapack )
  endif ()
  if ( NOT MUPARSER_FOUND )
    add_dependencies ( OT muparser )
  endif ()
  add_dependencies ( check cppcheck )
  add_dependencies ( installcheck cppinstallcheck )
endif ( BUILD_LIB )

if ( PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND )
  add_subdirectory ( python )
  add_dependencies ( installcheck pyinstallcheck )
endif ()


if ( BUILD_VALIDATION )
  add_subdirectory ( validation )
endif ()


include ( CPack )

install ( FILES COPYING
                COPYING.LESSER
                COPYING.cobyla
                COPYING.dsfmt
                COPYING.ev3
                COPYING.faddeeva
                COPYING.kendall
                COPYING.kissfft
                COPYING.KolmogorovSmirnovDist
                COPYING.poissinv
                COPYING.tnc
          DESTINATION ${OPENTURNS_DOC_PATH}
        )