From 780bac671f45ab2c5ef15c9e7d6dff0031673e28 Mon Sep 17 00:00:00 2001 From: David Adam Date: Fri, 20 Dec 2019 23:00:06 +0800 Subject: [PATCH] cmake: add -latomic on platforms that need it for 64-bit atomic operations Closes #5865. --- CMakeLists.txt | 2 +- cmake/ConfigureChecks.cmake | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32cf3ac17..2f1560ecf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,7 +172,7 @@ ADD_LIBRARY(fishlib STATIC ${FISH_SRCS}) TARGET_SOURCES(fishlib PRIVATE ${FISH_HEADERS}) TARGET_LINK_LIBRARIES(fishlib ${CURSES_LIBRARY} ${CURSES_EXTRA_LIBRARY} Threads::Threads ${CMAKE_DL_LIBS} - ${PCRE2_LIB} ${Intl_LIBRARIES}) + ${PCRE2_LIB} ${Intl_LIBRARIES} ${ATOMIC_LIBRARY}) # Define fish. ADD_EXECUTABLE(fish src/fish.cpp) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 3bc0f41c3..69dbb17b0 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -187,3 +187,16 @@ int main () { ) FIND_PROGRAM(SED sed) + +# https://github.com/fish-shell/fish-shell/issues/5865 +CHECK_CXX_SOURCE_COMPILES(" +#include +struct big { int foo[64]; }; +std::atomic x; +int main() { + return x.load().foo[13]; +}" +LIBATOMIC_NOT_NEEDED) +IF (NOT LIBATOMIC_NOT_NEEDED) + SET(ATOMIC_LIBRARY "atomic") +ENDIF()