FindArmadillo.cmake 3.41 KB
Newer Older
1 2 3
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

4 5 6 7 8 9
#.rst:
# FindArmadillo
# -------------
#
# Find Armadillo
#
10 11
# Find the Armadillo C++ library
#
12
# Using Armadillo:
13 14 15 16 17 18 19 20
#
# ::
#
#   find_package(Armadillo REQUIRED)
#   include_directories(${ARMADILLO_INCLUDE_DIRS})
#   add_executable(foo foo.cc)
#   target_link_libraries(foo ${ARMADILLO_LIBRARIES})
#
Clement Creusot's avatar
Clement Creusot committed
21
# This module sets the following variables:
22 23 24 25 26 27 28 29 30 31 32
#
# ::
#
#   ARMADILLO_FOUND - set to true if the library is found
#   ARMADILLO_INCLUDE_DIRS - list of required include directories
#   ARMADILLO_LIBRARIES - list of libraries to be linked
#   ARMADILLO_VERSION_MAJOR - major version number
#   ARMADILLO_VERSION_MINOR - minor version number
#   ARMADILLO_VERSION_PATCH - patch version number
#   ARMADILLO_VERSION_STRING - version number as a string (ex: "1.0.4")
#   ARMADILLO_VERSION_NAME - name of the version (ex: "Antipodean Antileech")
33

Clement Creusot's avatar
Clement Creusot committed
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
# UNIX paths are standard, no need to write.
find_library(ARMADILLO_LIBRARY
  NAMES armadillo
  PATHS "$ENV{ProgramFiles}/Armadillo/lib"  "$ENV{ProgramFiles}/Armadillo/lib64" "$ENV{ProgramFiles}/Armadillo"
  )
find_path(ARMADILLO_INCLUDE_DIR
  NAMES armadillo
  PATHS "$ENV{ProgramFiles}/Armadillo/include"
  )


if(ARMADILLO_INCLUDE_DIR)

  # ------------------------------------------------------------------------
  #  Extract version information from <armadillo>
  # ------------------------------------------------------------------------

  # WARNING: Early releases of Armadillo didn't have the arma_version.hpp file.
  # (e.g. v.0.9.8-1 in ubuntu maverick packages (2001-03-15))
  # If the file is missing, set all values to 0
  set(ARMADILLO_VERSION_MAJOR 0)
  set(ARMADILLO_VERSION_MINOR 0)
  set(ARMADILLO_VERSION_PATCH 0)
  set(ARMADILLO_VERSION_NAME "EARLY RELEASE")

  if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp")

    # Read and parse armdillo version header file for version number
62
    file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _armadillo_HEADER_CONTENTS REGEX "#define ARMA_VERSION_[A-Z]+ ")
Clement Creusot's avatar
Clement Creusot committed
63 64 65 66 67
    string(REGEX REPLACE ".*#define ARMA_VERSION_MAJOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MAJOR "${_armadillo_HEADER_CONTENTS}")
    string(REGEX REPLACE ".*#define ARMA_VERSION_MINOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MINOR "${_armadillo_HEADER_CONTENTS}")
    string(REGEX REPLACE ".*#define ARMA_VERSION_PATCH ([0-9]+).*" "\\1" ARMADILLO_VERSION_PATCH "${_armadillo_HEADER_CONTENTS}")

    # WARNING: The number of spaces before the version name is not one.
68
    string(REGEX REPLACE ".*#define ARMA_VERSION_NAME +\"([0-9a-zA-Z _-]+)\".*" "\\1" ARMADILLO_VERSION_NAME "${_armadillo_HEADER_CONTENTS}")
Clement Creusot's avatar
Clement Creusot committed
69

70
    unset(_armadillo_HEADER_CONTENTS)
71
  endif()
Clement Creusot's avatar
Clement Creusot committed
72 73

  set(ARMADILLO_VERSION_STRING "${ARMADILLO_VERSION_MAJOR}.${ARMADILLO_VERSION_MINOR}.${ARMADILLO_VERSION_PATCH}")
74
endif ()
Clement Creusot's avatar
Clement Creusot committed
75 76 77 78

#======================


Rolf Eike Beer's avatar
Rolf Eike Beer committed
79
# Checks 'REQUIRED', 'QUIET' and versions.
80
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
Clement Creusot's avatar
Clement Creusot committed
81 82 83 84 85 86 87 88
find_package_handle_standard_args(Armadillo
  REQUIRED_VARS ARMADILLO_LIBRARY ARMADILLO_INCLUDE_DIR
  VERSION_VAR ARMADILLO_VERSION_STRING)
# version_var fails with cmake < 2.8.4.

if (ARMADILLO_FOUND)
  set(ARMADILLO_INCLUDE_DIRS ${ARMADILLO_INCLUDE_DIR})
  set(ARMADILLO_LIBRARIES ${ARMADILLO_LIBRARY})
89
endif ()
Clement Creusot's avatar
Clement Creusot committed
90 91 92 93 94 95 96 97


# Hide internal variables
mark_as_advanced(
  ARMADILLO_INCLUDE_DIR
  ARMADILLO_LIBRARY)

#======================