[mlpack-git] master: Add pkg-config support. (31eb9b0)

gitdub at mlpack.org gitdub at mlpack.org
Tue Sep 13 10:52:49 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/12a10f428c07dd409d52684932655842a8eddb29...8d6d3919faf8596778b6db8c8865262fec9c394b

>---------------------------------------------------------------

commit 31eb9b0564ffc2014ff629e6f95b3d5933a0f6d3
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Sep 13 10:52:49 2016 -0400

    Add pkg-config support.


>---------------------------------------------------------------

31eb9b0564ffc2014ff629e6f95b3d5933a0f6d3
 CMake/GeneratePkgConfig.cmake | 27 ++++++++++++++++++++++
 CMake/mlpack.pc.in            | 11 +++++++++
 CMakeLists.txt                | 54 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+)

diff --git a/CMake/GeneratePkgConfig.cmake b/CMake/GeneratePkgConfig.cmake
new file mode 100644
index 0000000..7a04040
--- /dev/null
+++ b/CMake/GeneratePkgConfig.cmake
@@ -0,0 +1,27 @@
+# As input the following variables should be set:
+#
+#   MLPACK_SOURCE_DIR: directory containing mlpack sources.
+#
+# And our goal in this file is to generate/configure mlpack.pc.
+
+# First, we need to extract the version string.
+if (NOT EXISTS "${MLPACK_SOURCE_DIR}/mlpack/core/util/version.hpp")
+  message(FATAL_ERROR "Cannot open "
+      "${MLPACK_SOURCE_DIR}/mlpack/core/util/version.hpp to extract version!")
+endif ()
+
+file(READ "${MLPACK_SOURCE_DIR}/mlpack/core/util/version.hpp"
+    VERSION_HPP_CONTENTS)
+string(REGEX REPLACE ".*#define MLPACK_VERSION_MAJOR ([0-9]+).*" "\\1"
+    MLPACK_VERSION_MAJOR "${VERSION_HPP_CONTENTS}")
+string(REGEX REPLACE ".*#define MLPACK_VERSION_MINOR ([0-9]+).*" "\\1"
+    MLPACK_VERSION_MINOR "${VERSION_HPP_CONTENTS}")
+string(REGEX REPLACE ".*#define MLPACK_VERSION_PATCH [\"]?([0-9x]+)[\"]?.*" "\\1"
+    MLPACK_VERSION_PATCH "${VERSION_HPP_CONTENTS}")
+
+set(MLPACK_VERSION_STRING
+    "${MLPACK_VERSION_MAJOR}.${MLPACK_VERSION_MINOR}.${MLPACK_VERSION_PATCH}")
+
+configure_file(
+    ${CMAKE_BINARY_DIR}/CMake/mlpack.pc.in.partial
+    ${CMAKE_BINARY_DIR}/lib/pkgconfig/mlpack.pc @ONLY)
diff --git a/CMake/mlpack.pc.in b/CMake/mlpack.pc.in
new file mode 100644
index 0000000..7aff792
--- /dev/null
+++ b/CMake/mlpack.pc.in
@@ -0,0 +1,11 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${exec_prefix}/include
+
+Name: mlpack
+Description: scalable C++ machine learning library
+URL: http://www.mlpack.org/
+Version: @MLPACK_VERSION_STRING@
+Cflags: @MLPACK_INCLUDE_DIRS_STRING@
+Libs: @MLPACK_LIBRARIES_STRING@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ffab60a..45be0b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -410,3 +410,57 @@ if (UNIX)
         DESTINATION share/man/man1/)
   endif ()
 endif ()
+
+# Create the pkg-config file, if we have pkg-config.
+find_package(PkgConfig)
+if (PKG_CONFIG_FOUND)
+  # mlpack.pc must be generated as a separate target, otherwise it is possible
+  # that the given version could be out of date.  We don't need to worry about
+  # the library or include directories changing, because CMake will re-run this
+  # portion of the code whenever any of those changes.  But the version must be
+  # re-extracted every time the library is built.
+
+  # So, we have to parse our list of library directories, libraries, and include
+  # directories in order to get the correct line to give to pkg-config.
+  # Next, adapt the list of include directories.
+  foreach (incldir ${MLPACK_INCLUDE_DIRS})
+    # Filter out some obviously unnecessary directories.
+    if ("${incldir}" STREQUAL "/usr/include")
+      continue()
+    endif ()
+
+    set(MLPACK_INCLUDE_DIRS_STRING "${MLPACK_INCLUDE_DIRS_STRING} -I${incldir}")
+  endforeach ()
+
+  # Create the list of link directories.
+  foreach (linkdir ${MLPACK_LIBRARY_DIRS})
+    set(MLPACK_LIBRARIES_STRING "${MLPACK_LIBRARIES_STRING} -L${linkdir}")
+  endforeach ()
+
+  foreach(lib ${MLPACK_LIBRARIES})
+    message("lib is ${lib}")
+
+    string(SUBSTRING "${lib}" 0 1 first)
+    if ("${first}" STREQUAL "/")
+      set(MLPACK_LIBRARIES_STRING "${MLPACK_LIBRARIES_STRING} -L${lib}")
+    else ()
+      set(MLPACK_LIBRARIES_STRING "${MLPACK_LIBRARIES_STRING} -l${lib}")
+    endif ()
+  endforeach ()
+
+  # Do first stage of configuration.
+  configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/CMake/mlpack.pc.in
+    ${CMAKE_BINARY_DIR}/CMake/mlpack.pc.in.partial @ONLY)
+
+  add_custom_target(pkgconfig ALL
+      ${CMAKE_COMMAND}
+          -D MLPACK_SOURCE_DIR="${CMAKE_BINARY_DIR}/include/"
+          -P "${CMAKE_CURRENT_SOURCE_DIR}/CMake/GeneratePkgConfig.cmake"
+      DEPENDS mlpack_headers
+      COMMENT "Generating mlpack.pc (pkg-config) file.")
+
+  # Do we need a different directory?
+  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib/pkgconfig/mlpack.pc
+      DESTINATION ${libdir}/pkgconfig/)
+endif ()




More information about the mlpack-git mailing list