From 4f1dbb127a6a3439549ec7966cf799dd07aeec2e Mon Sep 17 00:00:00 2001 From: superfloh247 Date: Wed, 27 Dec 2023 22:19:56 +0100 Subject: [PATCH] Update CMakeLists.txt to fix MacOS build (#14160) Co-authored-by: sfan5 --- src/CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 082158c6e..3780e31b2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -316,9 +316,14 @@ endif() # On clang and gcc, some functionalities of std::atomic require -latomic. # See . -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" - OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(PLATFORM_LIBS ${PLATFORM_LIBS} atomic) +# Note that find_library does not reliably find it so we have to resort to this. +# Also, passing -latomic is not always the same as adding atomic to the library list. +include(CheckCSourceCompiles) +set(CMAKE_REQUIRED_LIBRARIES "-latomic") +check_c_source_compiles("int main(){}" HAVE_LINK_ATOMIC) +set(CMAKE_REQUIRED_LIBRARIES "") +if(HAVE_LINK_ATOMIC) + set(PLATFORM_LIBS ${PLATFORM_LIBS} "-latomic") endif() check_include_files(endian.h HAVE_ENDIAN_H)