LofarFindPackage.cmake 4.64 KB
Newer Older
1
# - Wrapper script around the find_package() command.
2
#
3 4 5 6 7 8
# lofar_find_package() finds a package like find_package() does. It uses the
# LOFAR search path to locate the package, unless the package's root directory
# <PKG>_ROOT_DIR is defined.
#
# Furthermore:
#  Add preprocessor definitions that are defined in <PKG>_DEFINITIONS.
9
#  Add include directories that are defined <PKG>_INCLUDE_DIR[S].
10 11 12 13 14 15 16
#  Add <PKG>_LIBRARIES to the list of LOFAR_EXTRA_LIBRARIES, needed for
#  linking.
#  Add cache variable HAVE_<PKG> that indicates whether the package was found;
#  it can be used with #cmakedefine.
# Note: <PKG> equals <package> in uppercase.

#  Copyright (C) 2008-2010
17
#  ASTRON (Netherlands Foundation for Research in Astronomy)
18
#  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, softwaresupport@astron.nl
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#  $Id$

36
include(LofarMacros)
37 38 39 40 41 42 43

function(lofar_find_package _package)

  string(TOLOWER ${_package} _pkg)
  string(TOUPPER ${_package} _PKG)

  if(NOT ${_PKG}_FOUND)
44 45 46 47 48 49 50 51
    # Set CMAKE_PREFIX_PATH, used by the find_xxx() commands, to the package's
    # root directory ${_PKG}_ROOT_DIR, if defined; otherwise set it to the
    # LOFAR search path.
    if(${_PKG}_ROOT_DIR)
      set(CMAKE_PREFIX_PATH ${${_PKG}_ROOT_DIR})
    else(${_PKG}_ROOT_DIR)
      lofar_search_path(CMAKE_PREFIX_PATH ${_pkg})
    endif(${_PKG}_ROOT_DIR)
52

53 54 55 56 57 58 59 60 61 62 63 64 65
    list(FIND ARGV REQUIRED is_required)

    IF(BUILD_DOCUMENTATION)
      IF(is_required GREATER -1)
          # Removing REQUIRED option while looking for package.
          # This allows cmake to continue configuring so you could make the doc,
          # but building the code might not be possible.
          # In case the package is not found, a WARNING is issued below.
          list(REMOVE_ITEM ARGV REQUIRED)
          list(REMOVE_ITEM ARGN REQUIRED)
      ENDIF()
    ENDIF(BUILD_DOCUMENTATION)

66 67 68 69 70 71 72 73 74
    # Search the package using the Find${_package}.cmake module, unless the
    # package have been disabled explicitly.
    if(NOT DEFINED USE_${_PKG} OR USE_${_PKG})
      if(LOFAR_VERBOSE_CONFIGURE)
        find_package(${ARGV})
      else(LOFAR_VERBOSE_CONFIGURE)
        find_package(${ARGV} QUIET)
      endif(LOFAR_VERBOSE_CONFIGURE)
    else(NOT DEFINED USE_${_PKG} OR USE_${_PKG})
75
      if(is_required GREATER -1)
76 77 78
        IF(NOT BUILD_DOCUMENTATION)
          message(SEND_ERROR "Package ${_package} is required, but has been disabled explicitly!")
        ENDIF(NOT BUILD_DOCUMENTATION)
79 80
      else(is_required GREATER -1)
        message(STATUS "Package ${_package} has been disabled explicitly")
81
      endif(is_required GREATER -1)
82
    endif(NOT DEFINED USE_${_PKG} OR USE_${_PKG})
83

84 85
    # Add include directories and libraries, if package was found;
    # set HAVE_<PACKAGE> variable in the cache.
86
    if(${_PKG}_FOUND)
87 88 89
      if(NOT DEFINED HAVE_${_PKG})
        set(HAVE_${_PKG} TRUE CACHE INTERNAL "Have ${_package}?")
      endif(NOT DEFINED HAVE_${_PKG})
Marcel Loose's avatar
Marcel Loose committed
90
      add_definitions(${${_PKG}_DEFINITIONS})
91
      if(${_PKG}_INCLUDE_DIRS)
92
        include_directories(SYSTEM ${${_PKG}_INCLUDE_DIRS})
93
        set(${_PKG}_INCLUDE_DIRS ${${_PKG}_INCLUDE_DIRS} PARENT_SCOPE)
94
      else(${_PKG}_INCLUDE_DIRS)
95
        include_directories(SYSTEM ${${_PKG}_INCLUDE_DIR})
96
        set(${_PKG}_INCLUDE_DIR ${${_PKG}_INCLUDE_DIR} PARENT_SCOPE)
97
      endif(${_PKG}_INCLUDE_DIRS)
98
      set(${_PKG}_LIBRARIES ${${_PKG}_LIBRARIES} PARENT_SCOPE)
99 100
      set(LOFAR_EXTRA_LIBRARIES ${LOFAR_EXTRA_LIBRARIES} ${${_PKG}_LIBRARIES}
        PARENT_SCOPE)
101 102
    else(${_PKG}_FOUND)
      set(HAVE_${_PKG} FALSE CACHE INTERNAL "Have ${_package}?")
103 104 105
      if(is_required GREATER -1)
          message(WARNING "Removed REQUIRED option while looking for package '${_package}' because BUILD_DOCUMENTATION=${BUILD_DOCUMENTATION}. This allows cmake to continue configuring so you could make the doc, but building the code might not be possible.")
      endif(is_required GREATER -1)
106
    endif(${_PKG}_FOUND)
107
    set(${_PKG}_FOUND ${${_PKG}_FOUND} PARENT_SCOPE)
108 109 110 111

  endif(NOT ${_PKG}_FOUND)

endfunction(lofar_find_package _package)