libdl (for dlopen, dlsym) is part of (or an extention to) the
standard library/linker on many platforms.  It doesn't currently
have support in CMake, though there are a few independent
implementations shown up by Google.  Given that there are
several upstreams and that it's a basic component of several
different POSIX systems, having support in CMake would be quite
beneficial.

I've tested the attached patch on FreeBSD, Linux and MacOS X.


Kind regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux    http://people.debian.org/~rleigh/
 `. `'   schroot and sbuild  http://alioth.debian.org/projects/buildd-tools
   `-    GPG Public Key      F33D 281D 470A B443 6756 147C 07B3 C8BC 4083 E800
>From 106be3be180fa9a09bf680758a725c13651a4e22 Mon Sep 17 00:00:00 2001
From: Roger Leigh <[email protected]>
Date: Wed, 19 Nov 2014 17:36:00 +0000
Subject: [PATCH] FindLibDl: New module to find libdl

---
 Help/manual/cmake-modules.7.rst    |  1 +
 Help/module/FindLibDl.rst          |  1 +
 Help/release/dev/add-FindLibDl.rst |  4 +++
 Modules/FindLibDl.cmake            | 65 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+)
 create mode 100644 Help/module/FindLibDl.rst
 create mode 100644 Help/release/dev/add-FindLibDl.rst
 create mode 100644 Modules/FindLibDl.cmake

diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst
index 083ed7a..a9d3a1b 100644
--- a/Help/manual/cmake-modules.7.rst
+++ b/Help/manual/cmake-modules.7.rst
@@ -129,6 +129,7 @@ All Modules
    /module/FindLAPACK
    /module/FindLATEX
    /module/FindLibArchive
+   /module/FindLibDl
    /module/FindLibLZMA
    /module/FindLibXml2
    /module/FindLibXslt
diff --git a/Help/module/FindLibDl.rst b/Help/module/FindLibDl.rst
new file mode 100644
index 0000000..1830a1c
--- /dev/null
+++ b/Help/module/FindLibDl.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLibDl.cmake
diff --git a/Help/release/dev/add-FindLibDl.rst b/Help/release/dev/add-FindLibDl.rst
new file mode 100644
index 0000000..3a1a7c4
--- /dev/null
+++ b/Help/release/dev/add-FindLibDl.rst
@@ -0,0 +1,4 @@
+add-FindLibDl
+-------------
+
+* The :module:`FindLibDl` module was added to find the libdl library.
diff --git a/Modules/FindLibDl.cmake b/Modules/FindLibDl.cmake
new file mode 100644
index 0000000..bd02a35
--- /dev/null
+++ b/Modules/FindLibDl.cmake
@@ -0,0 +1,65 @@
+#.rst:
+# FindLibDl
+# ---------
+#
+# Find the libdl headers and libraries.
+#
+# This module reports information about the libdl library used to
+# load and introspect libraries and loadable modules on platforms
+# using ELF- and Mach-O-linkers.
+#
+#   LibDl_FOUND - true if the libdl headers and libraries were found
+#   LibDl_INCLUDE_DIRS - the directory containing the libdl headers
+#   LibDl_LIBRARIES - libdl libraries to be linked
+#
+# The following cache variables may also be set::
+#
+#   LibDl_INCLUDE_DIR - the directory containing the libdl headers
+#   LibDl_LIBRARY - the libdl library (if any)
+#
+# .. note::
+#   On some platforms, such as FreeBSD, the libdl functions are
+#   present in the C standard library and libdl is not required.
+#   ``LibDl_LIBRARIES`` will be empty in this case.
+
+
+# Written by Roger Leigh <[email protected]>
+
+#=============================================================================
+# Copyright 2014 Roger Leigh <[email protected]>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+# Find include directory
+find_path(LibDl_INCLUDE_DIR
+          NAMES "dlfcn.h"
+          DOC "libdl include directory")
+mark_as_advanced(LibDl_INCLUDE_DIR)
+
+# Find all LibDl libraries
+find_library(LibDl_LIBRARY "dl"
+  DOC "libdl libraries (if not in the C library)")
+mark_as_advanced(LibDl_LIBRARY)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibDl
+                                  FOUND_VAR LibDl_FOUND
+                                  REQUIRED_VARS LibDl_INCLUDE_DIR
+                                  FAIL_MESSAGE "Failed to find libdl")
+
+if(LibDl_FOUND)
+  set(LibDl_INCLUDE_DIRS "${LibDl_INCLUDE_DIR}")
+  if(LibDl_LIBRARY)
+    set(LibDl_LIBRARIES "${LibDl_LIBRARY}")
+  else()
+    unset(LibDl_LIBRARIES)
+  endif()
+endif()
-- 
2.1.2

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to