CMakeUserFindOpenTURNS: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
No edit summary
Line 3: Line 3:
[[File:FindOpenTURNS.cmake]]
[[File:FindOpenTURNS.cmake]]
-----
-----
    #  -- Try to find OpenTURNS
#  -- Try to find OpenTURNS
    #
  #
    #  OpenTURNS is an Open source initiative to Treat Uncertainties,
  #  OpenTURNS is an Open source initiative to Treat Uncertainties,
    #  Risks’N Statistics in a structured industrial approach,
  #  Risks’N Statistics in a structured industrial approach,
    #  available at http://www.openturns.org/
  #  available at http://www.openturns.org/
    #
  #
    #  ---------------------------------------------------------------------
  #  ---------------------------------------------------------------------
    #
  #
    #  -- Library usage example :
  #  -- Library usage example :
    #
  #
    #  find_package (OpenTURNS 0.13.1)
  #  find_package (OpenTURNS 0.13.1)
    #  if (OPENTURNS_FOUND)
  #  if (OPENTURNS_FOUND)
    #    include_directories (${OPENTURNS_INCLUDE_DIRS})
  #    include_directories (${OPENTURNS_INCLUDE_DIRS})
    #    add_executable (foo foo.cpp)
  #    add_executable (foo foo.cpp)
    #    target_link_libraries (foo ${OPENTURNS_LIBRARIES})
  #    target_link_libraries (foo ${OPENTURNS_LIBRARIES})
    #  endif ()
  #  endif ()
    #
  #
    #  -- Module usage example :
  #  -- Module usage example :
    #
  #
    #  find_package (OpenTURNS 0.13 COMPONENTS Trapezoidal)
  #  find_package (OpenTURNS 0.13 COMPONENTS Trapezoidal)
    #  if (OPENTURNS_TRAPEZOIDAL_FOUND)
  #  if (OPENTURNS_TRAPEZOIDAL_FOUND)
    #    include_directories (${OPENTURNS_TRAPEZOIDAL_INCLUDE_DIRS})
  #    include_directories (${OPENTURNS_TRAPEZOIDAL_INCLUDE_DIRS})
    #    add_executable (foo foo.cpp)
  #    add_executable (foo foo.cpp)
    #    target_link_libraries (foo ${OPENTURNS_TRAPEZOIDAL_LIBRARIES})
  #    target_link_libraries (foo ${OPENTURNS_TRAPEZOIDAL_LIBRARIES})
    #  endif ()
  #  endif ()
    #
  #
    #  -- Show some debug information :
  #  -- Show some debug information :
    #
  #
    #  set (OPENTURNS_DEBUG TRUE)
  #  set (OPENTURNS_DEBUG TRUE)
    #  find_package (OpenTURNS)
  #  find_package (OpenTURNS)
    #
  #
    #  ---------------------------------------------------------------------
  #  ---------------------------------------------------------------------
    #
  #
    #  -- This module defines :
  #  -- This module defines :
    #
  #
    #  OPENTURNS_FOUND - OpenTURNS is usable as a library
  #  OPENTURNS_FOUND - OpenTURNS is usable as a library
    #  OPENTURNS_INCLUDE_DIR - Where to find OT.hxx (not for general use)
  #  OPENTURNS_INCLUDE_DIR - Where to find OT.hxx (not for general use)
    #  OPENTURNS_INCLUDE_DIRS - dependencies include directories
  #  OPENTURNS_INCLUDE_DIRS - dependencies include directories
    #  OPENTURNS_SWIG_INCLUDE_DIR - Include directory to swig (.i) interface
  #  OPENTURNS_SWIG_INCLUDE_DIR - Include directory to swig (.i) interface
    #  OPENTURNS_VERSION - Version string
  #  OPENTURNS_VERSION - Version string
    #  OPENTURNS_LIBRARY - Path to libOT.so (not for general use)
  #  OPENTURNS_LIBRARY - Path to libOT.so (not for general use)
    #  OPENTURNS_LIBRARIES - Link these to use the library
  #  OPENTURNS_LIBRARIES - Link these to use the library
    #  OPENTURNS_ROOT_DIR - Installation directory
  #  OPENTURNS_ROOT_DIR - Installation directory
    #  OPENTURNS_EXAMPLES_DIR - path to examples programs
  #  OPENTURNS_EXAMPLES_DIR - path to examples programs
    #
  #
    #  OPENTURNS_WRAPPER_FOUND - OpenTURNS wrapper library is usable
  #  OPENTURNS_WRAPPER_FOUND - OpenTURNS wrapper library is usable
    #  OPENTURNS_WRAPPER_DIR - Wrapper directory
  #  OPENTURNS_WRAPPER_DIR - Wrapper directory
    #  OPENTURNS_WRAPPER_LIBRARIES - Link these to use the wrapper
  #  OPENTURNS_WRAPPER_LIBRARIES - Link these to use the wrapper
    #  OPENTURNS_WRAPPER_DEFINITIONS - Compiler switches required for wrapper
  #  OPENTURNS_WRAPPER_DEFINITIONS - Compiler switches required for wrapper
    #
  #
    #  OPENTURNS_MODULE_DIR - OpenTURNS module directory
  #  OPENTURNS_MODULE_DIR - OpenTURNS module directory
    #  OPENTURNS_MODULE_DEFINITIONS - Compiler switches required for module
  #  OPENTURNS_MODULE_DEFINITIONS - Compiler switches required for module
    #  OPENTURNS_NAME_FOUND - True if module NAME was found
  #  OPENTURNS_NAME_FOUND - True if module NAME was found
    #  OPENTURNS_NAME_INCLUDE_DIR - Module NAME headers
  #  OPENTURNS_NAME_INCLUDE_DIR - Module NAME headers
    #  OPENTURNS_NAME_INCLUDE_DIRS - Module NAME includes
  #  OPENTURNS_NAME_INCLUDE_DIRS - Module NAME includes
    #  OPENTURNS_NAME_SWIG_INCLUDE_DIR - Module NAME swig (.i) headers
  #  OPENTURNS_NAME_SWIG_INCLUDE_DIR - Module NAME swig (.i) headers
    #  OPENTURNS_NAME_LIBRARY - Module NAME library location
  #  OPENTURNS_NAME_LIBRARY - Module NAME library location
    #  OPENTURNS_NAME_LIBRARIES - Module NAME libraries location
  #  OPENTURNS_NAME_LIBRARIES - Module NAME libraries location
    #  Macro add_module_extra_definitions(MODULE_NAME VERSION)
  #  Macro add_module_extra_definitions(MODULE_NAME VERSION)
    #  MUST be called when building a module
  #  MUST be called when building a module
    #
  #
    #  ---------------------------------------------------------------------
  #  ---------------------------------------------------------------------
    #
  #
    #  Copyright (c) 2009 Mathieu Lapointe <lapointe@phimeca.com>
  #  Copyright (c) 2009 Mathieu Lapointe <lapointe at phimeca dot com>
    #  Copyright (c) 2010 Julien Schueller <schueller@phimeca.com>
  #  Copyright (c) 2010 Julien Schueller <schueller at phimeca dot com>
    #
  #
    #  Redistribution and use is allowed according to the terms of the New
  #  Redistribution and use is allowed according to the terms of the New
    #  BSD license.
  #  BSD license.
    #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
    #
  #


    include (CheckFunctionExists)
  include (CheckFunctionExists)
    include (CheckIncludeFileCXX)
  include (CheckIncludeFileCXX)




    # check dependencies quietly
  # check dependencies quietly
    if (OpenTURNS_FIND_QUIETLY)
  if (OpenTURNS_FIND_QUIETLY)
      # except when debugging
    # except when debugging
      if (NOT OPENTURNS_DEBUG)
    if (NOT OPENTURNS_DEBUG)
        set (_FIND_ARG QUIET)
      set (_FIND_ARG QUIET)
      endif ()
     endif ()
     endif ()
  endif ()




    # libxml
  # libxml
    if (NOT LIBXML2_FOUND)
  if (NOT LIBXML2_FOUND)
      find_package (LibXml2 2.6.27 ${_FIND_ARG})
    find_package (LibXml2 2.6.27 ${_FIND_ARG})
    endif ()
  endif ()




    # python
  # python
    if (NOT PYTHONLIBS_FOUND)
  if (NOT PYTHONLIBS_FOUND)
      find_package (PythonLibs 2.5 ${_FIND_ARG})
    find_package (PythonLibs 2.5 ${_FIND_ARG})
    endif()
  endif()




    # include dir
  # include dir
    if (NOT OPENTURNS_INCLUDE_DIR)
  if (NOT OPENTURNS_INCLUDE_DIR)
      find_path (OPENTURNS_INCLUDE_DIR
    find_path (OPENTURNS_INCLUDE_DIR
        NAMES
      NAMES
          OT.hxx
        OT.hxx
        PATHS
      PATHS
          ${OPENTURNS_ROOT_DIR}/include
        ${OPENTURNS_ROOT_DIR}/include
          C:/OpenTURNS/include
        C:/OpenTURNS/include
        PATH_SUFFIXES
      PATH_SUFFIXES
          openturns
        openturns
        DOC
      DOC
          "OpenTURNS include directory"
        "OpenTURNS include directory"
      )
    )
    endif ()
  endif ()




    # set swig include dir
  # set swig include dir
    if (NOT OPENTURNS_SWIG_INCLUDE_DIR)
  if (NOT OPENTURNS_SWIG_INCLUDE_DIR)
      set(OPENTURNS_SWIG_INCLUDE_DIR "${OPENTURNS_INCLUDE_DIR}/swig")
    set(OPENTURNS_SWIG_INCLUDE_DIR "${OPENTURNS_INCLUDE_DIR}/swig")
    endif ()
  endif ()




    # dependencies includes
  # dependencies includes
    if (NOT OPENTURNS_INCLUDE_DIRS)
  if (NOT OPENTURNS_INCLUDE_DIRS)
      if (OPENTURNS_INCLUDE_DIR)
    if (OPENTURNS_INCLUDE_DIR)
        set (OPENTURNS_INCLUDE_DIRS ${OPENTURNS_INCLUDE_DIR})
      set (OPENTURNS_INCLUDE_DIRS ${OPENTURNS_INCLUDE_DIR})
      endif ()
      list (APPEND OPENTURNS_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR})
      list (APPEND OPENTURNS_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) # cmake >= 2.8.0
      list (APPEND OPENTURNS_INCLUDE_DIRS ${PYTHON_INCLUDE_PATH}) # cmake <= 2.6.4
     endif ()
     endif ()
    list (APPEND OPENTURNS_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR})
    list (APPEND OPENTURNS_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) # cmake >= 2.8.0
    list (APPEND OPENTURNS_INCLUDE_DIRS ${PYTHON_INCLUDE_PATH}) # cmake <= 2.6.4
  endif ()




    # version
  # version
    if (NOT OPENTURNS_VERSION)
  if (NOT OPENTURNS_VERSION)
      if (OPENTURNS_INCLUDE_DIR)
    if (OPENTURNS_INCLUDE_DIR)
        file (STRINGS "${OPENTURNS_INCLUDE_DIR}/OTconfig.h" _VERSION_STRING
      file (STRINGS "${OPENTURNS_INCLUDE_DIR}/OTconfig.h" _VERSION_STRING
          REGEX ".*PACKAGE_VERSION.*")
        REGEX ".*PACKAGE_VERSION.*")
        string (REGEX REPLACE ".*_VERSION[ ]+\"([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" OPENTURNS_VERSION "${_VERSION_STRING}")
      string (REGEX REPLACE ".*_VERSION[ ]+\"([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" OPENTURNS_VERSION "${_VERSION_STRING}")
      endif ()
     endif ()
     endif ()
  endif ()




    # check version
  # check version
    set (_OPENTURNS_VERSION_MATCH TRUE)
  set (_OPENTURNS_VERSION_MATCH TRUE)
    set (_REQUIRED_VERSION "${OpenTURNS_FIND_VERSION_MAJOR}.${OpenTURNS_FIND_VERSION_MINOR}.${OpenTURNS_FIND_VERSION_PATCH}")
  set (_REQUIRED_VERSION "${OpenTURNS_FIND_VERSION_MAJOR}.${OpenTURNS_FIND_VERSION_MINOR}.${OpenTURNS_FIND_VERSION_PATCH}")
    if (OpenTURNS_FIND_VERSION)
  if (OpenTURNS_FIND_VERSION)
      if (OpenTURNS_FIND_VERSION_EXACT)
    if (OpenTURNS_FIND_VERSION_EXACT)
        if ("${_REQUIRED_VERSION}" VERSION_EQUAL "${OPENTURNS_VERSION}")
      if ("${_REQUIRED_VERSION}" VERSION_EQUAL "${OPENTURNS_VERSION}")
        else ()
          set (_OPENTURNS_VERSION_MATCH FALSE)
        endif ()
       else ()
       else ()
         if ("${_REQUIRED_VERSION}" VERSION_GREATER "${OPENTURNS_VERSION}")
         set (_OPENTURNS_VERSION_MATCH FALSE)
          set (_OPENTURNS_VERSION_MATCH FALSE)
      endif ()
        endif ()
    else ()
      if ("${_REQUIRED_VERSION}" VERSION_GREATER "${OPENTURNS_VERSION}")
        set (_OPENTURNS_VERSION_MATCH FALSE)
       endif ()
       endif ()
     endif ()
     endif ()
  endif ()




    # check for library directory
  # check for library directory
    if (NOT OPENTURNS_LIBRARY)
  if (NOT OPENTURNS_LIBRARY)
      find_library (OPENTURNS_LIBRARY
    find_library (OPENTURNS_LIBRARY
        NAMES
      NAMES
          OT
        OT
        PATHS
      PATHS
          ${OPENTURNS_ROOT_DIR}/lib
        ${OPENTURNS_ROOT_DIR}/lib
          C:/OpenTURNS/lib
        C:/OpenTURNS/lib
        PATH_SUFFIXES
      PATH_SUFFIXES
          openturns
        openturns
        DOC
      DOC
          "OpenTURNS library location"
        "OpenTURNS library location"
      )
    )
    endif ()
  endif ()




    # find dependent libraries
  # find dependent libraries
    if (NOT OPENTURNS_LIBRARIES)
  if (NOT OPENTURNS_LIBRARIES)
      set (OPENTURNS_LIBRARIES ${OPENTURNS_LIBRARY})
    set (OPENTURNS_LIBRARIES ${OPENTURNS_LIBRARY})
      list (APPEND OPENTURNS_LIBRARIES ${LIBXML2_LIBRARIES})
    list (APPEND OPENTURNS_LIBRARIES ${LIBXML2_LIBRARIES})
      list (APPEND OPENTURNS_LIBRARIES ${PYTHON_LIBRARIES})
    list (APPEND OPENTURNS_LIBRARIES ${PYTHON_LIBRARIES})
    endif ()
  endif ()




    # root dir
  # root dir
    if (NOT OPENTURNS_ROOT_DIR)
  if (NOT OPENTURNS_ROOT_DIR)
      # try to guess root dir from include dir
    # try to guess root dir from include dir
      if (OPENTURNS_INCLUDE_DIR)
    if (OPENTURNS_INCLUDE_DIR)
        string (REGEX REPLACE "(.*)/include/openturns/?" "\\1" OPENTURNS_ROOT_DIR "${OPENTURNS_INCLUDE_DIR}")
      string (REGEX REPLACE "(.*)/include/openturns/?" "\\1" OPENTURNS_ROOT_DIR ${OPENTURNS_INCLUDE_DIR})


      # try to guess root dir from library dir
    # try to guess root dir from library dir
      elseif (OPENTURNS_LIBRARY)
    elseif (OPENTURNS_LIBRARY)
        get_filename_component (_LIBRARY_DIR ${OPENTURNS_LIBRARY} PATH)
      string (REGEX REPLACE "(.*)/lib[32|64]?/openturns/.*" "\\1" OPENTURNS_ROOT_DIR ${OPENTURNS_LIBRARY})
        string (REGEX REPLACE "(.*)/lib[0-9]*/openturns/?" "\\1" OPENTURNS_ROOT_DIR "${_LIBRARY_DIR}")
      endif ()
     endif ()
     endif ()
  endif ()


  # examples dir
  if (NOT OPENTURNS_EXAMPLES_DIR)
    set (OPENTURNS_EXAMPLES_DIR "${OPENTURNS_ROOT_DIR}/share/openturns/examples")
  endif ()


    # examples dir
    if (NOT OPENTURNS_EXAMPLES_DIR)
      set (OPENTURNS_EXAMPLES_DIR "${OPENTURNS_ROOT_DIR}/share/openturns/examples")
    endif ()


  # debug
  if (OPENTURNS_DEBUG)
    message (STATUS "OPENTURNS_LIBRARY: ${OPENTURNS_LIBRARY}")
    message (STATUS "OPENTURNS_LIBRARIES: ${OPENTURNS_LIBRARIES}")
    message (STATUS "OPENTURNS_INCLUDE_DIR: ${OPENTURNS_INCLUDE_DIR}")
    message (STATUS "OPENTURNS_INCLUDE_DIRS: ${OPENTURNS_INCLUDE_DIRS}")
    message (STATUS "OPENTURNS_VERSION: ${OPENTURNS_VERSION}")
    message (STATUS "OPENTURNS_SWIG_INCLUDE_DIR: ${OPENTURNS_SWIG_INCLUDE_DIR}")
    message (STATUS "OPENTURNS_ROOT_DIR: ${OPENTURNS_ROOT_DIR}")
    message (STATUS "OPENTURNS_EXAMPLES_DIR: ${OPENTURNS_EXAMPLES_DIR}")
  endif ()


    # debug
    if (OPENTURNS_DEBUG)
      message (STATUS "OPENTURNS_LIBRARY: ${OPENTURNS_LIBRARY}")
      message (STATUS "OPENTURNS_LIBRARIES: ${OPENTURNS_LIBRARIES}")
      message (STATUS "OPENTURNS_INCLUDE_DIR: ${OPENTURNS_INCLUDE_DIR}")
      message (STATUS "OPENTURNS_INCLUDE_DIRS: ${OPENTURNS_INCLUDE_DIRS}")
      message (STATUS "OPENTURNS_VERSION: ${OPENTURNS_VERSION}")
      message (STATUS "OPENTURNS_SWIG_INCLUDE_DIR: ${OPENTURNS_SWIG_INCLUDE_DIR}")
      message (STATUS "OPENTURNS_ROOT_DIR: ${OPENTURNS_ROOT_DIR}")
      message (STATUS "OPENTURNS_EXAMPLES_DIR: ${OPENTURNS_EXAMPLES_DIR}")
    endif ()


  # handle REQUIRED and QUIET options
  include (FindPackageHandleStandardArgs)
  find_package_handle_standard_args (OpenTURNS DEFAULT_MSG OPENTURNS_LIBRARY
    OPENTURNS_LIBRARIES
    LIBXML2_FOUND
    PYTHONLIBS_FOUND
    OPENTURNS_INCLUDE_DIR OPENTURNS_INCLUDE_DIRS OPENTURNS_SWIG_INCLUDE_DIR
    OPENTURNS_VERSION _OPENTURNS_VERSION_MATCH
    OPENTURNS_ROOT_DIR
    OPENTURNS_EXAMPLES_DIR
  )


    # handle REQUIRED and QUIET options
  mark_as_advanced (
    include (FindPackageHandleStandardArgs)
     OPENTURNS_LIBRARY
     find_package_handle_standard_args (OpenTURNS DEFAULT_MSG OPENTURNS_LIBRARY
    OPENTURNS_INCLUDE_DIR
      OPENTURNS_LIBRARIES
    OPENTURNS_SWIG_INCLUDE_DIR
      LIBXML2_FOUND
    OPENTURNS_INCLUDE_DIRS
      PYTHONLIBS_FOUND
    OPENTURNS_VERSION
      OPENTURNS_INCLUDE_DIR OPENTURNS_INCLUDE_DIRS OPENTURNS_SWIG_INCLUDE_DIR
    OPENTURNS_LIBRARIES
      OPENTURNS_VERSION _OPENTURNS_VERSION_MATCH
    OPENTURNS_ROOT_DIR
      OPENTURNS_ROOT_DIR
    OPENTURNS_EXAMPLES_DIR
      OPENTURNS_EXAMPLES_DIR
  )
    )


    mark_as_advanced (
      OPENTURNS_LIBRARY
      OPENTURNS_INCLUDE_DIR
      OPENTURNS_SWIG_INCLUDE_DIR
      OPENTURNS_INCLUDE_DIRS
      OPENTURNS_VERSION
      OPENTURNS_LIBRARIES
      OPENTURNS_ROOT_DIR
      OPENTURNS_EXAMPLES_DIR
    )




