1 # - Try to find the shared-mime-info package
3 # SHARED_MIME_INFO_MINIMUM_VERSION - Set this to the minimum version you need, default is 0.18
5 # Once done this will define
7 # SHARED_MIME_INFO_FOUND - system has the shared-mime-info package
8 # UPDATE_MIME_DATABASE_EXECUTABLE - the update-mime-database executable
10 # Copyright (c) 2007, Pino Toscano, <toscano.pino@tiscali.it>
12 # Redistribution and use is allowed according to the terms of the BSD license.
13 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
15 # the minimum version of shared-mime-database we require
16 if (NOT SHARED_MIME_INFO_MINIMUM_VERSION)
17 set(SHARED_MIME_INFO_MINIMUM_VERSION "0.18")
18 endif (NOT SHARED_MIME_INFO_MINIMUM_VERSION)
20 if (UPDATE_MIME_DATABASE_EXECUTABLE)
23 set(SHARED_MIME_INFO_FOUND TRUE)
25 else (UPDATE_MIME_DATABASE_EXECUTABLE)
27 include (MacroEnsureVersion)
29 find_program (UPDATE_MIME_DATABASE_EXECUTABLE NAMES update-mime-database)
31 if (UPDATE_MIME_DATABASE_EXECUTABLE)
33 exec_program (${UPDATE_MIME_DATABASE_EXECUTABLE} ARGS -v RETURN_VALUE _null OUTPUT_VARIABLE _smiVersionRaw)
35 string(REGEX REPLACE "update-mime-database \\([a-zA-Z\\-]+\\) ([0-9]\\.[0-9]+).*"
36 "\\1" smiVersion "${_smiVersionRaw}")
37 set (SHARED_MIME_INFO_FOUND TRUE)
38 endif (UPDATE_MIME_DATABASE_EXECUTABLE)
40 if (SHARED_MIME_INFO_FOUND)
41 if (NOT SharedMimeInfo_FIND_QUIETLY)
42 message(STATUS "Found shared-mime-info version: ${smiVersion}")
43 macro_ensure_version(${SHARED_MIME_INFO_MINIMUM_VERSION} ${smiVersion} _smiVersion_OK)
44 if (NOT _smiVersion_OK)
45 message(FATAL_ERROR "The found version of shared-mime-info (${smiVersion}) is below the minimum required (${SHARED_MIME_INFO_MINIMUM_VERSION})")
46 endif (NOT _smiVersion_OK)
48 endif (NOT SharedMimeInfo_FIND_QUIETLY)
49 else (SHARED_MIME_INFO_FOUND)
50 if (SharedMimeInfo_FIND_REQUIRED)
51 message(FATAL_ERROR "Could NOT find shared-mime-info. See http://freedesktop.org/wiki/Software/shared-mime-info.")
52 endif (SharedMimeInfo_FIND_REQUIRED)
53 endif (SHARED_MIME_INFO_FOUND)
55 endif (UPDATE_MIME_DATABASE_EXECUTABLE)
57 mark_as_advanced(UPDATE_MIME_DATABASE_EXECUTABLE)
60 macro(UPDATE_XDG_MIMETYPES _path)
61 get_filename_component(_xdgmimeDir "${_path}" NAME)
62 if("${_xdgmimeDir}" STREQUAL packages )
63 get_filename_component(_xdgmimeDir "${_path}" PATH)
64 else("${_xdgmimeDir}" STREQUAL packages )
65 set(_xdgmimeDir "${_path}")
66 endif("${_xdgmimeDir}" STREQUAL packages )
69 set(DESTDIR_VALUE \"\$ENV{DESTDIR}\")
70 if (NOT DESTDIR_VALUE)
71 # under Windows relative paths are used, that's why it runs from CMAKE_INSTALL_PREFIX
72 execute_process(COMMAND ${UPDATE_MIME_DATABASE_EXECUTABLE} ${_xdgmimeDir}
73 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX})
74 endif (NOT DESTDIR_VALUE)
76 endmacro (UPDATE_XDG_MIMETYPES)