From: rrahn <rene.rahn@fu-berlin.de>
Date: Mon, 10 Oct 2016 16:55:04 +0200
Subject: Fix static linking against pthread on some linux kernels.
--- seqan2.orig/manual/source/Infrastructure/Use/CustomBuildSystem.rst
+++ seqan2/manual/source/Infrastructure/Use/CustomBuildSystem.rst
@@ -45,6 +45,10 @@
 
 Add ``-lrt -lpthread`` to the compiler call.
 
+Note static linking against pthread might cause issues on some linux distributions.
+In this case you need to explicitly link against the whole archive like: ``-Wl,--whole-archive -lpthread -Wl,--no-whole-archive``.
+You can read more about this issue `here <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52590>`_.
+
 BSD
 ^^^
 
--- seqan2.orig/util/cmake/FindSeqAn.cmake
+++ seqan2/util/cmake/FindSeqAn.cmake
@@ -287,8 +287,13 @@
 
 # librt, libpthread -- implicit, on Linux only
 
-if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
-  set (SEQAN_LIBRARIES ${SEQAN_LIBRARIES} rt pthread)
+if ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") OR (${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD") OR (${CMAKE_SYSTEM_NAME} STREQUAL "GNU"))
+  set (SEQAN_LIBRARIES ${SEQAN_LIBRARIES} rt)
+  if ((CMAKE_CXX_FLAGS MATCHES "-static") OR (SEQAN_CXX_FLAGS MATCHES "-static") OR (CMAKE_EXE_LINKER_FLAGS MATCHES "-static"))
+    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
+  else ()
+    set (SEQAN_LIBRARIES ${SEQAN_LIBRARIES} pthread)
+  endif ()
 elseif ((${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") OR (${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD"))
   set (SEQAN_LIBRARIES ${SEQAN_LIBRARIES} pthread)
   set (SEQAN_DEFINITIONS ${SEQAN_DEFINITIONS} "-D_GLIBCXX_USE_C99=1")
