Skip to content

Commit 3b2647f

Browse files
Merge pull request DrTimothyAldenDavis#726 from mmuetzel/suitesparse_config
SuiteSparse_config: Check if linking to librt is necessary
2 parents c8187d0 + eab4d8c commit 3b2647f

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

SuiteSparse_config/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,28 @@ if ( SUITESPARSE_USE_STRICT AND SUITESPARSE_CONFIG_USE_OPENMP AND NOT SUITESPARS
103103
message ( FATAL_ERROR "OpenMP required for SuiteSparse_config but not found" )
104104
endif ( )
105105

106+
# check for librt in case of fallback to "clock_gettime"
107+
include ( CheckSymbolExists )
108+
check_symbol_exists ( clock_gettime "time.h" NO_RT )
109+
if ( NO_RT )
110+
message ( STATUS "Using clock_gettime without librt" )
111+
set ( SUITESPARSE_HAVE_CLOCK_GETTIME ON )
112+
else ( )
113+
# check if we need to link to librt for that function
114+
set ( _orig_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} )
115+
list ( APPEND CMAKE_REQUIRED_LIBRARIES "rt" )
116+
check_symbol_exists ( clock_gettime "time.h" WITH_RT )
117+
set ( CMAKE_REQUIRED_LIBRARIES ${_orig_CMAKE_REQUIRED_LIBRARIES} )
118+
if ( WITH_RT )
119+
message ( STATUS "Using clock_gettime with librt" )
120+
set ( SUITESPARSE_HAVE_CLOCK_GETTIME ON )
121+
endif ( )
122+
endif ( )
123+
124+
if ( NOT SUITESPARSE_CONFIG_USE_OPENMP AND NOT SUITESPARSE_HAVE_CLOCK_GETTIME )
125+
message ( STATUS "No OpenMP and no clock_gettime available. Timing functions won't work." )
126+
endif ( )
127+
106128
#-------------------------------------------------------------------------------
107129
# find the BLAS
108130
#-------------------------------------------------------------------------------
@@ -208,6 +230,17 @@ if ( SUITESPARSE_CONFIG_USE_OPENMP )
208230
"$<TARGET_PROPERTY:OpenMP::OpenMP_C,INTERFACE_INCLUDE_DIRECTORIES>" )
209231
list ( APPEND SUITESPARSE_CONFIG_STATIC_LIBS ${OpenMP_C_LIBRARIES} )
210232
endif ( )
233+
else ( )
234+
# librt
235+
if ( WITH_RT )
236+
if ( BUILD_SHARED_LIBS )
237+
target_link_libraries ( SuiteSparseConfig PRIVATE "rt" )
238+
endif ( )
239+
if ( BUILD_STATIC_LIBS )
240+
target_link_libraries ( SuiteSparseConfig_static PRIVATE "rt" )
241+
list ( APPEND SUITESPARSE_CONFIG_STATIC_LIBS "rt" )
242+
endif ( )
243+
endif ( )
211244
endif ( )
212245

213246
# BLAS:

SuiteSparse_config/Config/SuiteSparse_config.h.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,13 @@ int SuiteSparse_divcomplex
372372
// but other packages can themselves use OpenMP. In this case,
373373
// those packages should use omp_get_wtime() directly. This can
374374
// be done via the SUITESPARSE_TIME macro, defined below:
375+
#cmakedefine SUITESPARSE_HAVE_CLOCK_GETTIME
375376
#if defined ( _OPENMP )
376377
#define SUITESPARSE_TIMER_ENABLED
377378
#define SUITESPARSE_TIME (omp_get_wtime ( ))
378-
#elif defined ( _POSIX_C_SOURCE )
379-
#if _POSIX_C_SOURCE >= 199309L
379+
#elif defined ( SUITESPARSE_HAVE_CLOCK_GETTIME )
380380
#define SUITESPARSE_TIMER_ENABLED
381381
#define SUITESPARSE_TIME (SuiteSparse_time ( ))
382-
#endif
383382
#else
384383
// No timer is available
385384
#define SUITESPARSE_TIME (0)

SuiteSparse_config/SuiteSparse_config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ void *SuiteSparse_free /* always returns NULL */
495495
tic [1] = 0 ;
496496
}
497497

498-
#else
498+
#else
499499

500500
/* ---------------------------------------------------------------------- */
501501
/* POSIX timer */
@@ -616,7 +616,7 @@ double SuiteSparse_hypot (double x, double y)
616616
r = x / y ;
617617
s = y * sqrt (1.0 + r*r) ;
618618
}
619-
}
619+
}
620620
return (s) ;
621621
}
622622

SuiteSparse_config/SuiteSparse_config.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,13 @@ int SuiteSparse_divcomplex
372372
// but other packages can themselves use OpenMP. In this case,
373373
// those packages should use omp_get_wtime() directly. This can
374374
// be done via the SUITESPARSE_TIME macro, defined below:
375+
#define SUITESPARSE_HAVE_CLOCK_GETTIME
375376
#if defined ( _OPENMP )
376377
#define SUITESPARSE_TIMER_ENABLED
377378
#define SUITESPARSE_TIME (omp_get_wtime ( ))
378-
#elif defined ( _POSIX_C_SOURCE )
379-
#if _POSIX_C_SOURCE >= 199309L
379+
#elif defined ( SUITESPARSE_HAVE_CLOCK_GETTIME )
380380
#define SUITESPARSE_TIMER_ENABLED
381381
#define SUITESPARSE_TIME (SuiteSparse_time ( ))
382-
#endif
383382
#else
384383
// No timer is available
385384
#define SUITESPARSE_TIME (0)

0 commit comments

Comments
 (0)