Line 245: Line 245:




  # wrapper -----------------------------------------------------------------------


    # wrapper -----------------------------------------------------------------------


  # threads
  if (NOT Threads_FOUND)
    find_package (Threads ${_FIND_ARG})
  endif ()


     # threads
  # wrapper definitions
     if (NOT Threads_FOUND)
  if (NOT OPENTURNS_WRAPPER_DEFINITIONS)
       find_package (Threads ${_FIND_ARG})
     set(OPENTURNS_WRAPPER_DEFINITIONS)
     if (CMAKE_USE_PTHREADS_INIT)
       list (APPEND OPENTURNS_WRAPPER_DEFINITIONS -DHAVE_PTHREAD_H)
     endif ()
     endif ()
  endif ()


    # wrapper definitions
    if (NOT OPENTURNS_WRAPPER_DEFINITIONS)
      set(OPENTURNS_WRAPPER_DEFINITIONS)
      if (CMAKE_USE_PTHREADS_INIT)
        list (APPEND OPENTURNS_WRAPPER_DEFINITIONS -DHAVE_PTHREAD_H)
      endif ()
    endif ()


  # find wrapper dir
  if (NOT OPENTURNS_WRAPPER_DIR)
    find_path (OPENTURNS_WRAPPER_DIR
      NAMES
        wrapper.xml
      PATHS
        ${OPENTURNS_ROOT_DIR}
      PATH_SUFFIXES
        share/openturns/wrappers
      DOC
        "OpenTURNS wrapper location"
    )
  endif ()


    # find wrapper dir
    if (NOT OPENTURNS_WRAPPER_DIR)
      find_path (OPENTURNS_WRAPPER_DIR
        NAMES
          wrapper.xml
        PATHS
          ${OPENTURNS_ROOT_DIR}
        PATH_SUFFIXES
          share/openturns/wrappers
        DOC
          "OpenTURNS wrapper location"
      )
    endif ()


  if (NOT OPENTURNS_WRAPPER_LIBRARIES)
    set(OPENTURNS_WRAPPER_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
  endif ()


     if (NOT OPENTURNS_WRAPPER_LIBRARIES)
  # check if wrapper library is usable
       set(OPENTURNS_WRAPPER_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
  if (NOT OPENTURNS_WRAPPER_FOUND)
     if (Threads_FOUND
          AND CMAKE_USE_PTHREADS_INIT
          AND OPENTURNS_WRAPPER_DEFINITIONS
          AND OPENTURNS_WRAPPER_DIR
          AND OPENTURNS_WRAPPER_LIBRARIES
          AND OPENTURNS_FOUND)
       set (OPENTURNS_WRAPPER_FOUND TRUE)
    else ()
      set (OPENTURNS_WRAPPER_FOUND FALSE)
     endif ()
     endif ()
  endif ()


    # check if wrapper library is usable
    if (NOT OPENTURNS_WRAPPER_FOUND)
      if (Threads_FOUND
            AND CMAKE_USE_PTHREADS_INIT
            AND OPENTURNS_WRAPPER_DEFINITIONS
            AND OPENTURNS_WRAPPER_DIR
            AND OPENTURNS_WRAPPER_LIBRARIES
            AND OPENTURNS_FOUND)
        set (OPENTURNS_WRAPPER_FOUND TRUE)
      else ()
        set (OPENTURNS_WRAPPER_FOUND FALSE)
      endif ()
    endif ()


  mark_as_advanced (
    OPENTURNS_WRAPPER_FOUND
    OPENTURNS_WRAPPER_DIR
    OPENTURNS_WRAPPER_LIBRARIES
    OPENTURNS_WRAPPER_DEFINITIONS
  )


    mark_as_advanced (
      OPENTURNS_WRAPPER_FOUND
      OPENTURNS_WRAPPER_DIR
      OPENTURNS_WRAPPER_LIBRARIES
      OPENTURNS_WRAPPER_DEFINITIONS
    )




Line 309: Line 309:




  # module --------------------------------------------------------------


    # module --------------------------------------------------------------


  # find module directory
  if (NOT OPENTURNS_MODULE_DIR)
    set (OPENTURNS_MODULE_DIR "${OPENTURNS_ROOT_DIR}/lib/openturns/module")
  endif ()


    # find module directory
    if (NOT OPENTURNS_MODULE_DIR)
      set (OPENTURNS_MODULE_DIR "${OPENTURNS_ROOT_DIR}/lib/openturns/module")
    endif ()


  # set module definitions
  if (NOT OPENTURNS_MODULE_DEFINITIONS)
    set (OPENTURNS_MODULE_DEFINITIONS)


     # set module definitions
     # check for STDC_HEADERS
     if (NOT OPENTURNS_MODULE_DEFINITIONS)
     if (NOT HAVE_STDLIB_H)
       set (OPENTURNS_MODULE_DEFINITIONS)
      check_include_file_cxx (stdlib.h HAVE_STDLIB_H)
    endif ()
    if (NOT HAVE_STDARG_H)
      check_include_file_cxx (stdarg.h HAVE_STDARG_H)
    endif ()
    if (NOT HAVE_STRING_H)
      check_include_file_cxx (string.h HAVE_STRING_H)
    endif ()
    if (NOT HAVE_FLOAT_H)
      check_include_file_cxx (float.h HAVE_FLOAT_H)
    endif ()
    check_function_exists (memchr HAVE_MEMCHR)
    if (NOT HAVE_FREE)
      check_function_exists (free HAVE_FREE)
    endif ()
    if (NOT HAVE_CTYPE_H)
      check_include_file_cxx (ctype.h HAVE_CTYPE_H)
    endif ()
    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)
      list (APPEND OPENTURNS_MODULE_DEFINITIONS -DSTDC_HEADERS_H=1)
    else ()
       list (APPEND OPENTURNS_MODULE_DEFINITIONS -DSTDC_HEADERS_H=0)
    endif ()


       # check for STDC_HEADERS
    # this macro checks a header and defines the corresponding macro
       if (NOT HAVE_STDLIB_H)
    macro (check_include_file_cxx_define_macro header_file)
         check_include_file_cxx (stdlib.h HAVE_STDLIB_H)
      # get macro name from header_file
      string (TOUPPER "${header_file}" macro_name)
      string (REGEX REPLACE "[/.]" "_" macro_name ${macro_name})
      set(macro_name HAVE_${macro_name})
       # check for header
       if (NOT ${macro_name})
         check_include_file_cxx (${header_file} ${macro_name})
       endif ()
       endif ()
       if (NOT HAVE_STDARG_H)
       # define macro
        check_include_file_cxx (stdarg.h HAVE_STDARG_H)
       if(${macro_name})
      endif ()
         list (APPEND OPENTURNS_MODULE_DEFINITIONS -D${macro_name}=1)
      if (NOT HAVE_STRING_H)
       else()
        check_include_file_cxx (string.h HAVE_STRING_H)
         list (APPEND OPENTURNS_MODULE_DEFINITIONS -D${macro_name}=0)
      endif ()
      if (NOT HAVE_FLOAT_H)
        check_include_file_cxx (float.h HAVE_FLOAT_H)
      endif ()
      check_function_exists (memchr HAVE_MEMCHR)
      if (NOT HAVE_FREE)
        check_function_exists (free HAVE_FREE)
      endif ()
      if (NOT HAVE_CTYPE_H)
        check_include_file_cxx (ctype.h HAVE_CTYPE_H)
      endif ()
       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)
         list (APPEND OPENTURNS_MODULE_DEFINITIONS -DSTDC_HEADERS_H=1)
       else ()
         list (APPEND OPENTURNS_MODULE_DEFINITIONS -DSTDC_HEADERS_H=0)
       endif ()
       endif ()
    endmacro ()
    # check for some headers
    check_include_file_cxx_define_macro (sys/types.h)
    check_include_file_cxx_define_macro (sys/stat.h)
    check_include_file_cxx_define_macro (stdlib.h)
    check_include_file_cxx_define_macro (string.h)
    check_include_file_cxx_define_macro (memory.h)
    check_include_file_cxx_define_macro (strings.h)
    check_include_file_cxx_define_macro (inttypes.h)
    check_include_file_cxx_define_macro (stdint.h)
    check_include_file_cxx_define_macro (unistd.h)
    check_include_file_cxx_define_macro (dlfcn.h)
    check_include_file_cxx_define_macro (stdbool.h)
    check_include_file_cxx_define_macro (regex.h)
  endif ()


      # this macro checks a header and defines the corresponding macro
      macro (check_include_file_cxx_define_macro header_file)
        # get macro name from header_file
        string (TOUPPER "${header_file}" macro_name)
        string (REGEX REPLACE "[/.]" "_" macro_name ${macro_name})
        set(macro_name HAVE_${macro_name})
        # check for header
        if (NOT ${macro_name})
          check_include_file_cxx (${header_file} ${macro_name})
        endif ()
        # define macro
        if(${macro_name})
          list (APPEND OPENTURNS_MODULE_DEFINITIONS -D${macro_name}=1)
        else()
          list (APPEND OPENTURNS_MODULE_DEFINITIONS -D${macro_name}=0)
        endif ()
      endmacro ()


      # check for some headers
  mark_as_advanced (
      check_include_file_cxx_define_macro (sys/types.h)
    OPENTURNS_MODULE_DIR
      check_include_file_cxx_define_macro (sys/stat.h)
    OPENTURNS_MODULE_DEFINITIONS
      check_include_file_cxx_define_macro (stdlib.h)
  )
      check_include_file_cxx_define_macro (string.h)
      check_include_file_cxx_define_macro (memory.h)
      check_include_file_cxx_define_macro (strings.h)
      check_include_file_cxx_define_macro (inttypes.h)
      check_include_file_cxx_define_macro (stdint.h)
      check_include_file_cxx_define_macro (unistd.h)
      check_include_file_cxx_define_macro (dlfcn.h)
      check_include_file_cxx_define_macro (stdbool.h)
      check_include_file_cxx_define_macro (regex.h)
    endif ()




     mark_as_advanced (
  # add module defs
      OPENTURNS_MODULE_DIR
  macro (add_module_extra_definitions module_name)
      OPENTURNS_MODULE_DEFINITIONS
     add_definitions (-DPACKAGE_NAME="OpenTURNS module ${module_name}")
     )
    add_definitions (-DPACKAGE_TARNAME="${module_name}")
    add_definitions (-DPACKAGE_VERSION="${OPENTURNS_VERSION}")
     add_definitions (-DPACKAGE_STRING="OpenTURNS module ${module_name} ${OPENTURNS_VERSION}")
    add_definitions (-DPACKAGE_BUGREPORT="")
  endmacro ()




    # add module defs
    macro (add_module_extra_definitions module_name)
      add_definitions (-DPACKAGE_NAME="OpenTURNS module ${module_name}")
      add_definitions (-DPACKAGE_TARNAME="${module_name}")
      add_definitions (-DPACKAGE_VERSION="${OPENTURNS_VERSION}")
      add_definitions (-DPACKAGE_STRING="OpenTURNS module ${module_name} ${OPENTURNS_VERSION}")
      add_definitions (-DPACKAGE_BUGREPORT="")
    endmacro ()




