File: CMakeLists.txt

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (185 lines) | stat: -rw-r--r-- 7,072 bytes parent folder | download | duplicates (2)
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
#-------------------------------------------------------------------------------
# CSparse/CMakeLists.txt:  cmake for CSparse
#-------------------------------------------------------------------------------

# Copyright (c) 2006-2023, Timothy A. Davis.  All Rights Reserved.
# SPDX-License-Identifier: LGPL-2.1+

# CSparse/CMakeLists.txt is a standalone script, which can be used outside of
# SuiteSparse.  There is no "make install" target for CSparse.  The library
# (libcsparse.so) and include file (cs.h) are NOT installed in ../lib and
# ../include.  CSparse is meant for classwork and stand-alone development,
# while SuiteSparse/CXSparse should be used in production.

#-------------------------------------------------------------------------------
# get the version
#-------------------------------------------------------------------------------

# Note that CSparse can use an older cmake version than most of SuiteSparse.
cmake_minimum_required ( VERSION 3.13 )     # CSparse can be built stand-alone

set ( CSPARSE_DATE "Mar 22, 2024" )
set ( CSPARSE_VERSION_MAJOR 4 CACHE STRING "" FORCE )
set ( CSPARSE_VERSION_MINOR 3 CACHE STRING "" FORCE )
set ( CSPARSE_VERSION_SUB   2 CACHE STRING "" FORCE )

message ( STATUS "Building CSparse version: v"
    ${CSPARSE_VERSION_MAJOR}.
    ${CSPARSE_VERSION_MINOR}.
    ${CSPARSE_VERSION_SUB} " (" ${CSPARSE_DATE} ")" )

#-------------------------------------------------------------------------------
# define the project
#-------------------------------------------------------------------------------

project ( csparse
    VERSION "${CSPARSE_VERSION_MAJOR}.${CSPARSE_VERSION_MINOR}.${CSPARSE_VERSION_SUB}"
    LANGUAGES C )

#-------------------------------------------------------------------------------
# SuiteSparse policies (a subset)
#-------------------------------------------------------------------------------

message ( STATUS "Source:        " ${PROJECT_SOURCE_DIR} )
message ( STATUS "Build:         " ${CMAKE_BINARY_DIR} )

if ( WIN32 )
    set ( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true )
    add_compile_definitions ( _CRT_SECURE_NO_WARNINGS )
endif ( )

include ( GNUInstallDirs )

if ( NOT CMAKE_BUILD_TYPE )
    set ( CMAKE_BUILD_TYPE Release )
endif ( )

message ( STATUS "Build type:    " ${CMAKE_BUILD_TYPE} )

# BUILD_SHARED_LIBS and BUILD_STATIC_LIBS options
option ( BUILD_SHARED_LIBS "OFF: do not build shared libraries.  ON (default): build shared libraries" ON )
option ( BUILD_STATIC_LIBS "OFF: do not build static libraries.  ON (default): build static libraries" ON )

if ( CMAKE_C_COMPILER_ID STREQUAL "Clang" )
    set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-extra-semi-stmt" )
endif ( )
if ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
    set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-extra-semi-stmt" )
endif ( )

#-------------------------------------------------------------------------------
# Configure cs.h with version number
#-------------------------------------------------------------------------------

configure_file ( "Config/cs.h.in"
    "${PROJECT_SOURCE_DIR}/Include/cs.h"
    NEWLINE_STYLE LF )

#-------------------------------------------------------------------------------
# include directories
#-------------------------------------------------------------------------------

set ( CMAKE_INCLUDE_CURRENT_DIR ON )
include_directories ( Source Include )

#-------------------------------------------------------------------------------
# dynamic csparse library properties
#-------------------------------------------------------------------------------

file ( GLOB CSPARSE_SOURCES "Source/*.c" )

if ( BUILD_SHARED_LIBS )
    add_library ( csparse SHARED ${CSPARSE_SOURCES} )

    set_target_properties ( csparse PROPERTIES
        VERSION ${CSPARSE_VERSION_MAJOR}.${CSPARSE_VERSION_MINOR}.${CSPARSE_VERSION_SUB}
        C_STANDARD 11
        C_STANDARD_REQUIRED ON
        SOVERSION ${CSPARSE_VERSION_MAJOR}
        PUBLIC_HEADER "Include/cs.h"
        WINDOWS_EXPORT_ALL_SYMBOLS ON )
endif ( )

#-------------------------------------------------------------------------------
# static csparse library properties
#-------------------------------------------------------------------------------

if ( BUILD_STATIC_LIBS )
    add_library ( csparse_static STATIC ${CSPARSE_SOURCES} )

    set_target_properties ( csparse_static PROPERTIES
        OUTPUT_NAME csparse
        C_STANDARD 11
        C_STANDARD_REQUIRED ON
        PUBLIC_HEADER "Include/cs.h" )

    if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") )
        set_target_properties ( csparse_static PROPERTIES
            OUTPUT_NAME csparse_static )
    endif ( )
endif ( )

#-------------------------------------------------------------------------------
# add the library dependencies
#-------------------------------------------------------------------------------

# libm:
if ( NOT WIN32 )
    if ( BUILD_SHARED_LIBS )
        target_link_libraries ( csparse PRIVATE m )
    endif ( )
    if ( BUILD_STATIC_LIBS )
        set ( CSPARSE_STATIC_LIBS "${CSPARSE_STATIC_LIBS} -lm" )
        target_link_libraries ( csparse_static PUBLIC m )
    endif ( )
endif ( )


#-------------------------------------------------------------------------------
# create pkg-config file
#-------------------------------------------------------------------------------

if ( NOT MSVC )
    set ( prefix "${CMAKE_INSTALL_PREFIX}" )
    set ( exec_prefix "\${prefix}" )
    cmake_path ( IS_ABSOLUTE CMAKE_INSTALL_LIBDIR SUITESPARSE_LIBDIR_IS_ABSOLUTE )
    if (SUITESPARSE_LIBDIR_IS_ABSOLUTE)
        set ( libdir "${CMAKE_INSTALL_LIBDIR}")
    else ( )
        set ( libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
    endif ( )
    cmake_path ( IS_ABSOLUTE CMAKE_INSTALL_INCLUDEDIR SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE )
    if (SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE)
        set ( includedir "${CMAKE_INSTALL_INCLUDEDIR}")
    else ( )
        set ( includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
    endif ( )
    configure_file (
        Config/CSparse.pc.in
        CSparse.pc
        @ONLY
        NEWLINE_STYLE LF )
    # install ( FILES
    #     ${CMAKE_CURRENT_BINARY_DIR}/CSparse.pc
    #     DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
endif ( )

#-------------------------------------------------------------------------------
# Demo library and programs
#-------------------------------------------------------------------------------

add_executable ( cs_demo1 "Demo/cs_demo1.c" "Demo/cs_demo.c" )
add_executable ( cs_demo2 "Demo/cs_demo2.c" "Demo/cs_demo.c" )
add_executable ( cs_demo3 "Demo/cs_demo3.c" "Demo/cs_demo.c" )

# Libraries required for Demo programs
if ( BUILD_SHARED_LIBS )
    target_link_libraries ( cs_demo1 PUBLIC csparse )
    target_link_libraries ( cs_demo2 PUBLIC csparse )
    target_link_libraries ( cs_demo3 PUBLIC csparse )
else ( )
    target_link_libraries ( cs_demo1 PUBLIC csparse_static )
    target_link_libraries ( cs_demo2 PUBLIC csparse_static )
    target_link_libraries ( cs_demo3 PUBLIC csparse_static )
endif ( )