forked from DrTimothyAldenDavis/SuiteSparse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
418 lines (335 loc) · 13 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#
# CMake support layer for SuiteSparse
#
# Copyright 2016-2021 Sergiu Deitsch <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
cmake_minimum_required (VERSION 3.9)
include (CheckLanguage)
project (SuiteSparse LANGUAGES C CXX VERSION 5.10.1
DESCRIPTION "A suite of sparse matrix packages"
HOMEPAGE_URL http://faculty.cse.tamu.edu/davis/suitesparse.html
)
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set (CMAKE_DEBUG_POSTFIX _debug)
#set (CMAKE_C_FLAGS "-Wall -pedantic")
# set(CMAKE_C_CLANG_TIDY
# clang-tidy;
# -header-filter=.;
# -checks=-*,clang-analyzer-*,bugprone-*,google-*,performance-*;)
include (CheckCCompilerFlag)
include (CheckFunctionExists)
include (CMakeDependentOption)
include (FeatureSummary)
include (GenerateExportHeader)
include (GNUInstallDirs)
set (CMAKE_C_VISIBILITY_PRESET hidden)
set (CMAKE_CXX_VISIBILITY_PRESET hidden)
set (CMAKE_VISIBILITY_INLINES_HIDDEN 1)
check_c_compiler_flag (-fPIC HAVE_FPIC)
check_c_compiler_flag (-Qstd=c99 HAVE_QSTD_C99)
option (WITH_LGPL "Enable GNU LGPL modules" ON)
cmake_dependent_option (WITH_GPL "Enable GNU GPL modules" ON "WITH_LGPL" OFF)
# SuiteSparse version
set (MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set (MINOR_VERSION ${PROJECT_VERSION_MINOR})
set (VERSION_PATCH ${PROJECT_VERSION_PATCH})
set (SHORT_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}")
if (NOT VERSION_PATCH EQUAL 0)
set (SHORT_VERSION "${SHORT_VERSION}.${VERSION_PATCH}")
endif (NOT VERSION_PATCH EQUAL 0)
set (VERSION ${PROJECT_VERSION})
set (CPACK_PACKAGE_NAME SuiteSparse)
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "SuiteSparse: an extended version of CSparse")
set (CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION})
set (CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set (CPACK_PACKAGE_VERSION ${SHORT_VERSION})
include (CMakePackageConfigHelpers)
include (CMakePushCheckState)
include (CPack)
include (CheckIncludeFile)
include (CheckLibraryExists)
include (CheckSymbolExists)
include (CheckTypeSize)
include (ComponentVersion)
include (GenerateSourceFiles)
cmake_push_check_state (RESET)
check_include_file (complex.h HAVE_COMPLEX_H)
check_include_file (fenv.h HAVE_FENV_H)
check_library_exists (m ceil "" HAVE_M)
cmake_push_check_state (RESET)
set (CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
if (HAVE_M)
set (CMAKE_REQUIRED_LIBRARIES m)
endif (HAVE_M)
check_symbol_exists (feenableexcept "fenv.h" HAVE_FEENABLEEXCEPT)
cmake_pop_check_state ()
check_symbol_exists (_controlfp "float.h" HAVE__CONTROLFP)
set (CMAKE_EXTRA_INCLUDE_FILES complex.h)
check_type_size (_C_double_complex HAVE_C_DOUBLE_COMPLEX BUILTIN_TYPES_ONLY)
source_group ("Generated Files" REGULAR_EXPRESSION ".+_(di|dl|zi|zl)(_.+)?\\.c$")
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_property (DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
_CRT_SECURE_NO_WARNINGS)
endif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set (AMD_SRCS
AMD/Source/amd_1.c
AMD/Source/amd_2.c
AMD/Source/amd_aat.c
AMD/Source/amd_control.c
AMD/Source/amd_defaults.c
AMD/Source/amd_dump.c
AMD/Source/amd_global.c
AMD/Source/amd_info.c
AMD/Source/amd_order.c
AMD/Source/amd_post_tree.c
AMD/Source/amd_postorder.c
AMD/Source/amd_preprocess.c
AMD/Source/amd_valid.c
)
set (AMD_HDRS
AMD/Include/amd.h
)
set (COLAMD_SRCS
COLAMD/Source/colamd.c
)
set (COLAMD_HDRS
COLAMD/Include/colamd.h
)
set (BTF_SRCS
BTF/Source/btf_maxtrans.c
BTF/Source/btf_order.c
BTF/Source/btf_strongcomp.c
)
set (BTF_HDRS
BTF/Include/btf.h
)
set (KLU_SRCS
KLU/Source/klu.c
KLU/Source/klu_analyze.c
KLU/Source/klu_analyze_given.c
KLU/Source/klu_compute_path.c
KLU/Source/klu_defaults.c
KLU/Source/klu_diagnostics.c
KLU/Source/klu_dump.c
KLU/Source/klu_extract.c
KLU/Source/klu_factor.c
KLU/Source/klu_free_numeric.c
KLU/Source/klu_free_symbolic.c
KLU/Source/klu_kernel.c
KLU/Source/klu_memory.c
KLU/Source/klu_print.c
KLU/Source/klu_partial_factorization_path.c
KLU/Source/klu_partial_refactorization_restart.c
KLU/Source/klu_refactor.c
KLU/Source/klu_scale.c
KLU/Source/klu_solve.c
KLU/Source/klu_sort.c
KLU/Source/klu_tsolve.c
)
set (KLU
KLU/Include/klu.h
KLU/Include/klu_version.h
)
generate_source_files (GEN_AMD_SRCS_DINT FILES "${AMD_SRCS}" SUFFIX _di
COMPILE_DEFINITIONS DINT)
generate_source_files (GEN_AMD_SRCS_DLONG FILES "${AMD_SRCS}" SUFFIX _dl
COMPILE_DEFINITIONS DLONG)
generate_source_files (GEN_COLAMD_SRCS_DINT FILES "${COLAMD_SRCS}" SUFFIX _di
COMPILE_DEFINITIONS DINT)
generate_source_files (GEN_COLAMD_SRCS_DLONG FILES "${COLAMD_SRCS}" SUFFIX _dl
COMPILE_DEFINITIONS DLONG)
generate_source_files (GEN_BTF_SRCS_DINT FILES "${BTF_SRCS}" SUFFIX _di
COMPILE_DEFINITIONS DINT)
generate_source_files (GEN_BTF_SRCS_DLONG FILES "${BTF_SRCS}" SUFFIX _dl
COMPILE_DEFINITIONS DLONG)
generate_source_files (GEN_KLU_SRCS_DINT FILES "${KLU_SRCS}" SUFFIX _di
COMPILE_DEFINITIONS DINT)
generate_source_files (GEN_KLU_SRCS_DLONG FILES "${KLU_SRCS}" SUFFIX _dl
COMPILE_DEFINITIONS DLONG)
if (HAVE_COMPLEX_H)
#list (APPEND PROJECT_SRCS Source/cs_convert.c)
endif (HAVE_COMPLEX_H)
if (MSVC)
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
endif (MSVC)
# output directory for binaries
set (OUTPUT_DIR ${CMAKE_BINARY_DIR})
# put binaries in a single directory
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR})
add_library (amd
AMD/Include/amd_internal.h
${AMD_HDRS}
${GEN_AMD_SRCS_DINT}
${GEN_AMD_SRCS_DLONG}
)
add_library (colamd
${COLAMD_HDRS}
${GEN_COLAMD_SRCS_DINT}
${GEN_COLAMD_SRCS_DLONG}
)
add_library (btf
BTF/Include/btf_internal.h
${BTF_HDRS}
${GEN_BTF_SRCS_DINT}
${GEN_BTF_SRCS_DLONG}
)
set (SUITESPARSECONFIG_HDRS
SuiteSparse_config/SuiteSparse_config.h
)
add_library (suitesparseconfig
SuiteSparse_config/SuiteSparse_config.c
${SUITESPARSECONFIG_HDRS}
)
set (KLU_HDRS
KLU/Include/klu.h
KLU/Include/klu_version.h
)
add_library (klu KLU/Include/klu_internal.h
${GEN_KLU_SRCS_DINT}
${GEN_KLU_SRCS_DLONG}
${KLU_HDRS}
)
target_link_libraries (klu PUBLIC amd btf colamd)
set (SuiteSparse_AMD_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/SuiteSparse/AMD)
set (SuiteSparse_BTF_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/SuiteSparse/BTF)
set (SuiteSparse_COLAMD_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/SuiteSparse/COLAMD)
set (SuiteSparse_SUITESPARSECONFIG_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/SuiteSparse)
set (SuiteSparse_KLU_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/SuiteSparse/KLU)
if (HAVE_M)
target_link_libraries (suitesparseconfig INTERFACE m)
endif (HAVE_M)
target_include_directories (suitesparseconfig PUBLIC
"$<INSTALL_INTERFACE:${SuiteSparse_SUITESPARSECONFIG_INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/SuiteSparse_config>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${SuiteSparse_SUITESPARSECONFIG_INCLUDE_DIR}>"
)
target_include_directories (colamd PUBLIC
"$<INSTALL_INTERFACE:${SuiteSparse_COLAMD_INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/COLAMD/Include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${SuiteSparse_COLAMD_INCLUDE_DIR}>")
target_include_directories (amd PUBLIC
"$<INSTALL_INTERFACE:${SuiteSparse_AMD_INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/AMD/Include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${SuiteSparse_AMD_INCLUDE_DIR}>")
target_include_directories (btf PUBLIC
"$<INSTALL_INTERFACE:${SuiteSparse_BTF_INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/BTF/Include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${SuiteSparse_BTF_INCLUDE_DIR}>")
target_include_directories (klu PUBLIC
"$<INSTALL_INTERFACE:${SuiteSparse_KLU_INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/KLU/Include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${SuiteSparse_KLU_INCLUDE_DIR}>")
target_link_libraries (amd PUBLIC suitesparseconfig)
target_link_libraries (colamd PUBLIC suitesparseconfig)
target_link_libraries (btf PUBLIC suitesparseconfig)
target_link_libraries (klu PUBLIC suitesparseconfig)
if (NOT HAVE_COMPLEX_H)
#target_compile_definitions (SuiteSparse PUBLIC NCOMPLEX)
endif (NOT HAVE_COMPLEX_H)
if (HAVE_C_DOUBLE_COMPLEX)
#target_compile_definitions (SuiteSparse PUBLIC HAVE_C_DOUBLE_COMPLEX)
endif (HAVE_C_DOUBLE_COMPLEX)
set (_SuiteSparse_TARGETS amd btf klu colamd suitesparseconfig)
set_property (TARGET suitesparseconfig PROPERTY NAME_ALIAS SuiteSparse)
set_property (TARGET suitesparseconfig PROPERTY HEADERS_VARIABLE
SUITESPARSECONFIG_HDRS)
set_property (TARGET suitesparseconfig PROPERTY INSTALL_DESTINATION
${SuiteSparse_SUITESPARSECONFIG_INCLUDE_DIR})
foreach (_target ${_SuiteSparse_TARGETS})
get_property (_alias TARGET ${_target} PROPERTY NAME_ALIAS)
string (TOUPPER "${_target}" _upper_target)
if ("${_alias}" STREQUAL "")
set (_alias ${_upper_target})
set (_export_prefix ${_target})
else ("${_alias}" STREQUAL "")
set (_export_prefix ${_alias})
endif ("${_alias}" STREQUAL "")
get_property (_target_include_dir TARGET ${_target} PROPERTY
INSTALL_DESTINATION)
if ("${_target_include_dir}" STREQUAL "")
set (_target_include_dir ${SuiteSparse_${_alias}_INCLUDE_DIR})
endif ("${_target_include_dir}" STREQUAL "")
set (_export_header
${CMAKE_CURRENT_BINARY_DIR}/${_target_include_dir}/${_export_prefix}_export.h)
# Generate an export header with the name <target>_export.h for each mandatory
# target.
generate_export_header (${_target} EXPORT_FILE_NAME ${_export_header})
# Add the export header to the target
target_sources (${_target} PRIVATE ${_export_header})
get_property (_HDRS_VAR TARGET ${_target} PROPERTY HEADERS_VARIABLE)
if ("${_HDRS_VAR}" STREQUAL "")
set (_HDRS_VAR ${_upper_target}_HDRS)
endif ("${_HDRS_VAR}" STREQUAL "")
# Install headers
install (FILES ${${_HDRS_VAR}} ${_export_header} DESTINATION
${_target_include_dir} COMPONENT Development)
endforeach (_target)
set (SuiteSparse_CMake_LIBDIR ${CMAKE_INSTALL_LIBDIR}/SuiteSparse)
# suitesparse-config.cmake relative install directory
set (SuiteSparse_CMake_INSTALLDIR ${SuiteSparse_CMake_LIBDIR}/cmake)
target_sources (suitesparseconfig PRIVATE ${_output_CMake_MODULES})
install (TARGETS ${_SuiteSparse_TARGETS}
EXPORT suitesparse-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${SuiteSparse_CMake_LIBDIR} COMPONENT Development
ARCHIVE DESTINATION ${SuiteSparse_CMake_LIBDIR} COMPONENT Development)
#set (SuiteSparse_NAMESPACE SuiteSparse::)
configure_package_config_file (suitesparse-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/suitesparse-config.cmake
INSTALL_DESTINATION ${SuiteSparse_CMake_INSTALLDIR})
write_basic_package_version_file (suitesparse-config-version.cmake
VERSION ${VERSION} COMPATIBILITY AnyNewerVersion)
export (TARGETS ${_SuiteSparse_TARGETS} NAMESPACE ${SuiteSparse_NAMESPACE} FILE
suitesparse-targets.cmake)
export (PACKAGE SuiteSparse)
install (EXPORT suitesparse-targets NAMESPACE ${SuiteSparse_NAMESPACE}
DESTINATION ${SuiteSparse_CMake_INSTALLDIR})
install (FILES
${CMAKE_CURRENT_BINARY_DIR}/suitesparse-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/suitesparse-config-version.cmake
DESTINATION ${SuiteSparse_CMake_INSTALLDIR}
COMPONENT Development)
set_component_version (amd 2.4.6)
set_component_version (btf 1.2.6)
set_component_version (colamd 2.9.6)
set_component_version (klu 1.3.9)
set_component_version (suitesparseconfig "${VERSION}")
if (HAVE_QSTD_C99)
target_compile_options (suitesparseconfig PUBLIC $<$<C_COMPILER_ID:Intel>:-Qstd=c99>)
endif (HAVE_QSTD_C99)
set_target_properties (amd PROPERTIES EXPORT_NAME AMD)
set_target_properties (colamd PROPERTIES EXPORT_NAME COLAMD)
set_target_properties (btf PROPERTIES EXPORT_NAME BTF)
set_target_properties (klu PROPERTIES EXPORT_NAME KLU)
set_target_properties (suitesparseconfig PROPERTIES EXPORT_NAME Config)
set_target_properties (${_SuiteSparse_TARGETS} PROPERTIES
POSITION_INDEPENDENT_CODE ON)
feature_summary (WHAT ALL)
add_executable(klu_test_partial_factorization_path KLU/Demo/klu_test_partial_factorization_path.c)
target_link_libraries(klu_test_partial_factorization_path PRIVATE klu)
add_executable(klu_test_partial_refactorization_restart KLU/Demo/klu_test_partial_refactorization_restart.c)
target_link_libraries(klu_test_partial_refactorization_restart PRIVATE klu)
enable_testing()
add_test(
NAME klu_test_partial_factorization_path
COMMAND $<TARGET_FILE:klu_test_partial_factorization_path>
)
add_test(
NAME klu_test_partial_refactorization_restart
COMMAND $<TARGET_FILE:klu_test_partial_refactorization_restart>
)