Line 402: Line 403:




  # modules ----------------------------------------------------------------------


  # find modules
  if (OpenTURNS_FIND_COMPONENTS)
    foreach (module_name ${OpenTURNS_FIND_COMPONENTS})
      string(TOLOWER ${module_name} module_lowercase_name)
      string(TOUPPER ${module_name} module_uppercase_name)


    # modules ----------------------------------------------------------------------
      set (OPENTURNS_${module_uppercase_name}_FOUND FALSE)


    # find modules
      # module library
    if (OpenTURNS_FIND_COMPONENTS)
      if (NOT OPENTURNS_${module_uppercase_name}_LIBRARY)
      foreach (module_name ${OpenTURNS_FIND_COMPONENTS})
        find_library (OPENTURNS_${module_uppercase_name}_LIBRARY
        string(TOLOWER ${module_name} module_lowercase_name)
          NAMES
        string(TOUPPER ${module_name} module_uppercase_name)
            ${module_name}
          PATHS
            ${OPENTURNS_MODULE_DIR}/lib
          PATH_SUFFIXES
            ${module_lowercase_name}
        )
      endif ()


         set (OPENTURNS_${module_uppercase_name}_FOUND FALSE)
      # module libraries
      if (NOT OPENTURNS_${module_uppercase_name}_LIBRARIES)
         set (OPENTURNS_${module_uppercase_name}_LIBRARIES ${OPENTURNS_${module_uppercase_name}_LIBRARY})
        list (APPEND OPENTURNS_${module_uppercase_name}_LIBRARIES ${OPENTURNS_LIBRARIES})
      endif ()


        # module library
      # module include dir
        if (NOT OPENTURNS_${module_uppercase_name}_LIBRARY)
      if (NOT OPENTURNS_${module_uppercase_name}_INCLUDE_DIR)
          find_library (OPENTURNS_${module_uppercase_name}_LIBRARY
        set (OPENTURNS_${module_uppercase_name}_INCLUDE_DIR "${OPENTURNS_MODULE_DIR}/include/${module_lowercase_name}")
            NAMES
      endif ()
              ${module_name}
            PATHS
              ${OPENTURNS_MODULE_DIR}/lib
            PATH_SUFFIXES
              ${module_lowercase_name}
          )
        endif ()


        # module libraries
      # module include dirs
        if (NOT OPENTURNS_${module_uppercase_name}_LIBRARIES)
      if (NOT OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS)
          set (OPENTURNS_${module_uppercase_name}_LIBRARIES ${OPENTURNS_${module_uppercase_name}_LIBRARY})
        set (OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS ${OPENTURNS_${module_uppercase_name}_INCLUDE_DIR})
          list (APPEND OPENTURNS_${module_uppercase_name}_LIBRARIES ${OPENTURNS_LIBRARIES})
        list (APPEND OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS ${OPENTURNS_INCLUDE_DIRS})
        endif ()
      endif ()


        # module include dir
      # module swig include dir
        if (NOT OPENTURNS_${module_uppercase_name}_INCLUDE_DIR)
      if (NOT OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR)
          set (OPENTURNS_${module_uppercase_name}_INCLUDE_DIR "${OPENTURNS_MODULE_DIR}/include/${module_lowercase_name}")
        set (OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR "${OPENTURNS_MODULE_DIR}/share/${module_lowercase_name}/swig")
        endif ()
      endif ()


        # module include dirs
      # test if the module is found
        if (NOT OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS)
      if (NOT OPENTURNS_${module_uppercase_name}_FOUND)
          set (OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS ${OPENTURNS_${module_uppercase_name}_INCLUDE_DIR})
        if (OPENTURNS_${module_uppercase_name}_LIBRARY
           list (APPEND OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS ${OPENTURNS_INCLUDE_DIRS})
              AND OPENTURNS_${module_uppercase_name}_LIBRARIES
              AND OPENTURNS_${module_uppercase_name}_INCLUDE_DIR
              AND OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS
              AND OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR
              AND OPENTURNS_FOUND)
           set (OPENTURNS_${module_uppercase_name}_FOUND TRUE)
        else ()
          set (OPENTURNS_${module_uppercase_name}_FOUND FALSE)
         endif ()
         endif ()
      endif ()


        # module swig include dir
      # handle REQUIRED and QUIET options
        if (NOT OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR)
      if (OPENTURNS_${module_uppercase_name}_FOUND)
           set (OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR "${OPENTURNS_MODULE_DIR}/share/${module_lowercase_name}/swig")
        if (NOT OpenTURNS_FIND_QUIETLY)
           message (STATUS "Found OpenTURNS module ${module_name}: ${OPENTURNS_${module_uppercase_name}_LIBRARY}")
         endif ()
         endif ()
 
      else ()
        # test if the module is found
        if (OpenTURNS_FIND_REQUIRED)
        if (NOT OPENTURNS_${module_uppercase_name}_FOUND)
           message(SEND_ERROR "Unable to find the requested OpenTURNS module : ${module_name}")
          if (OPENTURNS_${module_uppercase_name}_LIBRARY
                AND OPENTURNS_${module_uppercase_name}_LIBRARIES
                AND OPENTURNS_${module_uppercase_name}_INCLUDE_DIR
                AND OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS
                AND OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR
                AND OPENTURNS_FOUND)
            set (OPENTURNS_${module_uppercase_name}_FOUND TRUE)
           else ()
            set (OPENTURNS_${module_uppercase_name}_FOUND FALSE)
          endif ()
         endif ()
         endif ()
 
         if (NOT OpenTURNS_FIND_QUIETLY)
         # handle REQUIRED and QUIET options
           message (STATUS "Could not find OpenTURNS module ${module_name}")
        if (OPENTURNS_${module_uppercase_name}_FOUND)
          if (NOT OpenTURNS_FIND_QUIETLY)
            message (STATUS "Found OpenTURNS module ${module_name}: ${OPENTURNS_${module_uppercase_name}_LIBRARY}")
          endif ()
        else ()
           if (OpenTURNS_FIND_REQUIRED)
            message(SEND_ERROR "Unable to find the requested OpenTURNS module : ${module_name}")
          endif ()
          if (NOT OpenTURNS_FIND_QUIETLY)
            message (STATUS "Could not find OpenTURNS module ${module_name}")
          endif ()
         endif ()
         endif ()
      endif ()


        mark_as_advanced (
      mark_as_advanced (
          OPENTURNS_${module_uppercase_name}_FOUND
        OPENTURNS_${module_uppercase_name}_FOUND
          OPENTURNS_${module_uppercase_name}_LIBRARY
        OPENTURNS_${module_uppercase_name}_LIBRARY
          OPENTURNS_${module_uppercase_name}_LIBRARIES
        OPENTURNS_${module_uppercase_name}_LIBRARIES
          OPENTURNS_${module_uppercase_name}_INCLUDE_DIR
        OPENTURNS_${module_uppercase_name}_INCLUDE_DIR
          OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS
        OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS
          OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR
        OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR
        )
      )


      endforeach ()
    endforeach ()
    endif ()
  endif ()




