-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathCMakeLists.txt
180 lines (138 loc) · 5.64 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
cmake_minimum_required (VERSION 3.18)
project(arpackpp VERSION 2.4.0
DESCRIPTION "ARPACK++: C++ interface to ARPACK"
LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(arpackpp_MAJOR_VERSION 2)
set(arpackpp_MINOR_VERSION 4)
set(arpackpp_PATCH_VERSION 0)
set(arpackpp_VERSION ${arpackpp_MAJOR_VERSION}.${arpackpp_MINOR_VERSION}.${arpackpp_PATCH_VERSION})
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/lib/libumfpack.a" AND
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/lib/libcholmod.a")
set (suitesparse_static ON)
else()
set (suitesparse_static OFF)
endif()
option(ENABLE_TESTS "Build tests (examples)" ON)
option(ENABLE_FORTRAN "Enable Fortran language (for static linking of ARPACK)" OFF)
option(ENABLE_SUPERLU "Enable SUPERLU" OFF)
option(ENABLE_UMFPACK "Enable UMFPACK" OFF)
option(ENABLE_CHOLMOD "Enable CHOLMOD" OFF)
option(ENABLE_SUITESPARSE_STATIC "Enable linking SuiteSparse static targets" ${suitesparse_static})
option(INSTALL_ARPACKPP_CMAKE_TARGET "Enable the creation of CMake config targets" ON)
if (ENABLE_FORTRAN)
enable_language(Fortran)
endif()
# In case the dependencies are installed locally using the shell scripts, we need to
# let CMake know, where to look for the config-file packages.
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/external)
# In case dependencies were installed by a package manager, we need to let CMake know
# where to look for the modules.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
# Custom macro to find packages. First try config mode. If the target isn't found,
# use module mode.
macro(find_package_custom name target)
find_package(${name} CONFIG QUIET)
if (NOT TARGET ${target})
find_package(${name} REQUIRED)
else()
get_target_property(location ${target} LOCATION)
message( STATUS "Found ${name} [config]: ${location}" )
endif()
endmacro()
# Find BLAS and LAPACK
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
# Find arpack-ng
find_package_custom(arpackng ARPACK::ARPACK)
get_target_property(type ARPACK::ARPACK TYPE)
if (NOT ENABLE_FORTRAN AND NOT WIN32 AND type MATCHES "^STATIC")
message( STATUS "Enabling Fortran for static linking to ARPACK..." )
enable_language(Fortran)
endif()
# Find SuperLU
if (ENABLE_SUPERLU)
find_package_custom(superlu superlu::superlu)
endif()
# Find SuiteSparse
if (ENABLE_CHOLMOD OR ENABLE_UMFPACK)
if (ENABLE_SUITESPARSE_STATIC)
message(STATUS "Linking SuiteSparse static")
find_package_custom ( SuiteSparse_config SuiteSparse::SuiteSparseConfig_static )
find_package_custom ( AMD SuiteSparse::AMD_static )
find_package_custom ( CAMD SuiteSparse::CAMD_static )
find_package_custom ( CCOLAMD SuiteSparse::CCOLAMD_static )
find_package_custom ( COLAMD SuiteSparse::COLAMD_static )
find_package_custom ( CHOLMOD SuiteSparse::CHOLMOD_static )
if (NOT TARGET SuiteSparse::CHOLMOD_static)
message(FATAL_ERROR "CHOLMOD_static not found")
endif()
else()
find_package_custom ( SuiteSparse_config SuiteSparse::SuiteSparseConfig )
find_package_custom ( AMD SuiteSparse::AMD )
find_package_custom ( CAMD SuiteSparse::CAMD )
find_package_custom ( CCOLAMD SuiteSparse::CCOLAMD )
find_package_custom ( COLAMD SuiteSparse::COLAMD )
find_package_custom ( CHOLMOD SuiteSparse::CHOLMOD )
if (NOT TARGET SuiteSparse::CHOLMOD)
message(FATAL_ERROR "CHOLMOD not found")
endif()
endif()
endif()
if (ENABLE_UMFPACK)
if (ENABLE_SUITESPARSE_STATIC)
find_package_custom ( UMFPACK SuiteSparse::UMFPACK_static )
if (NOT TARGET SuiteSparse::UMFPACK_static )
message(FATAL_ERROR "UMFPACK_static not found")
endif()
else()
find_package_custom ( UMFPACK SuiteSparse::UMFPACK )
if (NOT TARGET SuiteSparse::UMFPACK )
message(FATAL_ERROR "UMFPACK not found")
endif()
endif()
endif()
# ARPACK++ target
include(GNUInstallDirs)
add_library(arpackpp INTERFACE)
add_library(arpackpp::arpackpp ALIAS arpackpp)
target_link_libraries(arpackpp INTERFACE ARPACK::ARPACK)
# Adding the install interface generator expression makes sure that the include
# files are installed to the proper location (provided by GNUInstallDirs)
target_include_directories(arpackpp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>/arpackpp)
target_compile_features(arpackpp INTERFACE cxx_std_17)
# Examples
if(ENABLE_TESTS)
enable_testing()
add_subdirectory(examples)
endif()
# Install
install (TARGETS arpackpp EXPORT arpackppTargets)
if(INSTALL_ARPACKPP_CMAKE_TARGET)
include(CMakePackageConfigHelpers)
set(ARPACKPP_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/arpackpp/cmake)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/arpackppConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/arpackppConfig.cmake
INSTALL_DESTINATION ${ARPACKPP_CONFIG_INSTALL_DIR}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(arpackppConfigVersion.cmake
VERSION ${arpackpp_VERSION}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT)
export(TARGETS arpackpp NAMESPACE arpackpp:: FILE arpackppTargets.cmake)
install(EXPORT arpackppTargets NAMESPACE arpackpp:: DESTINATION ${ARPACKPP_CONFIG_INSTALL_DIR})
install (FILES
${CMAKE_CURRENT_BINARY_DIR}/arpackppConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/arpackppConfigVersion.cmake
DESTINATION ${ARPACKPP_CONFIG_INSTALL_DIR})
endif()
file (GLOB HEADERS "include/*.h")
install (FILES ${HEADERS} DESTINATION include/arpackpp)
file (GLOB_RECURSE EXAMPLE_HEADERS "examples/*.h")
install (FILES ${EXAMPLE_HEADERS} DESTINATION include/arpackpp)