summaryrefslogtreecommitdiffstats
path: root/cmake/FindLibMagic.cmake
diff options
context:
space:
mode:
authorLubos Dolezel <lubos@dolezel.info>2015-06-01 16:38:53 +0200
committerLubos Dolezel <lubos@dolezel.info>2015-06-01 16:38:53 +0200
commit2142a3eaa4c1eb99aa1e4c7d95a4e1115bc4c689 (patch)
treed5e801c683f59a4471ba9d64f2b22ab7908a8b8b /cmake/FindLibMagic.cmake
parent545703d60acb8b0245e3d79e5dfd7171ca10c572 (diff)
downloadtwinkle-2142a3eaa4c1eb99aa1e4c7d95a4e1115bc4c689.tar
twinkle-2142a3eaa4c1eb99aa1e4c7d95a4e1115bc4c689.tar.gz
twinkle-2142a3eaa4c1eb99aa1e4c7d95a4e1115bc4c689.tar.lz
twinkle-2142a3eaa4c1eb99aa1e4c7d95a4e1115bc4c689.tar.xz
twinkle-2142a3eaa4c1eb99aa1e4c7d95a4e1115bc4c689.zip
Many submodules building (no gui yet), with link-time errors
Diffstat (limited to 'cmake/FindLibMagic.cmake')
-rw-r--r--cmake/FindLibMagic.cmake74
1 files changed, 74 insertions, 0 deletions
diff --git a/cmake/FindLibMagic.cmake b/cmake/FindLibMagic.cmake
new file mode 100644
index 0000000..ba0abd6
--- /dev/null
+++ b/cmake/FindLibMagic.cmake
@@ -0,0 +1,74 @@
+# - Try to find libmagic header and library
+#
+# Usage of this module as follows:
+#
+# find_package(LibMagic)
+#
+# Variables used by this module, they can change the default behaviour and need
+# to be set before calling find_package:
+#
+# LibMagic_ROOT_DIR Set this variable to the root installation of
+# libmagic if the module has problems finding the
+# proper installation path.
+#
+# Variables defined by this module:
+#
+# LIBMAGIC_FOUND System has libmagic, magic.h, and file
+# LibMagic_FILE_EXE Path to the 'file' command
+# LibMagic_VERSION Version of libmagic
+# LibMagic_LIBRARY The libmagic library
+# LibMagic_INCLUDE_DIR The location of magic.h
+
+find_path(LibMagic_ROOT_DIR
+ NAMES include/magic.h
+)
+
+if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+ # the static version of the library is preferred on OS X for the
+ # purposes of making packages (libmagic doesn't ship w/ OS X)
+ set(libmagic_names libmagic.a magic)
+else ()
+ set(libmagic_names magic)
+endif ()
+
+find_file(LibMagic_FILE_EXE
+ NAMES file
+ HINTS ${LibMagic_ROOT_DIR}/bin
+)
+
+find_library(LibMagic_LIBRARY
+ NAMES ${libmagic_names}
+ HINTS ${LibMagic_ROOT_DIR}/lib
+)
+
+find_path(LibMagic_INCLUDE_DIR
+ NAMES magic.h
+ HINTS ${LibMagic_ROOT_DIR}/include
+)
+
+if (LibMagic_FILE_EXE)
+ execute_process(COMMAND "${LibMagic_FILE_EXE}" --version
+ ERROR_VARIABLE LibMagic_VERSION
+ OUTPUT_VARIABLE LibMagic_VERSION)
+ string(REGEX REPLACE "^file-([0-9.]+).*$" "\\1"
+ LibMagic_VERSION "${LibMagic_VERSION}")
+ message(STATUS "libmagic version: ${LibMagic_VERSION}")
+else ()
+ set(LibMagic_VERSION NOTFOUND)
+endif ()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LibMagic DEFAULT_MSG
+ LibMagic_LIBRARY
+ LibMagic_INCLUDE_DIR
+ LibMagic_FILE_EXE
+ LibMagic_VERSION
+)
+
+mark_as_advanced(
+ LibMagic_ROOT_DIR
+ LibMagic_FILE_EXE
+ LibMagic_VERSION
+ LibMagic_LIBRARY
+ LibMagic_INCLUDE_DIR
+)