Skip to content
Snippets Groups Projects
Commit ebf2362b authored by Sprite's avatar Sprite
Browse files

Pull Request #602: cmake: fix incorrectly linking to libatomic on macOS

parents fe6676f2 619a2d89
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,10 @@ find_package(Doxygen) ...@@ -49,6 +49,10 @@ find_package(Doxygen)
option (OPENDHT_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND}) option (OPENDHT_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
# Dependencies # Dependencies
if (NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
link_libraries (atomic)
endif ()
list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
if (NOT MSVC) if (NOT MSVC)
set (THREADS_PREFER_PTHREAD_FLAG TRUE) set (THREADS_PREFER_PTHREAD_FLAG TRUE)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
INCLUDE(CheckCXXSourceCompiles) INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckLibraryExists) INCLUDE(CheckLibraryExists)
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/DetermineGCCCompatible.cmake")
# Sometimes linking against libatomic is required for atomic ops, if # Sometimes linking against libatomic is required for atomic ops, if
# the platform doesn't support lock-free atomics. # the platform doesn't support lock-free atomics.
...@@ -32,6 +33,7 @@ function(check_working_cxx_atomics64 varname) ...@@ -32,6 +33,7 @@ function(check_working_cxx_atomics64 varname)
std::atomic<uint64_t> x (0); std::atomic<uint64_t> x (0);
int main() { int main() {
uint64_t i = x.load(std::memory_order_relaxed); uint64_t i = x.load(std::memory_order_relaxed);
(void)i;
return 0; return 0;
} }
" ${varname}) " ${varname})
...@@ -39,9 +41,10 @@ int main() { ...@@ -39,9 +41,10 @@ int main() {
endfunction(check_working_cxx_atomics64) endfunction(check_working_cxx_atomics64)
# This isn't necessary on MSVC, so avoid command-line switch annoyance # Check for (non-64-bit) atomic operations.
# by only running on GCC-like hosts. if(MSVC)
if (LLVM_COMPILER_IS_GCC_COMPATIBLE) set(HAVE_CXX_ATOMICS_WITHOUT_LIB True)
elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL")
# First check if atomics work without the library. # First check if atomics work without the library.
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
# If not, check if the library exists, and atomics work with it. # If not, check if the library exists, and atomics work with it.
...@@ -57,10 +60,9 @@ endif() ...@@ -57,10 +60,9 @@ endif()
# Check for 64 bit atomic operations. # Check for 64 bit atomic operations.
if(MSVC) if(MSVC)
set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
else() elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL")
# First check if atomics work without the library.
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
endif()
# If not, check if the library exists, and atomics work with it. # If not, check if the library exists, and atomics work with it.
if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
...@@ -69,6 +71,7 @@ if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) ...@@ -69,6 +71,7 @@ if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!")
endif() endif()
endif() endif()
endif()
## TODO: This define is only used for the legacy atomic operations in ## TODO: This define is only used for the legacy atomic operations in
## llvm's Atomic.h, which should be replaced. Other code simply ## llvm's Atomic.h, which should be replaced. Other code simply
......
# Determine if the compiler has GCC-compatible command-line syntax.
if(NOT DEFINED LLVM_COMPILER_IS_GCC_COMPATIBLE)
if(CMAKE_COMPILER_IS_GNUCXX)
set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON)
elseif( MSVC )
set(LLVM_COMPILER_IS_GCC_COMPATIBLE OFF)
elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON)
elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel" )
set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON)
endif()
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment