File: StdAtomic.cmake

package info (click to toggle)
ccache 4.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,192 kB
  • sloc: cpp: 47,336; asm: 28,570; sh: 8,709; ansic: 5,357; python: 685; perl: 68; makefile: 23
file content (42 lines) | stat: -rw-r--r-- 1,373 bytes parent folder | download
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
# Check if std::atomic needs -latomic

set(LIBATOMIC_STATIC_PATH "" CACHE PATH "Directory containing static libatomic.a")

include(CheckCXXSourceCompiles)

set(
  check_std_atomic_source_code
  [=[
    #include <atomic>
    int main()
    {
      std::atomic<long long> x;
      ++x;
      (void)x.load();
      return 0;
    }
  ]=])

check_cxx_source_compiles("${check_std_atomic_source_code}" std_atomic_without_libatomic)

if(NOT std_atomic_without_libatomic)
  set(CMAKE_REQUIRED_LIBRARIES atomic)
  check_cxx_source_compiles("${check_std_atomic_source_code}" std_atomic_with_libatomic)
  set(CMAKE_REQUIRED_LIBRARIES)
  if(NOT std_atomic_with_libatomic)
    message(FATAL_ERROR "Toolchain doesn't support std::atomic with nor without -latomic")
  else()
    if(STATIC_LINK)
      find_library(ATOMIC_STATIC NAMES libatomic.a PATHS /usr/lib /usr/local/lib ${LIBATOMIC_STATIC_PATH} NO_DEFAULT_PATH)
      if(ATOMIC_STATIC)
        message(STATUS "Linking static libatomic: ${ATOMIC_STATIC}")
        target_link_libraries(standard_settings INTERFACE ${ATOMIC_STATIC})
      else()
        message(WARNING "STATIC_LINK is set but static libatomic not found; falling back to -latomic")
        target_link_libraries(standard_settings INTERFACE atomic)
      endif()
    else()
      target_link_libraries(standard_settings INTERFACE atomic)
    endif()
  endif()
endif()