Line 493: Line 492:




    # debug ------------------------------------------------------------------------------------------
  # debug ------------------------------------------------------------------------------------------


    if (OPENTURNS_DEBUG)
  if (OPENTURNS_DEBUG)
      message (STATUS "OPENTURNS_FOUND: ${OPENTURNS_FOUND}")
    message (STATUS "OPENTURNS_FOUND: ${OPENTURNS_FOUND}")


      message (STATUS "OPENTURNS_WRAPPER_FOUND: ${OPENTURNS_WRAPPER_FOUND}")
    message (STATUS "OPENTURNS_WRAPPER_FOUND: ${OPENTURNS_WRAPPER_FOUND}")
      message (STATUS "OPENTURNS_WRAPPER_DIR: ${OPENTURNS_WRAPPER_DIR}")
    message (STATUS "OPENTURNS_WRAPPER_DIR: ${OPENTURNS_WRAPPER_DIR}")
      message (STATUS "OPENTURNS_WRAPPER_DEFINITIONS: ${OPENTURNS_WRAPPER_DEFINITIONS}")
    message (STATUS "OPENTURNS_WRAPPER_DEFINITIONS: ${OPENTURNS_WRAPPER_DEFINITIONS}")
      message (STATUS "OPENTURNS_WRAPPER_LIBRARIES: ${OPENTURNS_WRAPPER_LIBRARIES}")
    message (STATUS "OPENTURNS_WRAPPER_LIBRARIES: ${OPENTURNS_WRAPPER_LIBRARIES}")


      message (STATUS "OPENTURNS_MODULE_DIR: ${OPENTURNS_MODULE_DIR}")
    message (STATUS "OPENTURNS_MODULE_DIR: ${OPENTURNS_MODULE_DIR}")
      message (STATUS "OPENTURNS_MODULE_DEFINITIONS: ${OPENTURNS_MODULE_DEFINITIONS}")
    message (STATUS "OPENTURNS_MODULE_DEFINITIONS: ${OPENTURNS_MODULE_DEFINITIONS}")


      foreach (module_name ${OpenTURNS_FIND_COMPONENTS})
    foreach (module_name ${OpenTURNS_FIND_COMPONENTS})
        message (STATUS "OPENTURNS_${module_uppercase_name}_FOUND: ${OPENTURNS_${module_uppercase_name}_FOUND}")
      message (STATUS "OPENTURNS_${module_uppercase_name}_FOUND: ${OPENTURNS_${module_uppercase_name}_FOUND}")
        message (STATUS "OPENTURNS_${module_uppercase_name}_LIBRARY: ${OPENTURNS_${module_uppercase_name}_LIBRARY}")
      message (STATUS "OPENTURNS_${module_uppercase_name}_LIBRARY: ${OPENTURNS_${module_uppercase_name}_LIBRARY}")
        message (STATUS "OPENTURNS_${module_uppercase_name}_LIBRARIES: ${OPENTURNS_${module_uppercase_name}_LIBRARIES}")
      message (STATUS "OPENTURNS_${module_uppercase_name}_LIBRARIES: ${OPENTURNS_${module_uppercase_name}_LIBRARIES}")
        message (STATUS "OPENTURNS_${module_uppercase_name}_INCLUDE_DIR: ${OPENTURNS_${module_uppercase_name}_INCLUDE_DIR}")
      message (STATUS "OPENTURNS_${module_uppercase_name}_INCLUDE_DIR: ${OPENTURNS_${module_uppercase_name}_INCLUDE_DIR}")
        message (STATUS "OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS: ${OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS}")
      message (STATUS "OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS: ${OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS}")
        message (STATUS "OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR: ${OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR}")
      message (STATUS "OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR: ${OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR}")
      endforeach ()
    endforeach ()
    endif ()
  endif ()


