aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-03-29 10:33:49 -0700
committerGarrett D'Amore <garrett@damore.org>2020-03-29 10:33:49 -0700
commitff99ee51b34268f00aab3efd858e0798e92417c3 (patch)
tree2ef6355b4a141383d1bf8ba8055cfc543ae0a671
parent86cfc4c140d4b5a345e5da6d504c814f24a0d53f (diff)
downloadnng-ff99ee51b34268f00aab3efd858e0798e92417c3.tar.gz
nng-ff99ee51b34268f00aab3efd858e0798e92417c3.tar.bz2
nng-ff99ee51b34268f00aab3efd858e0798e92417c3.zip
fixes #1225 atomic check operation fails with android cross toolchain
-rw-r--r--CMakeLists.txt16
-rw-r--r--cmake/CheckAtomicLib.cmake70
2 files changed, 9 insertions, 77 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 10185c8e..2b78d4e0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -155,13 +155,6 @@ if (NOT NNG_SANITIZER STREQUAL "none")
set(NNG_SANITIZER_FLAGS "-fsanitize=${NNG_SANITIZER}")
endif ()
-include(CheckAtomicLib)
-CheckAtomicLib()
-if (NOT HAVE_C_ATOMICS_WITHOUT_LIB AND HAVE_C_ATOMICS_WITH_LIB)
- list(APPEND NNG_LIBS "atomic")
-endif ()
-
-
if (NNG_ENABLE_COVERAGE)
# NB: This only works for GCC and Clang 3.0 and newer. If your stuff
# is older than that, you will need to find something newer. For
@@ -327,6 +320,15 @@ else ()
nng_check_lib(nsl gethostbyname NNG_HAVE_LIBNSL)
nng_check_lib(socket socket NNG_HAVE_LIBSOCKET)
+ # GCC needs libatomic on some architectures (e.g. ARM) because the
+ # underlying architecture may lack the necessary atomic primitives.
+ # One hopes that the libatomic implementation is superior to just using
+ # a pthread mutex. The symbol chosen here was identified from GCC's
+ # libatomic map file.
+ #
+ # Arguably when using clang, compiler-rt might be better.
+ nng_check_lib(__atomic_load_1 atomic NNG_HAVE_LIBATOMIC)
+
nng_check_sym(AF_UNIX sys/socket.h NNG_HAVE_UNIX_SOCKETS)
nng_check_sym(backtrace_symbols_fd execinfo.h NNG_HAVE_BACKTRACE)
nng_check_struct_member(msghdr msg_control sys/socket.h NNG_HAVE_MSG_CONTROL)
diff --git a/cmake/CheckAtomicLib.cmake b/cmake/CheckAtomicLib.cmake
deleted file mode 100644
index 06979305..00000000
--- a/cmake/CheckAtomicLib.cmake
+++ /dev/null
@@ -1,70 +0,0 @@
-#
-# Copyright 2020 Kenneth Haase <kh@beingmeta.com>
-#
-# This software is supplied under the terms of the MIT License, a
-# copy of which should be located in the distribution where this
-# file was obtained (LICENSE.txt). A copy of the license may also be
-# found online at https://opensource.org/licenses/MIT.
-#
-
-# atomic builtins are required for threading support.
-
-INCLUDE(CheckIncludeFiles)
-INCLUDE(CheckCSourceCompiles)
-INCLUDE(CheckLibraryExists)
-
-# Sometimes linking against libatomic is required for atomic ops, if
-# the platform doesn't support lock-free atomics.
-
-function(check_c_atomics_without_lib varname)
- CHECK_C_SOURCE_COMPILES("
-#include <stdatomic.h>
-int main() {
- _Atomic long long x;
- atomic_store(&x,3);
- long long y = atomic_load(&x);
- atomic_fetch_add(&x,12);
- long long z = atomic_load(&x);
-
- return x;
-}
-" ${varname})
-endfunction(check_c_atomics_without_lib)
-
-function(check_c_atomics_with_lib varname)
- SET(SAVED_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
- list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
- CHECK_C_SOURCE_COMPILES("
-#include <stdatomic.h>
-int main() {
- _Atomic long long x;
- atomic_store(&x,3);
- long long y = atomic_load(&x);
- atomic_fetch_add(&x,12);
- long long z = atomic_load(&x);
-
- return x;
-}
-" ${varname})
- SET(CMAKE_REQUIRED_LIBRARIES "${SAVED_CMAKE_REQUIRED_LIBRARIES}")
-endfunction(check_c_atomics_with_lib)
-
-macro (CheckAtomicLib)
- # First check if atomics work without the library.
- if(MSVC)
- set(HAVE_C_ATOMICS_WITHOUT_LIB True)
- else()
- check_c_atomics_without_lib(HAVE_C_ATOMICS_WITHOUT_LIB)
- if(NOT HAVE_C_ATOMICS_WITHOUT_LIB)
- check_library_exists(atomic __atomic_fetch_add_8 "" HAVE_LIBATOMIC)
- if( HAVE_LIBATOMIC )
- check_c_atomics_with_lib(HAVE_C_ATOMICS_WITH_LIB)
- if (NOT HAVE_C_ATOMICS_WITH_LIB)
- message(FATAL_ERROR "Host compiler must support atomic types!")
- endif()
- else()
- message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
- endif()
- endif()
- endif()
-endmacro (CheckAtomicLib)