FindArmadillo.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindArmadillo
  5. -------------
  6. Find the Armadillo C++ library.
  7. Armadillo is library for linear algebra & scientific computing.
  8. Using Armadillo:
  9. ::
  10. find_package(Armadillo REQUIRED)
  11. include_directories(${ARMADILLO_INCLUDE_DIRS})
  12. add_executable(foo foo.cc)
  13. target_link_libraries(foo ${ARMADILLO_LIBRARIES})
  14. This module sets the following variables:
  15. ::
  16. ARMADILLO_FOUND - set to true if the library is found
  17. ARMADILLO_INCLUDE_DIRS - list of required include directories
  18. ARMADILLO_LIBRARIES - list of libraries to be linked
  19. ARMADILLO_VERSION_MAJOR - major version number
  20. ARMADILLO_VERSION_MINOR - minor version number
  21. ARMADILLO_VERSION_PATCH - patch version number
  22. ARMADILLO_VERSION_STRING - version number as a string (ex: "1.0.4")
  23. ARMADILLO_VERSION_NAME - name of the version (ex: "Antipodean Antileech")
  24. #]=======================================================================]
  25. # UNIX paths are standard, no need to write.
  26. find_library(ARMADILLO_LIBRARY
  27. NAMES armadillo
  28. PATHS "$ENV{ProgramFiles}/Armadillo/lib" "$ENV{ProgramFiles}/Armadillo/lib64" "$ENV{ProgramFiles}/Armadillo"
  29. )
  30. find_path(ARMADILLO_INCLUDE_DIR
  31. NAMES armadillo
  32. PATHS "$ENV{ProgramFiles}/Armadillo/include"
  33. )
  34. if(ARMADILLO_INCLUDE_DIR)
  35. # ------------------------------------------------------------------------
  36. # Extract version information from <armadillo>
  37. # ------------------------------------------------------------------------
  38. # WARNING: Early releases of Armadillo didn't have the arma_version.hpp file.
  39. # (e.g. v.0.9.8-1 in ubuntu maverick packages (2001-03-15))
  40. # If the file is missing, set all values to 0
  41. set(ARMADILLO_VERSION_MAJOR 0)
  42. set(ARMADILLO_VERSION_MINOR 0)
  43. set(ARMADILLO_VERSION_PATCH 0)
  44. set(ARMADILLO_VERSION_NAME "EARLY RELEASE")
  45. if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp")
  46. # Read and parse armdillo version header file for version number
  47. file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _armadillo_HEADER_CONTENTS REGEX "#define ARMA_VERSION_[A-Z]+ ")
  48. string(REGEX REPLACE ".*#define ARMA_VERSION_MAJOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MAJOR "${_armadillo_HEADER_CONTENTS}")
  49. string(REGEX REPLACE ".*#define ARMA_VERSION_MINOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MINOR "${_armadillo_HEADER_CONTENTS}")
  50. string(REGEX REPLACE ".*#define ARMA_VERSION_PATCH ([0-9]+).*" "\\1" ARMADILLO_VERSION_PATCH "${_armadillo_HEADER_CONTENTS}")
  51. # WARNING: The number of spaces before the version name is not one.
  52. string(REGEX REPLACE ".*#define ARMA_VERSION_NAME +\"([0-9a-zA-Z _-]+)\".*" "\\1" ARMADILLO_VERSION_NAME "${_armadillo_HEADER_CONTENTS}")
  53. unset(_armadillo_HEADER_CONTENTS)
  54. endif()
  55. set(ARMADILLO_VERSION_STRING "${ARMADILLO_VERSION_MAJOR}.${ARMADILLO_VERSION_MINOR}.${ARMADILLO_VERSION_PATCH}")
  56. endif ()
  57. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  58. find_package_handle_standard_args(Armadillo
  59. REQUIRED_VARS ARMADILLO_LIBRARY ARMADILLO_INCLUDE_DIR
  60. VERSION_VAR ARMADILLO_VERSION_STRING)
  61. # version_var fails with cmake < 2.8.4.
  62. if (ARMADILLO_FOUND)
  63. set(ARMADILLO_INCLUDE_DIRS ${ARMADILLO_INCLUDE_DIR})
  64. set(ARMADILLO_LIBRARIES ${ARMADILLO_LIBRARY})
  65. endif ()
  66. # Hide internal variables
  67. mark_as_advanced(
  68. ARMADILLO_INCLUDE_DIR
  69. ARMADILLO_LIBRARY)