summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Birmingham <birm@rbirm.us>2020-03-03 02:40:24 (GMT)
committerBrad King <brad.king@kitware.com>2020-03-06 16:29:21 (GMT)
commit38c6dd7b1982b4af8e59e136d267a52de1851a3d (patch)
treeca9c51eafa5b99d074a003450f34e0d774007df1
parent6e9eaca24f86500c10e0f5d7399d04deb009a2b4 (diff)
downloadCMake-38c6dd7b1982b4af8e59e136d267a52de1851a3d.zip
CMake-38c6dd7b1982b4af8e59e136d267a52de1851a3d.tar.gz
CMake-38c6dd7b1982b4af8e59e136d267a52de1851a3d.tar.bz2
FindArmadillo: Add support for non-wrapper case
Armadillo is typically built as a wrapper library, which is what this find module has historically supported, but it does not have to be. If not, then instead of armadillo itself, we need to link to some combination of dependencies and not armadillo.
-rw-r--r--Modules/FindArmadillo.cmake83
1 files changed, 62 insertions, 21 deletions
diff --git a/Modules/FindArmadillo.cmake b/Modules/FindArmadillo.cmake
index c4e55ce..243b9e0 100644
--- a/Modules/FindArmadillo.cmake
+++ b/Modules/FindArmadillo.cmake
@@ -6,7 +6,7 @@ FindArmadillo
-------------
Find the Armadillo C++ library.
-Armadillo is library for linear algebra & scientific computing.
+Armadillo is a library for linear algebra & scientific computing.
Using Armadillo:
@@ -31,19 +31,13 @@ This module sets the following variables:
ARMADILLO_VERSION_NAME - name of the version (ex: "Antipodean Antileech")
#]=======================================================================]
-# 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"
)
-
+mark_as_advanced(ARMADILLO_INCLUDE_DIR)
if(ARMADILLO_INCLUDE_DIR)
-
# ------------------------------------------------------------------------
# Extract version information from <armadillo>
# ------------------------------------------------------------------------
@@ -59,32 +53,79 @@ if(ARMADILLO_INCLUDE_DIR)
if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp")
# Read and parse armdillo version header file for version number
- file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _armadillo_HEADER_CONTENTS REGEX "#define ARMA_VERSION_[A-Z]+ ")
- 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}")
+ file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _ARMA_HEADER_CONTENTS REGEX "#define ARMA_VERSION_[A-Z]+ ")
+ string(REGEX REPLACE ".*#define ARMA_VERSION_MAJOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MAJOR "${_ARMA_HEADER_CONTENTS}")
+ string(REGEX REPLACE ".*#define ARMA_VERSION_MINOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MINOR "${_ARMA_HEADER_CONTENTS}")
+ string(REGEX REPLACE ".*#define ARMA_VERSION_PATCH ([0-9]+).*" "\\1" ARMADILLO_VERSION_PATCH "${_ARMA_HEADER_CONTENTS}")
# WARNING: The number of spaces before the version name is not one.
- string(REGEX REPLACE ".*#define ARMA_VERSION_NAME +\"([0-9a-zA-Z _-]+)\".*" "\\1" ARMADILLO_VERSION_NAME "${_armadillo_HEADER_CONTENTS}")
+ string(REGEX REPLACE ".*#define ARMA_VERSION_NAME\ +\"([0-9a-zA-Z\ _-]+)\".*" "\\1" ARMADILLO_VERSION_NAME "${_ARMA_HEADER_CONTENTS}")
- unset(_armadillo_HEADER_CONTENTS)
endif()
set(ARMADILLO_VERSION_STRING "${ARMADILLO_VERSION_MAJOR}.${ARMADILLO_VERSION_MINOR}.${ARMADILLO_VERSION_PATCH}")
endif ()
+if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp")
+ file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp" _ARMA_CONFIG_CONTENTS REGEX "^#define ARMA_USE_[A-Z]+")
+ string(REGEX MATCH "ARMA_USE_WRAPPER" _ARMA_USE_WRAPPER "${_ARMA_CONFIG_CONTENTS}")
+ string(REGEX MATCH "ARMA_USE_LAPACK" _ARMA_USE_LAPACK "${_ARMA_CONFIG_CONTENTS}")
+ string(REGEX MATCH "ARMA_USE_BLAS" _ARMA_USE_BLAS "${_ARMA_CONFIG_CONTENTS}")
+ string(REGEX MATCH "ARMA_USE_ARPACK" _ARMA_USE_ARPACK "${_ARMA_CONFIG_CONTENTS}")
+ string(REGEX MATCH "ARMA_USE_HDF5" _ARMA_USE_HDF5 "${_ARMA_CONFIG_CONTENTS}")
+endif()
+
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+# If _ARMA_USE_WRAPPER is set, then we just link to armadillo, but if it's not then we need support libraries instead
+set(_ARMA_SUPPORT_LIBRARIES)
+
+if(_ARMA_USE_WRAPPER)
+ # Link to the armadillo wrapper library.
+ find_library(ARMADILLO_LIBRARY
+ NAMES armadillo
+ PATHS
+ "$ENV{ProgramFiles}/Armadillo/lib"
+ "$ENV{ProgramFiles}/Armadillo/lib64"
+ "$ENV{ProgramFiles}/Armadillo"
+ )
+ mark_as_advanced(ARMADILLO_LIBRARY)
+ set(_ARMA_REQUIRED_VARS ARMADILLO_LIBRARY)
+else()
+ # Link directly to individual components.
+ set(ARMADILLO_LIBRARY "")
+ foreach(pkg
+ LAPACK
+ BLAS
+ ARPACK
+ HDF5
+ )
+ if(_ARMA_USE_${pkg})
+ find_package(${pkg} QUIET)
+ list(APPEND _ARMA_REQUIRED_VARS "${pkg}_FOUND")
+ if(${pkg}_FOUND)
+ list(APPEND _ARMA_SUPPORT_LIBRARIES ${${pkg}_LIBRARIES})
+ endif()
+ endif()
+ endforeach()
+endif()
+
find_package_handle_standard_args(Armadillo
- REQUIRED_VARS ARMADILLO_LIBRARY ARMADILLO_INCLUDE_DIR
+ REQUIRED_VARS ARMADILLO_INCLUDE_DIR ${_ARMA_REQUIRED_VARS}
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})
+ set(ARMADILLO_LIBRARIES ${ARMADILLO_LIBRARY} ${_ARMA_SUPPORT_LIBRARIES})
endif ()
-# Hide internal variables
-mark_as_advanced(
- ARMADILLO_INCLUDE_DIR
- ARMADILLO_LIBRARY)
+# Clean up internal variables
+unset(_ARMA_REQUIRED_VARS)
+unset(_ARMA_SUPPORT_LIBRARIES)
+unset(_ARMA_USE_WRAPPER)
+unset(_ARMA_USE_LAPACK)
+unset(_ARMA_USE_BLAS)
+unset(_ARMA_USE_ARPACK)
+unset(_ARMA_USE_HDF5)
+unset(_ARMA_CONFIG_CONTENTS)
+unset(_ARMA_HEADER_CONTENTS)