Check for rt and pthread libraries before linking

This fixes building on Android which does not have separate librt
or libpthread libraries.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
This commit is contained in:
Fredrik Fornwall 2017-01-24 23:01:16 +01:00 committed by Roger A. Light
parent 2c92d3b837
commit 35cc1eb21e
2 changed files with 15 additions and 3 deletions

View File

@ -7,7 +7,12 @@ if (${WITH_THREADING} STREQUAL ON)
set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x86\\pthreadVC2.lib)
set (PTHREAD_INCLUDE_DIR C:\\pthreads\\Pre-built.2\\include)
else (WIN32)
set (PTHREAD_LIBRARIES pthread)
find_library(LIBPTHREAD pthread)
if (LIBPTHREAD)
set (PTHREAD_LIBRARIES pthread)
else (LIBPTHREAD)
set (PTHREAD_LIBRARIES "")
endif()
set (PTHREAD_INCLUDE_DIR "")
endif (WIN32)
else (${WITH_THREADING} STREQUAL ON)
@ -44,7 +49,10 @@ add_library(libmosquitto SHARED
set (LIBRARIES ${OPENSSL_LIBRARIES} ${PTHREAD_LIBRARIES})
if (UNIX AND NOT APPLE)
set (LIBRARIES ${LIBRARIES} rt)
find_library(LIBRT rt)
if (LIBRT)
set (LIBRARIES ${LIBRARIES} rt)
endif (LIBRT)
endif (UNIX AND NOT APPLE)
if (WIN32)

View File

@ -86,7 +86,11 @@ if (UNIX)
if (APPLE)
set (MOSQ_LIBS ${MOSQ_LIBS} dl m)
else (APPLE)
set (MOSQ_LIBS ${MOSQ_LIBS} rt dl m)
set (MOSQ_LIBS ${MOSQ_LIBS} dl m)
find_library(LIBRT rt)
if (LIBRT)
set (MOSQ_LIBS ${MOSQ_LIBS} rt)
endif (LIBRT)
endif (APPLE)
endif (UNIX)