Skip to content

Commit

Permalink
add libatomic if clang and pthreads are used (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkaminsk authored and BenKaufmann committed Aug 25, 2017
1 parent 4683d3c commit fe3e176
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ if (CLASP_BUILD_WITH_THREADS)
# some versions of findThreads will fail if C is not enabled
enable_language(C)
find_package(Threads REQUIRED)

# Add libatomic if necessary
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_USE_PTHREADS_INIT)
include (CheckCXXSourceCompiles)
set (OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set (OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
list(APPEND CMAKE_REQUIRED_FLAGS "-std=c++11")
list(APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads)
check_cxx_source_compiles("
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x (0);
int main() {
uint64_t i = x.load(std::memory_order_relaxed);
return 0;
}
" CLASP_HAS_WORKING_LIBATOMIC)
set (CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
set (CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
if (NOT CLASP_HAS_WORKING_LIBATOMIC)
check_library_exists(atomic __atomic_fetch_add_4 "" CLASP_HAS_LIBATOMIC)
if (CLASP_HAS_LIBATOMIC)
set_property(TARGET Threads::Threads APPEND PROPERTY INTERFACE_LINK_LIBRARIES "atomic")
endif()
endif()
endif()
endif()

# Check for and optionally build external dependency
Expand Down

0 comments on commit fe3e176

Please sign in to comment.