File: SuiteSparseAtomic.cmake

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (62 lines) | stat: -rw-r--r-- 2,192 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
#-------------------------------------------------------------------------------
# GraphBLAS/cmake_modules/SuiteSparseAtomic.cmake
#-------------------------------------------------------------------------------

# Copyright (c) 2022, Timothy A. Davis.  All Rights Reserved.
# SPDX-License-Identifier: BSD-3-clause

#-------------------------------------------------------------------------------

# determine if -latomic must be linked

include ( CheckCSourceCompiles )

set ( atomic_source
"
#if defined ( _MSC_VER ) && \
  !(defined ( __INTEL_CLANG_COMPILER ) || defined ( __INTEL_COMPILER ) || \
    defined ( __clang__ ) || defined ( __GNUC__ ))
    // MS Visual Studio compiler.  No need to check for atomics; GraphBLAS
    // uses MSC-specific methods.  (See Source/GB_atomics.h)
    int main (void) { return (0) ; }
#else
    // gcc, clang, icx, xlc, etc: see if -latomic is required
    #include <stdatomic.h>
    #include <stdint.h>
    int main (void)
    {
        _Atomic uint8_t t8 = 0 ;
        uint8_t e8 = 0, d8 = 0 ;
        atomic_compare_exchange_weak (&t8, &e8, d8) ;
        _Atomic uint16_t t16 = 0 ;
        uint16_t e16 = 0, d16 = 0 ;
        atomic_compare_exchange_weak (&t16, &e16, d16) ;
        _Atomic uint32_t t32 = 0 ;
        uint32_t e32 = 0, d32 = 0 ;
        atomic_compare_exchange_weak (&t32, &e32, d32) ;
        _Atomic uint64_t t64 = 0 ;
        uint64_t e64 = 0, d64 = 0 ;
        atomic_compare_exchange_weak (&t64, &e64, d64) ;
        return (0) ;
    }
#endif
" )

check_c_source_compiles ( "${atomic_source}" TEST_FOR_STDATOMIC )

if ( NOT TEST_FOR_STDATOMIC )
    # try with -latomic
    set ( CMAKE_REQUIRED_LIBRARIES "atomic" )
    check_c_source_compiles ( "${atomic_source}" TEST_FOR_STDATOMIC_WITH_LIBATOMIC )
    if ( NOT TEST_FOR_STDATOMIC_WITH_LIBATOMIC )
        # fails with -latomic
        message ( FATAL_ERROR "ANSI C11 atomics: failed" )
    endif ( )
    # source compiles but -latomic is required
    set ( LIBATOMIC_REQUIRED true )
    message ( STATUS "ANSI C11 atomics: OK, but -latomic required" )
else ( )
    set ( LIBATOMIC_REQUIRED false )
    message ( STATUS "ANSI C11 atomics: OK. -latomic not needed" )
endif ( )