19
19
find_path(ARMADILLO_INCLUDE_DIRS
21
PATHS ${ARMADILLO_DIR}/include $ENV{ARMADILLO_DIR}/include
21
HINTS ${ARMADILLO_DIR}/include $ENV{ARMADILLO_DIR}/include
22
22
DOC "Directory where the Armadillo header file is located"
24
24
mark_as_advanced(ARMADILLO_INCLUDE_DIRS)
26
26
find_library(ARMADILLO_LIBRARIES
28
PATHS ${ARMADILLO_DIR}/lib $ENV{ARMADILLO_DIR}/lib
28
HINTS ${ARMADILLO_DIR}/lib $ENV{ARMADILLO_DIR}/lib
29
29
DOC "The Armadillo library"
31
31
mark_as_advanced(ARMADILLO_LIBRARIES)
50
50
include(CheckCXXSourceRuns)
52
52
# Armadillo needs the location of the Boost header files
53
if (NOT Boost_INCLUDE_DIR)
54
54
set(BOOST_ROOT $ENV{BOOST_DIR})
55
set(Boost_ADDITIONAL_VERSIONS 1.43 1.43.0)
55
set(Boost_ADDITIONAL_VERSIONS 1.43 1.43.0 1.44 1.44.0 1.45 1.45.0)
56
56
find_package(Boost REQUIRED)
59
59
# These are needed for the try_run and check_cxx_source_runs commands below
60
set(CMAKE_REQUIRED_INCLUDES ${ARMADILLO_INCLUDE_DIRS} ${Boost_INCLUDE_DIR})
60
set(CMAKE_REQUIRED_INCLUDES ${ARMADILLO_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
61
61
set(CMAKE_REQUIRED_LIBRARIES ${ARMADILLO_LIBRARIES})
62
62
if (ARMADILLO_LINK_FLAGS)
63
63
set(CMAKE_REQUIRED_LIBRARIES ${ARMADILLO_LINK_FLAGS} ${CMAKE_REQUIRED_LIBRARIES})
83
83
ARMADILLO_CONFIG_TEST_VERSION_COMPILED
84
84
${CMAKE_CURRENT_BINARY_DIR}
85
85
${ARMADILLO_CONFIG_TEST_VERSION_CPP}
86
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
86
87
RUN_OUTPUT_VARIABLE OUTPUT
90
91
set(ARMADILLO_VERSION ${OUTPUT} CACHE TYPE STRING)
94
if (${ARMADILLO_VERSION} VERSION_GREATER "0.9.10")
95
set(armadillo_test_str "
99
arma::mat A = arma::randu(4, 4);
100
arma::vec b = arma::randu(4);
101
arma::vec x = arma::solve(A, b);
106
set(armadillo_test_str "
110
arma::mat A = arma::rand(4, 4);
111
arma::vec b = arma::rand(4);
112
arma::vec x = arma::solve(A, b);
93
118
# Check that C++ program runs
94
check_cxx_source_compiles("
98
arma::mat A = arma::rand(4, 4);
99
arma::vec b = arma::rand(4);
100
arma::vec x = arma::solve(A, b);
119
check_cxx_source_runs("${armadillo_test_str}" ARMADILLO_TEST_RUNS)
106
# If program runs, trying adding LAPACK library and test again
121
# If program does not run, try adding LAPACK library and test again
107
122
if(NOT ARMADILLO_TEST_RUNS)
123
if (NOT LAPACK_FOUND)
109
126
if (LAPACK_LIBRARIES)
110
127
set(CMAKE_REQUIRED_LIBRARIES ${ARMADILLO_LIBRARIES} ${LAPACK_LIBRARIES})
111
check_cxx_source_runs("
115
arma::mat A = arma::rand(4, 4);
116
arma::vec b = arma::rand(4);
117
arma::vec x = arma::solve(A, b);
121
ARMADILLO_LAPACK_TEST_RUNS)
128
check_cxx_source_runs("${armadillo_test_str}" ARMADILLO_LAPACK_TEST_RUNS)
123
130
# Add LAPACK libary if required
124
131
if (ARMADILLO_LAPACK_TEST_RUNS)
138
145
include(FindPackageHandleStandardArgs)
139
146
find_package_handle_standard_args(Armadillo
140
147
"Armadillo could not be found. Be sure to set ARMADILLO_DIR."
148
ARMADILLO_LIBRARIES ARMADILLO_INCLUDE_DIRS ARMADILLO_TEST_RUNS)