1 From e20a5d13935a41a856e8f71c49f2cc9d81b1d92c Mon Sep 17 00:00:00 2001
2 From: Changqing Li <changqing.li@windriver.com>
3 Date: Fri, 13 Nov 2020 17:07:00 +0800
4 Subject: [PATCH] support link against libatomic if no built-in atomic exist
7 | framework/lib/ppc/libframework.a(device.cpp.o): in function `std::__atomic_base<unsigned long long>::load(std::memory_order) const':
8 | /usr/include/c++/10.2.0/bits/atomic_base.h:426: undefined reference to `__atomic_load_8'
10 Upstream-Status: Submitted [https://github.com/KhronosGroup/Vulkan-Samples/pull/212]
12 Signed-off-by: Changqing Li <changqing.li@windriver.com>
15 bldsys/cmake/check_atomic.cmake | 62 +++++++++++++++++++++++++++++++++
16 framework/CMakeLists.txt | 4 +++
17 3 files changed, 67 insertions(+)
18 create mode 100644 bldsys/cmake/check_atomic.cmake
20 diff --git a/CMakeLists.txt b/CMakeLists.txt
21 index e72e829..466f51d 100644
24 @@ -42,6 +42,7 @@ endmacro(vulkan_samples_pch)
26 include(global_options)
27 include(sample_helper)
28 +include(check_atomic)
30 # Add third party libraries
31 add_subdirectory(third_party)
32 diff --git a/bldsys/cmake/check_atomic.cmake b/bldsys/cmake/check_atomic.cmake
34 index 0000000..6b47a7a
36 +++ b/bldsys/cmake/check_atomic.cmake
38 +# check weither need to link atomic library explicitly
39 +INCLUDE(CheckCXXSourceCompiles)
40 +INCLUDE(CheckLibraryExists)
42 +if(NOT DEFINED VULKAN_COMPILER_IS_GCC_COMPATIBLE)
43 + if(CMAKE_COMPILER_IS_GNUCXX)
44 + set(VULKAN_COMPILER_IS_GCC_COMPATIBLE ON)
46 + set(VULKAN_COMPILER_IS_GCC_COMPATIBLE OFF)
47 + elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
48 + set(VULKAN_COMPILER_IS_GCC_COMPATIBLE ON)
49 + elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel" )
50 + set(VULKAN_COMPILER_IS_GCC_COMPATIBLE ON)
54 +# Sometimes linking against libatomic is required for atomic ops, if
55 +# the platform doesn't support lock-free atomics.
57 +function(check_working_cxx_atomics varname)
58 + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
59 + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
60 + CHECK_CXX_SOURCE_COMPILES("
63 +std::atomic<short> y;
71 + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
72 +endfunction(check_working_cxx_atomics)
74 +function(check_working_cxx_atomics64 varname)
75 + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
76 + set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
77 + CHECK_CXX_SOURCE_COMPILES("
80 +std::atomic<uint64_t> x (0);
82 + uint64_t i = x.load(std::memory_order_relaxed);
87 + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
88 +endfunction(check_working_cxx_atomics64)
90 +set(NEED_LINK_ATOMIC OFF CACHE BOOL "weither need to link against atomic library")
91 +if(VULKAN_COMPILER_IS_GCC_COMPATIBLE)
92 + # check if non-64-bit atomics work without the library.
93 + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
94 + # check 64-bit atomics work without the library.
95 + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
96 + if (NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
97 + set(NEED_LINK_ATOMIC ON CACHE BOOL "weither need to link to atomic library" FORCE)
100 diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
101 index bf26786..322526e 100644
102 --- a/framework/CMakeLists.txt
103 +++ b/framework/CMakeLists.txt
104 @@ -412,6 +412,10 @@ target_link_libraries(${PROJECT_NAME}
108 +if(${NEED_LINK_ATOMIC})
109 + target_link_libraries(${PROJECT_NAME} atomic)
112 # Link platform specific libraries
114 target_link_libraries(${PROJECT_NAME} log android native_app_glue)