FindArmadillo.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #.rst:
  2. # FindArmadillo
  3. # -------------
  4. #
  5. # Find Armadillo
  6. #
  7. # Find the Armadillo C++ library
  8. #
  9. # Using Armadillo:
  10. #
  11. # ::
  12. #
  13. # find_package(Armadillo REQUIRED)
  14. # include_directories(${ARMADILLO_INCLUDE_DIRS})
  15. # add_executable(foo foo.cc)
  16. # target_link_libraries(foo ${ARMADILLO_LIBRARIES})
  17. #
  18. # This module sets the following variables:
  19. #
  20. # ::
  21. #
  22. # ARMADILLO_FOUND - set to true if the library is found
  23. # ARMADILLO_INCLUDE_DIRS - list of required include directories
  24. # ARMADILLO_LIBRARIES - list of libraries to be linked
  25. # ARMADILLO_VERSION_MAJOR - major version number
  26. # ARMADILLO_VERSION_MINOR - minor version number
  27. # ARMADILLO_VERSION_PATCH - patch version number
  28. # ARMADILLO_VERSION_STRING - version number as a string (ex: "1.0.4")
  29. # ARMADILLO_VERSION_NAME - name of the version (ex: "Antipodean Antileech")
  30. #=============================================================================
  31. # Copyright 2011 Clement Creusot <creusot@cs.york.ac.uk>
  32. #
  33. # Distributed under the OSI-approved BSD License (the "License");
  34. # see accompanying file Copyright.txt for details.
  35. #
  36. # This software is distributed WITHOUT ANY WARRANTY; without even the
  37. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  38. # See the License for more information.
  39. #=============================================================================
  40. # (To distribute this file outside of CMake, substitute the full
  41. # License text for the above reference.)
  42. # UNIX paths are standard, no need to write.
  43. find_library(ARMADILLO_LIBRARY
  44. NAMES armadillo
  45. PATHS "$ENV{ProgramFiles}/Armadillo/lib" "$ENV{ProgramFiles}/Armadillo/lib64" "$ENV{ProgramFiles}/Armadillo"
  46. )
  47. find_path(ARMADILLO_INCLUDE_DIR
  48. NAMES armadillo
  49. PATHS "$ENV{ProgramFiles}/Armadillo/include"
  50. )
  51. if(ARMADILLO_INCLUDE_DIR)
  52. # ------------------------------------------------------------------------
  53. # Extract version information from <armadillo>
  54. # ------------------------------------------------------------------------
  55. # WARNING: Early releases of Armadillo didn't have the arma_version.hpp file.
  56. # (e.g. v.0.9.8-1 in ubuntu maverick packages (2001-03-15))
  57. # If the file is missing, set all values to 0
  58. set(ARMADILLO_VERSION_MAJOR 0)
  59. set(ARMADILLO_VERSION_MINOR 0)
  60. set(ARMADILLO_VERSION_PATCH 0)
  61. set(ARMADILLO_VERSION_NAME "EARLY RELEASE")
  62. if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp")
  63. # Read and parse armdillo version header file for version number
  64. file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _armadillo_HEADER_CONTENTS REGEX "#define ARMA_VERSION_[A-Z]+ ")
  65. string(REGEX REPLACE ".*#define ARMA_VERSION_MAJOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MAJOR "${_armadillo_HEADER_CONTENTS}")
  66. string(REGEX REPLACE ".*#define ARMA_VERSION_MINOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MINOR "${_armadillo_HEADER_CONTENTS}")
  67. string(REGEX REPLACE ".*#define ARMA_VERSION_PATCH ([0-9]+).*" "\\1" ARMADILLO_VERSION_PATCH "${_armadillo_HEADER_CONTENTS}")
  68. # WARNING: The number of spaces before the version name is not one.
  69. string(REGEX REPLACE ".*#define ARMA_VERSION_NAME +\"([0-9a-zA-Z _-]+)\".*" "\\1" ARMADILLO_VERSION_NAME "${_armadillo_HEADER_CONTENTS}")
  70. unset(_armadillo_HEADER_CONTENTS)
  71. endif()
  72. set(ARMADILLO_VERSION_STRING "${ARMADILLO_VERSION_MAJOR}.${ARMADILLO_VERSION_MINOR}.${ARMADILLO_VERSION_PATCH}")
  73. endif ()
  74. #======================
  75. # Checks 'REQUIRED', 'QUIET' and versions.
  76. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  77. find_package_handle_standard_args(Armadillo
  78. REQUIRED_VARS ARMADILLO_LIBRARY ARMADILLO_INCLUDE_DIR
  79. VERSION_VAR ARMADILLO_VERSION_STRING)
  80. # version_var fails with cmake < 2.8.4.
  81. if (ARMADILLO_FOUND)
  82. set(ARMADILLO_INCLUDE_DIRS ${ARMADILLO_INCLUDE_DIR})
  83. set(ARMADILLO_LIBRARIES ${ARMADILLO_LIBRARY})
  84. endif ()
  85. # Hide internal variables
  86. mark_as_advanced(
  87. ARMADILLO_INCLUDE_DIR
  88. ARMADILLO_LIBRARY)
  89. #======================