Commit 4b0c7ff2 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

cmake: explicitly link against libatomic when required

Summary:
When using clang with libstdc++ `-latomic` must be explicitly specified
as part of the link command in order to get some of the symbols required
for C++ std::atomic support.

The old autoconf-based build did have this check (added in github commit
60a5636b, D2519083).  However this check was missing from the
CMake-based build.

Reviewed By: igorsugak

Differential Revision: D10405960

fbshipit-source-id: 37291edc5a387e2e966ece79241aa00312194cbd
parent 2d6a8fcb
......@@ -151,6 +151,36 @@ if (FOLLY_HAVE_ELF_H AND FOLLY_HAVE_BACKTRACE AND LIBDWARF_FOUND)
endif()
message(STATUS "Setting FOLLY_USE_SYMBOLIZER: ${FOLLY_USE_SYMBOLIZER}")
# Using clang with libstdc++ requires explicitly linking against libatomic
check_cxx_source_compiles("
#include <atomic>
int main(int argc, char** argv) {
struct Test { int val; };
std::atomic<Test> s;
return static_cast<int>(s.is_lock_free());
}"
FOLLY_CPP_ATOMIC_BUILTIN
)
if(NOT FOLLY_CPP_ATOMIC_BUILTIN)
list(APPEND CMAKE_REQUIRED_LIBRARIES atomic)
list(APPEND FOLLY_LINK_LIBRARIES atomic)
check_cxx_source_compiles("
#include <atomic>
int main(int argc, char** argv) {
struct Test { int val; };
std::atomic<Test> s2;
return static_cast<int>(s2.is_lock_free());
}"
FOLLY_CPP_ATOMIC_WITH_LIBATOMIC
)
if (NOT FOLLY_CPP_ATOMIC_WITH_LIBATOMIC)
message(
FATAL_ERROR "unable to link C++ std::atomic code: you may need \
to install GNU libatomic"
)
endif()
endif()
option(
FOLLY_ASAN_ENABLED
"Build folly with Address Sanitizer enabled."
......
......@@ -67,7 +67,6 @@ set(
)
include(GNUInstallDirs)
include(folly-deps) # Find the required packages
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
include(FollyCompilerMSVC)
......@@ -76,6 +75,7 @@ else()
endif()
include(FollyFunctions)
include(folly-deps) # Find the required packages
include(FollyConfigChecks)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/CMake/folly-config.h.cmake
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment