Skip to content

Commit

Permalink
Fix undefined reference to `__atomic_fetch_add_8' (#46)
Browse files Browse the repository at this point in the history
* Find libatomic

* Improve libatomic detection

* Use -std=c++11  to compile <atomic>

* Refactor libatomic detection

* Changes in version 6.3

* Use CMAKE_REQUIRED_FLAGS instead of CMAKE_REQUIRED_DEFINITIONS
  • Loading branch information
kimwalisch authored Nov 12, 2017
1 parent 6c74531 commit 5cf9141
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
31 changes: 29 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,39 @@ if(no_fallthrough)
set_source_files_properties(src/primesieve/EratSmall.cpp PROPERTIES COMPILE_FLAGS -Wno-implicit-fallthrough)
endif()

# Check if libatomic is needed #######################################

include(CheckCXXSourceCompiles)

set(CMAKE_OLD_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX11_STANDARD_COMPILE_OPTION})

check_cxx_source_compiles("
#include <atomic>
int main() {
std::atomic<int> x;
x = 1;
x--;
return x;
}"
have_atomic)

set(CMAKE_REQUIRED_FLAGS ${CMAKE_OLD_FLAGS})

if(NOT have_atomic)
find_library(ATOMIC NAMES atomic libatomic.so libatomic.so.1)
if(ATOMIC)
set(LIBATOMIC ${ATOMIC})
message(STATUS "Found libatomic: TRUE")
endif()
endif()

# libprimesieve ######################################################

add_library(libprimesieve ${LIB_SRC})
set_target_properties(libprimesieve PROPERTIES OUTPUT_NAME primesieve)
find_package(Threads REQUIRED)
target_link_libraries(libprimesieve Threads::Threads)
target_link_libraries(libprimesieve Threads::Threads ${LIBATOMIC})

target_include_directories(libprimesieve PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -83,7 +110,7 @@ install(TARGETS libprimesieve
if(BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS)
add_library(static_libprimesieve STATIC ${LIB_SRC})
set_target_properties(static_libprimesieve PROPERTIES OUTPUT_NAME primesieve)
target_link_libraries(static_libprimesieve Threads::Threads)
target_link_libraries(static_libprimesieve Threads::Threads ${LIBATOMIC})

target_include_directories(static_libprimesieve PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Changes in version 6.3, 12/11/2017
==================================

This is a minor new release, the API and ABI are
backwards compatible.

* test/ilog2.cpp: Fix Linux i386 bug.
* test/floorPower2.cpp: Fix Linux i386 bug.
* CMakeLists.txt: Link against libatomic if needed.
* CMakeLists.txt: Add Debian Multiarch support.

Changes in version 6.2, 12/10/2017
==================================

Expand Down

0 comments on commit 5cf9141

Please sign in to comment.