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,
    #  Risks’N Statistics in a structured industrial approach,
    #  available at http://www.openturns.org/
    #
    #  ---------------------------------------------------------------------
     #
     #
     #  -- Library usage example :
     #  -- Library usage example :
Line 31: Line 37:
     #  ---------------------------------------------------------------------
     #  ---------------------------------------------------------------------
     #
     #
     #  This module defines :
     #  -- This module defines :
     #
     #
     #  OpenTURNS_FOUND - OpenTURNS is usable as a library
     #  OpenTURNS_FOUND - OpenTURNS is usable as a library
Line 56: Line 62:
     #  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 to use the module
     # MUST be called to use the module
    #
     #
     #
     #  ---------------------------------------------------------------------
     #  ---------------------------------------------------------------------

Revision as of 14:21, 2 March 2010

Back


File:FindOpenTURNS.cmake


   #  -- 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_module_extra_definitions (Trapezoidal)
   #     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
   #  OpenTURNS_INCLUDE_DIRS - dependencies include directories
   #  OpenTURNS_SWIG_INCLUDE_DIR - Include directory to swig (.i) interface
   #  OpenTURNS_VERSION - Version string
   #  OpenTURNS_LIBRARY - Where to find the library
   #  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 to use the module
   #
   #  ---------------------------------------------------------------------
   #
   #  Copyright (c) 2009 Mathieu Lapointe <lapointe@phimeca.com>
   #  Copyright (c) 2010 Julien Schueller <schueller@phimeca.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
   if (OpenTURNS_FIND_QUIETLY)
     set (_FIND_ARG QUIET)
   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
         /usr/include
         /usr/local/include
         /opt/local/include
         /sw/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)
     set (OpenTURNS_INCLUDE_DIRS ${OpenTURNS_INCLUDE_DIR})
     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
         /usr/lib
         /usr/local/lib
         /opt
         /opt/lib
         /opt/local/lib
         /sw/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)
     string (REGEX REPLACE "(.*)/[a-z]+/[a-z]+/?" "\\1" OpenTURNS_ROOT_DIR "${OpenTURNS_INCLUDE_DIR}")
   endif ()
   
   
   # examples dir
   if (NOT OpenTURNS_EXAMPLES_DIR)
     set (OpenTURNS_EXAMPLES_DIR "${OpenTURNS_ROOT_DIR}/share/openturns/examples")
   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
   )
   # find_package_handle_standard_args sets OPENTURNS_FOUND :[
   set (OpenTURNS_FOUND ${OPENTURNS_FOUND})
   
   
   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 QUIET)
   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 wrapper.dtd
       PATHS
         "${OpenTURNS_ROOT_DIR}"
         /usr/lib
         /usr/local/lib
         /opt/lib
         /opt
       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)
       set (OpenTURNS_${module_name}_FOUND FALSE)
   
       # module library
       if (NOT OpenTURNS_${module_name}_LIBRARY)
         find_library (OpenTURNS_${module_name}_LIBRARY
           NAMES
             ${module_name}
           PATHS
             ${OpenTURNS_Module_DIR}/lib
           PATH_SUFFIXES
             ${module_lowercase_name}
         )
       endif ()
   
       # module libraries
       if (NOT OpenTURNS_${module_name}_LIBRARIES)
         set (OpenTURNS_${module_name}_LIBRARIES ${OpenTURNS_${module_name}_LIBRARY})
         list (APPEND OpenTURNS_${module_name}_LIBRARIES ${OpenTURNS_LIBRARIES})
       endif ()
   
       # module inlude
       if (NOT OpenTURNS_${module_name}_INCLUDE_DIR)
         set (OpenTURNS_${module_name}_INCLUDE_DIR "${OpenTURNS_Module_DIR}/include/${module_lowercase_name}")
       endif ()
   
       # module include dirs
       if (NOT OpenTURNS_${module_name}_INCLUDE_DIRS)
         set (OpenTURNS_${module_name}_INCLUDE_DIRS ${OpenTURNS_${module_name}_INCLUDE_DIR})
         list (APPEND OpenTURNS_${module_name}_INCLUDE_DIRS ${OpenTURNS_INCLUDE_DIRS})
       endif ()
   
       # module swig inlude
       if (NOT OpenTURNS_${module_name}_SWIG_INCLUDE_DIR)
         set (OpenTURNS_${module_name}_SWIG_INCLUDE_DIR "${OpenTURNS_Module_DIR}/share/${module_lowercase_name}/swig")
       endif ()
   
       # test if the module is found
       if (NOT OpenTURNS_${module_name}_FOUND)
         if (OpenTURNS_${module_name}_LIBRARY
               AND OpenTURNS_${module_name}_LIBRARIES
               AND OpenTURNS_${module_name}_INCLUDE_DIR 
               AND OpenTURNS_${module_name}_INCLUDE_DIRS
               AND OpenTURNS_${module_name}_SWIG_INCLUDE_DIR
               AND OpenTURNS_FOUND)
           set (OpenTURNS_${module_name}_FOUND TRUE)
         else ()
           set (OpenTURNS_${module_name}_FOUND FALSE)
         endif ()
       endif ()
   
       # handle REQUIRED and QUIET options
       if (OpenTURNS_${module_name}_FOUND)
         if (NOT OpenTURNS_FIND_QUIETLY)
           message (STATUS "Found OpenTURNS module ${module_name}: ${OpenTURNS_${module_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_name}_FOUND
         OpenTURNS_${module_name}_LIBRARY
         OpenTURNS_${module_name}_LIBRARIES
         OpenTURNS_${module_name}_INCLUDE_DIR 
         OpenTURNS_${module_name}_INCLUDE_DIRS
         OpenTURNS_${module_name}_SWIG_INCLUDE_DIR
       )
   
     endforeach ()
   endif ()
   
   
   
   
   
   
   # debug ------------------------------------------------------------------------------------------
   
   if (OpenTURNS_DEBUG)
     message (STATUS "OpenTURNS_FOUND: ${OpenTURNS_FOUND}")
     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}")
   
     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_name}_FOUND: ${OpenTURNS_${module_name}_FOUND}")
       message (STATUS "OpenTURNS_${module_name}_LIBRARY: ${OpenTURNS_${module_name}_LIBRARY}")
       message (STATUS "OpenTURNS_${module_name}_LIBRARIES: ${OpenTURNS_${module_name}_LIBRARIES}")
       message (STATUS "OpenTURNS_${module_name}_INCLUDE_DIR: ${OpenTURNS_${module_name}_INCLUDE_DIR}")
       message (STATUS "OpenTURNS_${module_name}_INCLUDE_DIRS: ${OpenTURNS_${module_name}_INCLUDE_DIRS}")
       message (STATUS "OpenTURNS_${module_name}_SWIG_INCLUDE_DIR: ${OpenTURNS_${module_name}_SWIG_INCLUDE_DIR}")
     endforeach ()
   endif ()

Back



CMake: [Welcome | Site Map]