-----
-----

Revision as of 13:22, 6 August 2010

Back


File:FindOpenTURNS.cmake


  1. -- Try to find OpenTURNS
 #
 #  OpenTURNS is an Open source initiative to Treat Uncertainties,
 #  Risks’N Statistics in a structured industrial approach,
 #  available at http://www.openturns.org/
 #
 #  ---------------------------------------------------------------------
 #
 #  -- Library usage example :
 #
 #  find_package (OpenTURNS 0.13.1)
 #  if (OPENTURNS_FOUND)
 #     include_directories (${OPENTURNS_INCLUDE_DIRS})
 #     add_executable (foo foo.cpp)
 #     target_link_libraries (foo ${OPENTURNS_LIBRARIES})
 #  endif ()
 #
 #  -- Module usage example :
 #
 #  find_package (OpenTURNS 0.13 COMPONENTS Trapezoidal)
 #  if (OPENTURNS_TRAPEZOIDAL_FOUND)
 #     include_directories (${OPENTURNS_TRAPEZOIDAL_INCLUDE_DIRS})
 #     add_executable (foo foo.cpp)
 #     target_link_libraries (foo ${OPENTURNS_TRAPEZOIDAL_LIBRARIES})
 #  endif ()
 #
 #  -- Show some debug information :
 #
 #  set (OPENTURNS_DEBUG TRUE)
 #  find_package (OpenTURNS)
 #
 #  ---------------------------------------------------------------------
 #
 #  -- This module defines :
 #
 #  OPENTURNS_FOUND - OpenTURNS is usable as a library
 #  OPENTURNS_INCLUDE_DIR - Where to find OT.hxx (not for general use)
 #  OPENTURNS_INCLUDE_DIRS - dependencies include directories
 #  OPENTURNS_SWIG_INCLUDE_DIR - Include directory to swig (.i) interface
 #  OPENTURNS_VERSION - Version string
 #  OPENTURNS_LIBRARY - Path to libOT.so (not for general use)
 #  OPENTURNS_LIBRARIES - Link these to use the library
 #  OPENTURNS_ROOT_DIR - Installation directory
 #  OPENTURNS_EXAMPLES_DIR - path to examples programs
 #
 #  OPENTURNS_WRAPPER_FOUND - OpenTURNS wrapper library is usable
 #  OPENTURNS_WRAPPER_DIR - Wrapper directory
 #  OPENTURNS_WRAPPER_LIBRARIES - Link these to use the wrapper
 #  OPENTURNS_WRAPPER_DEFINITIONS - Compiler switches required for wrapper
 #
 #  OPENTURNS_MODULE_DIR - OpenTURNS module directory
 #  OPENTURNS_MODULE_DEFINITIONS - Compiler switches required for module
 #  OPENTURNS_NAME_FOUND - True if module NAME was found
 #  OPENTURNS_NAME_INCLUDE_DIR - Module NAME headers
 #  OPENTURNS_NAME_INCLUDE_DIRS - Module NAME includes
 #  OPENTURNS_NAME_SWIG_INCLUDE_DIR - Module NAME swig (.i) headers
 #  OPENTURNS_NAME_LIBRARY - Module NAME library location
 #  OPENTURNS_NAME_LIBRARIES - Module NAME libraries location
 #  Macro add_module_extra_definitions(MODULE_NAME VERSION)
 #  MUST be called when building a module
 #
 #  ---------------------------------------------------------------------
 #
 #  Copyright (c) 2009 Mathieu Lapointe <lapointe at phimeca dot com>
 #  Copyright (c) 2010 Julien Schueller <schueller at phimeca dot com>
 #
 #  Redistribution and use is allowed according to the terms of the New
 #  BSD license.
 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 #
 include (CheckFunctionExists)
 include (CheckIncludeFileCXX)


 # check dependencies quietly
 if (OpenTURNS_FIND_QUIETLY)
   # except when debugging
   if (NOT OPENTURNS_DEBUG)
     set (_FIND_ARG QUIET)
   endif ()
 endif ()


 # libxml
 if (NOT LIBXML2_FOUND)
   find_package (LibXml2 2.6.27 ${_FIND_ARG})
 endif ()


 # python
 if (NOT PYTHONLIBS_FOUND)
   find_package (PythonLibs 2.5 ${_FIND_ARG})
 endif()


 # include dir
 if (NOT OPENTURNS_INCLUDE_DIR)
   find_path (OPENTURNS_INCLUDE_DIR
     NAMES
       OT.hxx
     PATHS
       ${OPENTURNS_ROOT_DIR}/include
       C:/OpenTURNS/include
     PATH_SUFFIXES
       openturns
     DOC
       "OpenTURNS include directory"
   )
 endif ()


 # set swig include dir
 if (NOT OPENTURNS_SWIG_INCLUDE_DIR)
   set(OPENTURNS_SWIG_INCLUDE_DIR "${OPENTURNS_INCLUDE_DIR}/swig")
 endif ()


 # dependencies includes
 if (NOT OPENTURNS_INCLUDE_DIRS)
   if (OPENTURNS_INCLUDE_DIR)
     set (OPENTURNS_INCLUDE_DIRS ${OPENTURNS_INCLUDE_DIR})
   endif ()
   list (APPEND OPENTURNS_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR})
   list (APPEND OPENTURNS_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) # cmake >= 2.8.0
   list (APPEND OPENTURNS_INCLUDE_DIRS ${PYTHON_INCLUDE_PATH}) # cmake <= 2.6.4
 endif ()


 # version
 if (NOT OPENTURNS_VERSION)
   if (OPENTURNS_INCLUDE_DIR)
     file (STRINGS "${OPENTURNS_INCLUDE_DIR}/OTconfig.h" _VERSION_STRING
       REGEX ".*PACKAGE_VERSION.*")
     string (REGEX REPLACE ".*_VERSION[ ]+\"([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" OPENTURNS_VERSION "${_VERSION_STRING}")
   endif ()
 endif ()


 # check version
 set (_OPENTURNS_VERSION_MATCH TRUE)
 set (_REQUIRED_VERSION "${OpenTURNS_FIND_VERSION_MAJOR}.${OpenTURNS_FIND_VERSION_MINOR}.${OpenTURNS_FIND_VERSION_PATCH}")
 if (OpenTURNS_FIND_VERSION)
   if (OpenTURNS_FIND_VERSION_EXACT)
     if ("${_REQUIRED_VERSION}" VERSION_EQUAL "${OPENTURNS_VERSION}")
     else ()
       set (_OPENTURNS_VERSION_MATCH FALSE)
     endif ()
   else ()
     if ("${_REQUIRED_VERSION}" VERSION_GREATER "${OPENTURNS_VERSION}")
       set (_OPENTURNS_VERSION_MATCH FALSE)
     endif ()
   endif ()
 endif ()


 # check for library directory
 if (NOT OPENTURNS_LIBRARY)
   find_library (OPENTURNS_LIBRARY
     NAMES
       OT
     PATHS
       ${OPENTURNS_ROOT_DIR}/lib
       C:/OpenTURNS/lib
     PATH_SUFFIXES
       openturns
     DOC
       "OpenTURNS library location"
   )
 endif ()


 # find dependent libraries
 if (NOT OPENTURNS_LIBRARIES)
   set (OPENTURNS_LIBRARIES ${OPENTURNS_LIBRARY})
   list (APPEND OPENTURNS_LIBRARIES ${LIBXML2_LIBRARIES})
   list (APPEND OPENTURNS_LIBRARIES ${PYTHON_LIBRARIES})
 endif ()


 # root dir
 if (NOT OPENTURNS_ROOT_DIR)
   # try to guess root dir from include dir
   if (OPENTURNS_INCLUDE_DIR)
     string (REGEX REPLACE "(.*)/include/openturns/?" "\\1" OPENTURNS_ROOT_DIR ${OPENTURNS_INCLUDE_DIR})
   # try to guess root dir from library dir
   elseif (OPENTURNS_LIBRARY)
     string (REGEX REPLACE "(.*)/lib[32|64]?/openturns/.*" "\\1" OPENTURNS_ROOT_DIR ${OPENTURNS_LIBRARY})
   endif ()
 endif ()


 # examples dir
 if (NOT OPENTURNS_EXAMPLES_DIR)
   set (OPENTURNS_EXAMPLES_DIR "${OPENTURNS_ROOT_DIR}/share/openturns/examples")
 endif ()


 # debug
 if (OPENTURNS_DEBUG)
   message (STATUS "OPENTURNS_LIBRARY: ${OPENTURNS_LIBRARY}")
   message (STATUS "OPENTURNS_LIBRARIES: ${OPENTURNS_LIBRARIES}")
   message (STATUS "OPENTURNS_INCLUDE_DIR: ${OPENTURNS_INCLUDE_DIR}")
   message (STATUS "OPENTURNS_INCLUDE_DIRS: ${OPENTURNS_INCLUDE_DIRS}")
   message (STATUS "OPENTURNS_VERSION: ${OPENTURNS_VERSION}")
   message (STATUS "OPENTURNS_SWIG_INCLUDE_DIR: ${OPENTURNS_SWIG_INCLUDE_DIR}")
   message (STATUS "OPENTURNS_ROOT_DIR: ${OPENTURNS_ROOT_DIR}")
   message (STATUS "OPENTURNS_EXAMPLES_DIR: ${OPENTURNS_EXAMPLES_DIR}")
 endif ()


 # handle REQUIRED and QUIET options
 include (FindPackageHandleStandardArgs)
 find_package_handle_standard_args (OpenTURNS DEFAULT_MSG OPENTURNS_LIBRARY
   OPENTURNS_LIBRARIES
   LIBXML2_FOUND
   PYTHONLIBS_FOUND
   OPENTURNS_INCLUDE_DIR OPENTURNS_INCLUDE_DIRS OPENTURNS_SWIG_INCLUDE_DIR
   OPENTURNS_VERSION _OPENTURNS_VERSION_MATCH
   OPENTURNS_ROOT_DIR
   OPENTURNS_EXAMPLES_DIR
 )
 mark_as_advanced (
   OPENTURNS_LIBRARY
   OPENTURNS_INCLUDE_DIR
   OPENTURNS_SWIG_INCLUDE_DIR
   OPENTURNS_INCLUDE_DIRS
   OPENTURNS_VERSION
   OPENTURNS_LIBRARIES
   OPENTURNS_ROOT_DIR
   OPENTURNS_EXAMPLES_DIR
 )





 # wrapper -----------------------------------------------------------------------


 # threads
 if (NOT Threads_FOUND)
   find_package (Threads ${_FIND_ARG})
 endif ()
 # wrapper definitions
 if (NOT OPENTURNS_WRAPPER_DEFINITIONS)
   set(OPENTURNS_WRAPPER_DEFINITIONS)
   if (CMAKE_USE_PTHREADS_INIT)
     list (APPEND OPENTURNS_WRAPPER_DEFINITIONS -DHAVE_PTHREAD_H)
   endif ()
 endif ()


 # find wrapper dir
 if (NOT OPENTURNS_WRAPPER_DIR)
   find_path (OPENTURNS_WRAPPER_DIR
     NAMES
       wrapper.xml
     PATHS
       ${OPENTURNS_ROOT_DIR}
     PATH_SUFFIXES
       share/openturns/wrappers
     DOC
       "OpenTURNS wrapper location"
   )
 endif ()


 if (NOT OPENTURNS_WRAPPER_LIBRARIES)
   set(OPENTURNS_WRAPPER_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
 endif ()
 # check if wrapper library is usable
 if (NOT OPENTURNS_WRAPPER_FOUND)
   if (Threads_FOUND
         AND CMAKE_USE_PTHREADS_INIT
         AND OPENTURNS_WRAPPER_DEFINITIONS
         AND OPENTURNS_WRAPPER_DIR
         AND OPENTURNS_WRAPPER_LIBRARIES
         AND OPENTURNS_FOUND)
     set (OPENTURNS_WRAPPER_FOUND TRUE)
   else ()
     set (OPENTURNS_WRAPPER_FOUND FALSE)
   endif ()
 endif ()


 mark_as_advanced (
   OPENTURNS_WRAPPER_FOUND
   OPENTURNS_WRAPPER_DIR
   OPENTURNS_WRAPPER_LIBRARIES
   OPENTURNS_WRAPPER_DEFINITIONS
 )




 # module --------------------------------------------------------------


 # find module directory
 if (NOT OPENTURNS_MODULE_DIR)
   set (OPENTURNS_MODULE_DIR "${OPENTURNS_ROOT_DIR}/lib/openturns/module")
 endif ()


 # set module definitions
 if (NOT OPENTURNS_MODULE_DEFINITIONS)
   set (OPENTURNS_MODULE_DEFINITIONS)
   # check for STDC_HEADERS
   if (NOT HAVE_STDLIB_H)
     check_include_file_cxx (stdlib.h HAVE_STDLIB_H)
   endif ()
   if (NOT HAVE_STDARG_H)
     check_include_file_cxx (stdarg.h HAVE_STDARG_H)
   endif ()
   if (NOT HAVE_STRING_H)
     check_include_file_cxx (string.h HAVE_STRING_H)
   endif ()
   if (NOT HAVE_FLOAT_H)
     check_include_file_cxx (float.h HAVE_FLOAT_H)
   endif ()
   check_function_exists (memchr HAVE_MEMCHR)
   if (NOT HAVE_FREE)
     check_function_exists (free HAVE_FREE)
   endif ()
   if (NOT HAVE_CTYPE_H)
     check_include_file_cxx (ctype.h HAVE_CTYPE_H)
   endif ()
   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)
     list (APPEND OPENTURNS_MODULE_DEFINITIONS -DSTDC_HEADERS_H=1)
   else ()
     list (APPEND OPENTURNS_MODULE_DEFINITIONS -DSTDC_HEADERS_H=0)
   endif ()
   # this macro checks a header and defines the corresponding macro
   macro (check_include_file_cxx_define_macro header_file)
     # get macro name from header_file
     string (TOUPPER "${header_file}" macro_name)
     string (REGEX REPLACE "[/.]" "_" macro_name ${macro_name})
     set(macro_name HAVE_${macro_name})
     # check for header
     if (NOT ${macro_name})
       check_include_file_cxx (${header_file} ${macro_name})
     endif ()
     # define macro
     if(${macro_name})
       list (APPEND OPENTURNS_MODULE_DEFINITIONS -D${macro_name}=1)
     else()
       list (APPEND OPENTURNS_MODULE_DEFINITIONS -D${macro_name}=0)
     endif ()
   endmacro ()
   # check for some headers
   check_include_file_cxx_define_macro (sys/types.h)
   check_include_file_cxx_define_macro (sys/stat.h)
   check_include_file_cxx_define_macro (stdlib.h)
   check_include_file_cxx_define_macro (string.h)
   check_include_file_cxx_define_macro (memory.h)
   check_include_file_cxx_define_macro (strings.h)
   check_include_file_cxx_define_macro (inttypes.h)
   check_include_file_cxx_define_macro (stdint.h)
   check_include_file_cxx_define_macro (unistd.h)
   check_include_file_cxx_define_macro (dlfcn.h)
   check_include_file_cxx_define_macro (stdbool.h)
   check_include_file_cxx_define_macro (regex.h)
 endif ()


 mark_as_advanced (
   OPENTURNS_MODULE_DIR
   OPENTURNS_MODULE_DEFINITIONS
 )


 # add module defs
 macro (add_module_extra_definitions module_name)
   add_definitions (-DPACKAGE_NAME="OpenTURNS module ${module_name}")
   add_definitions (-DPACKAGE_TARNAME="${module_name}")
   add_definitions (-DPACKAGE_VERSION="${OPENTURNS_VERSION}")
   add_definitions (-DPACKAGE_STRING="OpenTURNS module ${module_name} ${OPENTURNS_VERSION}")
   add_definitions (-DPACKAGE_BUGREPORT="")
 endmacro ()




 # modules ----------------------------------------------------------------------
 # find modules
 if (OpenTURNS_FIND_COMPONENTS)
   foreach (module_name ${OpenTURNS_FIND_COMPONENTS})
     string(TOLOWER ${module_name} module_lowercase_name)
     string(TOUPPER ${module_name} module_uppercase_name)
     set (OPENTURNS_${module_uppercase_name}_FOUND FALSE)
     # module library
     if (NOT OPENTURNS_${module_uppercase_name}_LIBRARY)
       find_library (OPENTURNS_${module_uppercase_name}_LIBRARY
         NAMES
           ${module_name}
         PATHS
           ${OPENTURNS_MODULE_DIR}/lib
         PATH_SUFFIXES
           ${module_lowercase_name}
       )
     endif ()
     # module libraries
     if (NOT OPENTURNS_${module_uppercase_name}_LIBRARIES)
       set (OPENTURNS_${module_uppercase_name}_LIBRARIES ${OPENTURNS_${module_uppercase_name}_LIBRARY})
       list (APPEND OPENTURNS_${module_uppercase_name}_LIBRARIES ${OPENTURNS_LIBRARIES})
     endif ()
     # module include dir
     if (NOT OPENTURNS_${module_uppercase_name}_INCLUDE_DIR)
       set (OPENTURNS_${module_uppercase_name}_INCLUDE_DIR "${OPENTURNS_MODULE_DIR}/include/${module_lowercase_name}")
     endif ()
     # module include dirs
     if (NOT OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS)
       set (OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS ${OPENTURNS_${module_uppercase_name}_INCLUDE_DIR})
       list (APPEND OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS ${OPENTURNS_INCLUDE_DIRS})
     endif ()
     # module swig include dir
     if (NOT OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR)
       set (OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR "${OPENTURNS_MODULE_DIR}/share/${module_lowercase_name}/swig")
     endif ()
     # test if the module is found
     if (NOT OPENTURNS_${module_uppercase_name}_FOUND)
       if (OPENTURNS_${module_uppercase_name}_LIBRARY
             AND OPENTURNS_${module_uppercase_name}_LIBRARIES
             AND OPENTURNS_${module_uppercase_name}_INCLUDE_DIR
             AND OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS
             AND OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR
             AND OPENTURNS_FOUND)
         set (OPENTURNS_${module_uppercase_name}_FOUND TRUE)
       else ()
         set (OPENTURNS_${module_uppercase_name}_FOUND FALSE)
       endif ()
     endif ()
     # handle REQUIRED and QUIET options
     if (OPENTURNS_${module_uppercase_name}_FOUND)
       if (NOT OpenTURNS_FIND_QUIETLY)
         message (STATUS "Found OpenTURNS module ${module_name}: ${OPENTURNS_${module_uppercase_name}_LIBRARY}")
       endif ()
     else ()
       if (OpenTURNS_FIND_REQUIRED)
         message(SEND_ERROR "Unable to find the requested OpenTURNS module : ${module_name}")
       endif ()
       if (NOT OpenTURNS_FIND_QUIETLY)
         message (STATUS "Could not find OpenTURNS module ${module_name}")
       endif ()
     endif ()
     mark_as_advanced (
       OPENTURNS_${module_uppercase_name}_FOUND
       OPENTURNS_${module_uppercase_name}_LIBRARY
       OPENTURNS_${module_uppercase_name}_LIBRARIES
       OPENTURNS_${module_uppercase_name}_INCLUDE_DIR
       OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS
       OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR
     )
   endforeach ()
 endif ()




 # debug ------------------------------------------------------------------------------------------
 if (OPENTURNS_DEBUG)
   message (STATUS "OPENTURNS_FOUND: ${OPENTURNS_FOUND}")
   message (STATUS "OPENTURNS_WRAPPER_FOUND: ${OPENTURNS_WRAPPER_FOUND}")
   message (STATUS "OPENTURNS_WRAPPER_DIR: ${OPENTURNS_WRAPPER_DIR}")
   message (STATUS "OPENTURNS_WRAPPER_DEFINITIONS: ${OPENTURNS_WRAPPER_DEFINITIONS}")
   message (STATUS "OPENTURNS_WRAPPER_LIBRARIES: ${OPENTURNS_WRAPPER_LIBRARIES}")
   message (STATUS "OPENTURNS_MODULE_DIR: ${OPENTURNS_MODULE_DIR}")
   message (STATUS "OPENTURNS_MODULE_DEFINITIONS: ${OPENTURNS_MODULE_DEFINITIONS}")
   foreach (module_name ${OpenTURNS_FIND_COMPONENTS})
     message (STATUS "OPENTURNS_${module_uppercase_name}_FOUND: ${OPENTURNS_${module_uppercase_name}_FOUND}")
     message (STATUS "OPENTURNS_${module_uppercase_name}_LIBRARY: ${OPENTURNS_${module_uppercase_name}_LIBRARY}")
     message (STATUS "OPENTURNS_${module_uppercase_name}_LIBRARIES: ${OPENTURNS_${module_uppercase_name}_LIBRARIES}")
     message (STATUS "OPENTURNS_${module_uppercase_name}_INCLUDE_DIR: ${OPENTURNS_${module_uppercase_name}_INCLUDE_DIR}")
     message (STATUS "OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS: ${OPENTURNS_${module_uppercase_name}_INCLUDE_DIRS}")
     message (STATUS "OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR: ${OPENTURNS_${module_uppercase_name}_SWIG_INCLUDE_DIR}")
   endforeach ()
 endif ()

Back



CMake: [Welcome | Site Map]