forked from DrTimothyAldenDavis/SuiteSparse
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
279 lines (225 loc) · 10.2 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
#-------------------------------------------------------------------------------
# SuiteSparse/CCOLAMD/CMakeLists.txt: cmake for CCOLAMD
#-------------------------------------------------------------------------------
# Copyright (c) 2005-2024, Timothy A. Davis. All Rights Reserved.
# SPDX-License-Identifier: BSD-3-clause
#-------------------------------------------------------------------------------
# get the version
#-------------------------------------------------------------------------------
cmake_minimum_required ( VERSION 3.22 )
set ( CCOLAMD_DATE "June 20, 2024" )
set ( CCOLAMD_VERSION_MAJOR 3 CACHE STRING "" FORCE )
set ( CCOLAMD_VERSION_MINOR 3 CACHE STRING "" FORCE )
set ( CCOLAMD_VERSION_SUB 4 CACHE STRING "" FORCE )
message ( STATUS "Building CCOLAMD version: v"
${CCOLAMD_VERSION_MAJOR}.
${CCOLAMD_VERSION_MINOR}.
${CCOLAMD_VERSION_SUB} " (" ${CCOLAMD_DATE} ")" )
#-------------------------------------------------------------------------------
# define the project
#-------------------------------------------------------------------------------
project ( CCOLAMD
VERSION "${CCOLAMD_VERSION_MAJOR}.${CCOLAMD_VERSION_MINOR}.${CCOLAMD_VERSION_SUB}"
LANGUAGES C )
#-------------------------------------------------------------------------------
# SuiteSparse policies
#-------------------------------------------------------------------------------
set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${PROJECT_SOURCE_DIR}/../SuiteSparse_config/cmake_modules )
include ( SuiteSparsePolicy )
#-------------------------------------------------------------------------------
# find library dependencies
#-------------------------------------------------------------------------------
if ( NOT SUITESPARSE_ROOT_CMAKELISTS )
find_package ( SuiteSparse_config 7.8.0
PATHS ${CMAKE_SOURCE_DIR}/../SuiteSparse_config/build NO_DEFAULT_PATH )
if ( NOT TARGET SuiteSparse::SuiteSparseConfig )
find_package ( SuiteSparse_config 7.8.0 REQUIRED )
endif ( )
endif ( )
#-------------------------------------------------------------------------------
# configure files
#-------------------------------------------------------------------------------
configure_file ( "Config/ccolamd.h.in"
"${PROJECT_SOURCE_DIR}/Include/ccolamd.h"
NEWLINE_STYLE LF )
#-------------------------------------------------------------------------------
# include directories
#-------------------------------------------------------------------------------
include_directories ( Source Include )
#-------------------------------------------------------------------------------
# dynamic ccolamd library properties
#-------------------------------------------------------------------------------
file ( GLOB CCOLAMD_SOURCES "Source/*.c" )
if ( BUILD_SHARED_LIBS )
add_library ( CCOLAMD SHARED ${CCOLAMD_SOURCES} )
set_target_properties ( CCOLAMD PROPERTIES
VERSION ${CCOLAMD_VERSION_MAJOR}.${CCOLAMD_VERSION_MINOR}.${CCOLAMD_VERSION_SUB}
C_STANDARD 11
C_STANDARD_REQUIRED ON
OUTPUT_NAME ccolamd
SOVERSION ${CCOLAMD_VERSION_MAJOR}
PUBLIC_HEADER "Include/ccolamd.h"
WINDOWS_EXPORT_ALL_SYMBOLS ON )
if ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25" )
set_target_properties ( CCOLAMD PROPERTIES EXPORT_NO_SYSTEM ON )
endif ( )
target_include_directories ( CCOLAMD
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Include>
$<INSTALL_INTERFACE:${SUITESPARSE_INCLUDEDIR}> )
endif ( )
#-------------------------------------------------------------------------------
# static ccolamd library properties
#-------------------------------------------------------------------------------
if ( BUILD_STATIC_LIBS )
add_library ( CCOLAMD_static STATIC ${CCOLAMD_SOURCES} )
set_target_properties ( CCOLAMD_static PROPERTIES
OUTPUT_NAME ccolamd
C_STANDARD 11
C_STANDARD_REQUIRED ON
PUBLIC_HEADER "Include/ccolamd.h" )
if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") )
set_target_properties ( CCOLAMD_static PROPERTIES
OUTPUT_NAME ccolamd_static )
endif ( )
if ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25" )
set_target_properties ( CCOLAMD_static PROPERTIES EXPORT_NO_SYSTEM ON )
endif ( )
target_include_directories ( CCOLAMD_static
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Include>
$<INSTALL_INTERFACE:${SUITESPARSE_INCLUDEDIR}> )
endif ( )
#-------------------------------------------------------------------------------
# add the library dependencies
#-------------------------------------------------------------------------------
if ( BUILD_SHARED_LIBS )
target_link_libraries ( CCOLAMD PRIVATE SuiteSparse::SuiteSparseConfig )
target_include_directories ( CCOLAMD PUBLIC
"$<TARGET_PROPERTY:SuiteSparse::SuiteSparseConfig,INTERFACE_INCLUDE_DIRECTORIES>" )
endif ( )
if ( BUILD_STATIC_LIBS )
if ( TARGET SuiteSparse::SuiteSparseConfig_static )
target_link_libraries ( CCOLAMD_static PUBLIC SuiteSparse::SuiteSparseConfig_static )
else ( )
target_link_libraries ( CCOLAMD_static PUBLIC SuiteSparse::SuiteSparseConfig )
endif ( )
endif ( )
# libm:
if ( NOT WIN32 )
if ( BUILD_SHARED_LIBS )
target_link_libraries ( CCOLAMD PRIVATE m )
endif ( )
if ( BUILD_STATIC_LIBS )
set ( CCOLAMD_STATIC_LIBS "${CCOLAMD_STATIC_LIBS} -lm" )
target_link_libraries ( CCOLAMD_static PUBLIC m )
endif ( )
endif ( )
#-------------------------------------------------------------------------------
# COLAMD installation location
#-------------------------------------------------------------------------------
include ( CMakePackageConfigHelpers )
if ( BUILD_SHARED_LIBS )
install ( TARGETS CCOLAMD
EXPORT CCOLAMDTargets
LIBRARY DESTINATION ${SUITESPARSE_LIBDIR}
ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR}
RUNTIME DESTINATION ${SUITESPARSE_BINDIR}
PUBLIC_HEADER DESTINATION ${SUITESPARSE_INCLUDEDIR} )
endif ( )
if ( BUILD_STATIC_LIBS )
install ( TARGETS CCOLAMD_static
EXPORT CCOLAMDTargets
ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR}
PUBLIC_HEADER DESTINATION ${SUITESPARSE_INCLUDEDIR} )
endif ( )
# create (temporary) export target file during build
export ( EXPORT CCOLAMDTargets
NAMESPACE SuiteSparse::
FILE ${CMAKE_CURRENT_BINARY_DIR}/CCOLAMDTargets.cmake )
# install export target, config and version files for find_package
install ( EXPORT CCOLAMDTargets
NAMESPACE SuiteSparse::
DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/CCOLAMD )
# generate config file to be used in common build tree
set ( SUITESPARSE_IN_BUILD_TREE ON )
configure_package_config_file (
Config/CCOLAMDConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CCOLAMDConfig.cmake
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/CCOLAMDConfig.cmake )
# generate config file to be installed
set ( SUITESPARSE_IN_BUILD_TREE OFF )
configure_package_config_file (
Config/CCOLAMDConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/target/CCOLAMDConfig.cmake
INSTALL_DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/CCOLAMD )
write_basic_package_version_file (
${CMAKE_CURRENT_BINARY_DIR}/CCOLAMDConfigVersion.cmake
COMPATIBILITY SameMajorVersion )
install ( FILES
${CMAKE_CURRENT_BINARY_DIR}/target/CCOLAMDConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/CCOLAMDConfigVersion.cmake
DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/CCOLAMD )
#-------------------------------------------------------------------------------
# create pkg-config file
#-------------------------------------------------------------------------------
if ( NOT MSVC )
set ( prefix "${CMAKE_INSTALL_PREFIX}" )
set ( exec_prefix "\${prefix}" )
cmake_path ( IS_ABSOLUTE SUITESPARSE_LIBDIR SUITESPARSE_LIBDIR_IS_ABSOLUTE )
if (SUITESPARSE_LIBDIR_IS_ABSOLUTE)
set ( libdir "${SUITESPARSE_LIBDIR}")
else ( )
set ( libdir "\${exec_prefix}/${SUITESPARSE_LIBDIR}")
endif ( )
cmake_path ( IS_ABSOLUTE SUITESPARSE_INCLUDEDIR SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE )
if (SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE)
set ( includedir "${SUITESPARSE_INCLUDEDIR}")
else ( )
set ( includedir "\${prefix}/${SUITESPARSE_INCLUDEDIR}")
endif ( )
if ( BUILD_SHARED_LIBS )
set ( SUITESPARSE_LIB_BASE_NAME $<TARGET_FILE_BASE_NAME:CCOLAMD> )
else ( )
set ( SUITESPARSE_LIB_BASE_NAME $<TARGET_FILE_BASE_NAME:CCOLAMD_static> )
endif ( )
configure_file (
Config/CCOLAMD.pc.in
CCOLAMD.pc.out
@ONLY
NEWLINE_STYLE LF )
file ( GENERATE
OUTPUT CCOLAMD.pc
INPUT ${CMAKE_CURRENT_BINARY_DIR}/CCOLAMD.pc.out
NEWLINE_STYLE LF )
install ( FILES
${CMAKE_CURRENT_BINARY_DIR}/CCOLAMD.pc
DESTINATION ${SUITESPARSE_PKGFILEDIR}/pkgconfig )
endif ( )
#-------------------------------------------------------------------------------
# Demo library and programs
#-------------------------------------------------------------------------------
if ( SUITESPARSE_DEMOS )
#---------------------------------------------------------------------------
# demo library
#---------------------------------------------------------------------------
message ( STATUS "Also compiling the demos in CCOLAMD/Demo" )
#---------------------------------------------------------------------------
# Demo programs
#---------------------------------------------------------------------------
add_executable ( ccolamd_example "Demo/ccolamd_example.c" )
add_executable ( ccolamd_l_example "Demo/ccolamd_l_example.c" )
# Libraries required for Demo programs
if ( BUILD_SHARED_LIBS )
target_link_libraries ( ccolamd_example PUBLIC CCOLAMD )
target_link_libraries ( ccolamd_l_example PUBLIC CCOLAMD )
else ( )
target_link_libraries ( ccolamd_example PUBLIC CCOLAMD_static )
target_link_libraries ( ccolamd_l_example PUBLIC CCOLAMD_static )
endif ( )
else ( )
message ( STATUS "Skipping the demos in CCOLAMD/Demo" )
endif ( )
#-------------------------------------------------------------------------------
# report status
#-------------------------------------------------------------------------------
include ( SuiteSparseReport )