From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <tarantool-patches-bounce@freelists.org>
Received: from localhost (localhost [127.0.0.1])
	by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id E822E2F6BD
	for <tarantool-patches@freelists.org>; Sat,  3 Nov 2018 00:29:43 -0400 (EDT)
Received: from turing.freelists.org ([127.0.0.1])
	by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id WORW05fbc4m7 for <tarantool-patches@freelists.org>;
	Sat,  3 Nov 2018 00:29:43 -0400 (EDT)
Received: from smtp5.mail.ru (smtp5.mail.ru [94.100.179.24])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 99B732F7BB
	for <tarantool-patches@freelists.org>; Sat,  3 Nov 2018 00:29:43 -0400 (EDT)
From: Alexander Turenko <alexander.turenko@tarantool.org>
Subject: [tarantool-patches] [PATCH 3/3] Make libdl.so optional (for FreeBSD prior to 11.2)
Date: Sat,  3 Nov 2018 07:29:34 +0300
Message-Id: <e6fd17208e49c9ae7051defe3c36087102647ec3.1541219191.git.alexander.turenko@tarantool.org>
In-Reply-To: <cover.1541219191.git.alexander.turenko@tarantool.org>
References: <cover.1541219191.git.alexander.turenko@tarantool.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Sender: tarantool-patches-bounce@freelists.org
Errors-to: tarantool-patches-bounce@freelists.org
Reply-To: tarantool-patches@freelists.org
List-help: <mailto:ecartis@freelists.org?Subject=help>
List-unsubscribe: <tarantool-patches-request@freelists.org?Subject=unsubscribe>
List-software: Ecartis version 1.0.0
List-Id: tarantool-patches <tarantool-patches.freelists.org>
List-subscribe: <tarantool-patches-request@freelists.org?Subject=subscribe>
List-owner: <mailto:>
List-post: <mailto:tarantool-patches@freelists.org>
List-archive: <http://www.freelists.org/archives/tarantool-patches>
To: Kirill Yukhin <kyukhin@tarantool.org>
Cc: Alexander Turenko <alexander.turenko@tarantool.org>, tarantool-patches@freelists.org

FreeBSD 10.4 has no libdl.so.

Fixes #3750.
---
 cmake/FindCURL.cmake | 21 +++++++++++++++++----
 src/CMakeLists.txt   |  9 ++++++++-
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/cmake/FindCURL.cmake b/cmake/FindCURL.cmake
index e2e2c6f20..e13b6cde4 100644
--- a/cmake/FindCURL.cmake
+++ b/cmake/FindCURL.cmake
@@ -24,9 +24,15 @@ else()
     set(NGHTTP2_LIB_NAME nghttp2)
 endif()
 
-# Curl may require nghttp library, search for it and add to dependicies if
-# found
+# Always links pthread and dl dynamically.
+set(PTHREAD_LIB_NAME pthread)
+set(DL_LIB_NAME dl)
+
+# Curl may be linked with optional or target-dependent libraries,
+# search for them and add to dependicies if found.
 find_library(NGHTTP2_LIBRARY NAMES ${NGHTTP2_LIB_NAME})
+find_library(PTHREAD_LIBRARY NAMES ${PTHREAD_LIB_NAME})
+find_library(DL_LIBRARY NAMES ${DL_LIB_NAME})
 
 if(DEFINED CURL_ROOT)
     set(CURL_FIND_OPTS NO_CMAKE NO_CMAKE_SYSTEM_PATH)
@@ -79,14 +85,21 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL
 
 if(CURL_FOUND)
   set(CURL_LIBRARIES ${CURL_LIBRARY})
+  set(CURL_LIBRARIES ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES})
   if(BUILD_STATIC)
-    # in case of a static build we have to add curl dependencies
+    # In case of a static build we have to add curl dependencies.
     if(NOT "${NGHTTP2_LIBRARY}" STREQUAL "NGHTTP2_LIBRARY-NOTFOUND")
       set(CURL_LIBRARIES ${CURL_LIBRARIES} ${NGHTTP2_LIBRARY})
     endif()
+    if(NOT "${PTHREAD_LIBRARY}" STREQUAL "PTHREAD_LIBRARY-NOTFOUND")
+      set(CURL_LIBRARIES ${CURL_LIBRARIES} ${PTHREAD_LIBRARY})
+    endif()
+    if(NOT "${DL_LIBRARY}" STREQUAL "DL_LIBRARY-NOTFOUND")
+      set(CURL_LIBRARIES ${CURL_LIBRARIES} ${DL_LIBRARY})
+    endif()
   endif()
   set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
-  set(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} pthread dl)
+  set(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBRARIES})
   set(CMAKE_REQUIRED_INCLUDES ${CURL_INCLUDE_DIRS})
   check_c_source_runs("
     #include <curl/curl.h>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d296348a3..ceff96ec0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -67,7 +67,14 @@ add_custom_target(ragel
     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
     COMMAND ragel -G2 src/uri.rl -o src/uri.c)
 
-set (generic_libraries pthread dl)
+# There is no libdl.so on FreeBSD prior to 11.2.
+#
+# Always links pthread and dl dynamically.
+set(generic_libraries pthread)
+find_library(DL_LIBRARY NAMES dl)
+if(NOT "${DL_LIBRARY}" STREQUAL "DL_LIBRARY-NOTFOUND")
+    set(generic_libraries ${generic_libraries} dl)
+endif()
 
 set (core_sources
      diag.c
-- 
2.19.1