From 2548455f456976e547aca60a142c532a454bd7e5 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Tue, 13 Apr 2021 13:14:06 +0200 Subject: [PATCH] Copy FindSharedMimeInfo from ECM Instead of relying on ECM being installed. We copy other stuff from ECM so be consistent. Signed-off-by: Nicolas Fella --- cmake/modules/FindSharedMimeInfo.cmake | 93 ++++++++++++++++++++++++++ src/gui/CMakeLists.txt | 2 - 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 cmake/modules/FindSharedMimeInfo.cmake diff --git a/cmake/modules/FindSharedMimeInfo.cmake b/cmake/modules/FindSharedMimeInfo.cmake new file mode 100644 index 000000000..0b8dec9c0 --- /dev/null +++ b/cmake/modules/FindSharedMimeInfo.cmake @@ -0,0 +1,93 @@ +#.rst: +# FindSharedMimeInfo +# ------------------ +# +# Try to find the shared-mime-info package. +# +# This will define the following variables: +# +# ``SharedMimeInfo_FOUND`` +# True if system has the shared-mime-info package +# ``UPDATE_MIME_DATABASE_EXECUTABLE`` +# The update-mime-database executable +# +# and the following imported targets: +# +# ``SharedMimeInfo::UpdateMimeDatabase`` +# The update-mime-database executable +# +# The follow macro is available:: +# +# update_xdg_mimetypes() +# +# Updates the XDG mime database at install time (unless the ``$DESTDIR`` +# environment variable is set, in which case it is up to package managers to +# perform this task). +# +# Since pre-1.0.0. + +#============================================================================= +# SPDX-FileCopyrightText: 2013-2014 Alex Merry +# SPDX-FileCopyrightText: 2007 Pino Toscano +# +# SPDX-License-Identifier: BSD-3-Clause +#============================================================================= + +include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake) + +ecm_find_package_version_check(SharedMimeInfo) + +find_program (UPDATE_MIME_DATABASE_EXECUTABLE NAMES update-mime-database) + +if (UPDATE_MIME_DATABASE_EXECUTABLE) + execute_process( + COMMAND "${UPDATE_MIME_DATABASE_EXECUTABLE}" -v + OUTPUT_VARIABLE _smiVersionRaw + ERROR_VARIABLE _smiVersionRaw) + + string(REGEX REPLACE "update-mime-database \\([a-zA-Z\\-]+\\) ([0-9]\\.[0-9]+).*" + "\\1" SharedMimeInfo_VERSION_STRING "${_smiVersionRaw}") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SharedMimeInfo + FOUND_VAR + SharedMimeInfo_FOUND + REQUIRED_VARS + UPDATE_MIME_DATABASE_EXECUTABLE + VERSION_VAR + SharedMimeInfo_VERSION_STRING) + +if(SharedMimeInfo_FOUND AND NOT TARGET SharedMimeInfo::UpdateMimeDatabase) + add_executable(SharedMimeInfo::UpdateMimeDatabase IMPORTED) + set_target_properties(SharedMimeInfo::UpdateMimeDatabase PROPERTIES + IMPORTED_LOCATION "${UPDATE_MIME_DATABASE_EXECUTABLE}" + ) +endif() + +mark_as_advanced(UPDATE_MIME_DATABASE_EXECUTABLE) + +function(UPDATE_XDG_MIMETYPES _path) + get_filename_component(_xdgmimeDir "${_path}" NAME) + if("${_xdgmimeDir}" STREQUAL packages ) + get_filename_component(_xdgmimeDir "${_path}" PATH) + else() + set(_xdgmimeDir "${_path}") + endif() + + # Note that targets and most variables are not available to install code + install(CODE " +set(DESTDIR_VALUE \"\$ENV{DESTDIR}\") +if (NOT DESTDIR_VALUE) + # under Windows relative paths are used, that's why it runs from CMAKE_INSTALL_PREFIX + message(STATUS \"Updating MIME database at \${CMAKE_INSTALL_PREFIX}/${_xdgmimeDir}\") + execute_process(COMMAND \"${UPDATE_MIME_DATABASE_EXECUTABLE}\" -n \"${_xdgmimeDir}\" + WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}\") +endif (NOT DESTDIR_VALUE) +") +endfunction() + +include(FeatureSummary) +set_package_properties(SharedMimeInfo PROPERTIES + URL https://freedesktop.org/wiki/Software/shared-mime-info/ + DESCRIPTION "A database of common MIME types") diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 468b0b750..671b19d6b 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -441,8 +441,6 @@ if(NOT BUILD_OWNCLOUD_OSX_BUNDLE AND NOT WIN32) configure_file(owncloud.xml.in ${APPLICATION_EXECUTABLE}.xml) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${APPLICATION_EXECUTABLE}.xml DESTINATION ${DATADIR}/mime/packages ) - find_package(ECM 1.2.0 CONFIG) - set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") find_package(SharedMimeInfo) if(SharedMimeInfo_FOUND) update_xdg_mimetypes( ${DATADIR}/mime/packages )