build: do not unconditionally link libpthread
authorJo-Philipp Wich <jo@mein.io>
Fri, 17 Feb 2017 17:19:53 +0000 (18:19 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 17 Feb 2017 17:19:53 +0000 (18:19 +0100)
Some environments, e.g. musl libc based ones, do not have a dedicated
libpthread, so only link it if it exists.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
src/CMakeLists.txt

index 5e1deca866597346f4615032ed5d36d65f46dd79..c4198667ec186bb41719b53ceff14c6cb5ed5f8c 100644 (file)
@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 2.6)
 
 PROJECT(opkg-cl C)
 
+INCLUDE(CheckLibraryExists)
+
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libopkg)
 LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libopkg ${CMAKE_CURRENT_SOURCE_DIR}/../libbb)
 
@@ -11,7 +13,10 @@ ELSE()
        FIND_LIBRARY(ubox NAMES ubox)
 ENDIF()
 
-FIND_LIBRARY(pthread NAMES pthread)
-
 ADD_EXECUTABLE(opkg-cl opkg-cl.c)
-TARGET_LINK_LIBRARIES(opkg-cl opkg bb ${ubox} ${pthread})
+TARGET_LINK_LIBRARIES(opkg-cl opkg bb ${ubox})
+
+CHECK_LIBRARY_EXISTS(pthread pthread_create "" NEED_PTHREAD)
+IF(NEED_PTHREAD)
+       TARGET_LINK_LIBRARIES(opkg-cl pthread)
+ENDIF()