LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0002-Fix-building-against-exiv2-0.27.patch of Package krename5 (Project home:wolfi323:branches:KDE:Frameworks5)

From b22de9135ba2a5abdbd2b275a60933a50f074010 Mon Sep 17 00:00:00 2001
From: Heiko Becker <heirecka@exherbo.org>
Date: Tue, 20 Nov 2018 18:26:47 +0100
Subject: [PATCH 2/3] Fix building against exiv2-0.27

One neeeded part is to copy over the new FindLibExiv2 module from
ECM which has not appeared in a release yet (it will with 5.53.0).
I'll probably add that version as a requirement and remove the copy
again in the near future.
The other part includes raising the cmake version requirement to
3.7.0, which was released over 2 years ago. (The version comparison
could be easily solved differently and less elegantly, but let's see
if people with ancient cmakes complain).
---
 CMakeLists.txt                   |  15 ++---
 cmake/modules/FindExiv2.cmake    |  79 ---------------------------
 cmake/modules/FindLibExiv2.cmake | 115 +++++++++++++++++++++++++++++++++++++++
 config-krename.h.cmake           |   3 +
 src/CMakeLists.txt               |   8 +--
 src/exiv2plugin.cpp              |   8 ++-
 6 files changed, 137 insertions(+), 91 deletions(-)
 delete mode 100644 cmake/modules/FindExiv2.cmake
 create mode 100644 cmake/modules/FindLibExiv2.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 717d859..be33a09 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
 project(krename)
 
-cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+cmake_minimum_required(VERSION 3.7)
 # search packages used by KDE
 find_package(ECM 0.0.11 REQUIRED NO_MODULE)
 set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
@@ -52,11 +52,12 @@ set_package_properties(Taglib PROPERTIES
     TYPE OPTIONAL)
 
 # Find exiv2
-find_package(Exiv2 0.13) # AccessMode was added in 0.13
-set_package_properties(Exiv2 PROPERTIES
-    DESCRIPTION "A library to access image metadata"
-    URL "http://www.exiv2.org"
-    TYPE OPTIONAL)
+find_package(LibExiv2 0.13) # AccessMode was added in 0.13
+set_package_properties(LibExiv2 PROPERTIES TYPE OPTIONAL)
+
+if (LibExiv2_VERSION VERSION_GREATER_EQUAL "0.27")
+    set(HAVE_LIBEXIV2_0_27 TRUE)
+endif()
 
 # Find podofo
 find_package(PoDoFo)
@@ -81,7 +82,7 @@ set_package_properties(Freetype PROPERTIES
 feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
 
 set(HAVE_TAGLIB TAGLIB_FOUND)
-set(HAVE_EXIV2 EXIV2_FOUND)
+set(HAVE_EXIV2 LibExiv2_FOUND)
 set(HAVE_PODOFO PoDoFo_FOUND)
 set(HAVE_FREETYPE FREETYPE_FOUND)
 configure_file(config-krename.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-krename.h)
diff --git a/cmake/modules/FindExiv2.cmake b/cmake/modules/FindExiv2.cmake
deleted file mode 100644
index dd9af86..0000000
--- a/cmake/modules/FindExiv2.cmake
+++ /dev/null
@@ -1,79 +0,0 @@
-# - Try to find the Exiv2 library
-#
-#  EXIV2_MIN_VERSION - You can set this variable to the minimum version you need
-#                      before doing FIND_PACKAGE(Exiv2). The default is 0.12.
-#
-# Once done this will define
-#
-#  EXIV2_FOUND - system has libexiv2
-#  EXIV2_INCLUDE_DIR - the libexiv2 include directory
-#  EXIV2_LIBRARIES - Link these to use libexiv2
-#  EXIV2_DEFINITIONS - Compiler switches required for using libexiv2
-#
-# The minimum required version of Exiv2 can be specified using the
-# standard syntax, e.g. find_package(Exiv2 0.17)
-#
-# For compatibility, also the variable EXIV2_MIN_VERSION can be set to the minimum version
-# you need before doing FIND_PACKAGE(Exiv2). The default is 0.12.
-
-# Copyright (c) 2010, Alexander Neundorf, <neundorf@kde.org>
-# Copyright (c) 2008, Gilles Caulier, <caulier.gilles@gmail.com>
-#
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
-
-# Support EXIV2_MIN_VERSION for compatibility:
-if(NOT Exiv2_FIND_VERSION)
-  set(Exiv2_FIND_VERSION "${EXIV2_MIN_VERSION}")
-endif(NOT Exiv2_FIND_VERSION)
-
-# the minimum version of exiv2 we require
-if(NOT Exiv2_FIND_VERSION)
-  set(Exiv2_FIND_VERSION "0.12")
-endif(NOT Exiv2_FIND_VERSION)
-
-
-if (NOT WIN32)
-   # use pkg-config to get the directories and then use these values
-   # in the FIND_PATH() and FIND_LIBRARY() calls
-   find_package(PkgConfig)
-   pkg_check_modules(PC_EXIV2 QUIET exiv2)
-   set(EXIV2_DEFINITIONS ${PC_EXIV2_CFLAGS_OTHER})
-endif (NOT WIN32)
-
-
-find_path(EXIV2_INCLUDE_DIR NAMES exiv2/exif.hpp
-          HINTS
-          ${PC_EXIV2_INCLUDEDIR}
-          ${PC_EXIV2_INCLUDE_DIRS}
-        )
-
-find_library(EXIV2_LIBRARY NAMES exiv2 libexiv2
-             HINTS
-             ${PC_EXIV2_LIBDIR}
-             ${PC_EXIV2_LIBRARY_DIRS}
-            )
-
-
-# Get the version number from exiv2/version.hpp and store it in the cache:
-if(EXIV2_INCLUDE_DIR  AND NOT  EXIV2_VERSION)
-  file(READ ${EXIV2_INCLUDE_DIR}/exiv2/version.hpp EXIV2_VERSION_CONTENT)
-  string(REGEX MATCH "#define EXIV2_MAJOR_VERSION +\\( *([0-9]+) *\\)"  _dummy "${EXIV2_VERSION_CONTENT}")
-  set(EXIV2_VERSION_MAJOR "${CMAKE_MATCH_1}")
-
-  string(REGEX MATCH "#define EXIV2_MINOR_VERSION +\\( *([0-9]+) *\\)"  _dummy "${EXIV2_VERSION_CONTENT}")
-  set(EXIV2_VERSION_MINOR "${CMAKE_MATCH_1}")
-
-  string(REGEX MATCH "#define EXIV2_PATCH_VERSION +\\( *([0-9]+) *\\)"  _dummy "${EXIV2_VERSION_CONTENT}")
-  set(EXIV2_VERSION_PATCH "${CMAKE_MATCH_1}")
-
-  set(EXIV2_VERSION "${EXIV2_VERSION_MAJOR}.${EXIV2_VERSION_MINOR}.${EXIV2_VERSION_PATCH}" CACHE STRING "Version number of Exiv2" FORCE)
-endif(EXIV2_INCLUDE_DIR  AND NOT  EXIV2_VERSION)
-
-set(EXIV2_LIBRARIES "${EXIV2_LIBRARY}")
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(Exiv2  REQUIRED_VARS  EXIV2_LIBRARY EXIV2_INCLUDE_DIR
-                                         VERSION_VAR  EXIV2_VERSION)
-
-mark_as_advanced(EXIV2_INCLUDE_DIR EXIV2_LIBRARY)
diff --git a/cmake/modules/FindLibExiv2.cmake b/cmake/modules/FindLibExiv2.cmake
new file mode 100644
index 0000000..935cee2
--- /dev/null
+++ b/cmake/modules/FindLibExiv2.cmake
@@ -0,0 +1,115 @@
+#.rst:
+# FindLibExiv2
+# ------------
+#
+# Try to find the Exiv2 library.
+#
+# This will define the following variables:
+#
+# ``LibExiv2_FOUND``
+#     System has LibExiv2.
+#
+# ``LibExiv2_VERSION``
+#     The version of LibExiv2.
+#
+# ``LibExiv2_INCLUDE_DIRS``
+#     This should be passed to target_include_directories() if
+#     the target is not used for linking.
+#
+# ``LibExiv2_LIBRARIES``
+#     The LibExiv2 library.
+#     This can be passed to target_link_libraries() instead of
+#     the ``LibExiv2::LibExiv2`` target
+#
+# If ``LibExiv2_FOUND`` is TRUE, the following imported target
+# will be available:
+#
+# ``LibExiv2::LibExiv2``
+#     The Exiv2 library
+#
+# Since 5.53.0.
+#
+#=============================================================================
+# Copyright (c) 2018, Christophe Giboudeaux, <christophe@krop.fr>
+# Copyright (c) 2010, Alexander Neundorf, <neundorf@kde.org>
+# Copyright (c) 2008, Gilles Caulier, <caulier.gilles@gmail.com>
+#
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+#    derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#=============================================================================
+
+find_package(PkgConfig QUIET)
+pkg_check_modules(PC_EXIV2 QUIET exiv2)
+
+find_path(LibExiv2_INCLUDE_DIRS NAMES exiv2/exif.hpp
+    HINTS ${PC_EXIV2_INCLUDEDIR}
+)
+
+find_library(LibExiv2_LIBRARIES NAMES exiv2 libexiv2
+    HINTS ${PC_EXIV2_LIBRARY_DIRS}
+)
+
+set(LibExiv2_VERSION ${PC_EXIV2_VERSION})
+
+if(NOT LibExiv2_VERSION AND DEFINED LibExiv2_INCLUDE_DIRS)
+    # With exiv >= 0.27, the version #defines are in exv_conf.h instead of version.hpp
+    foreach(_exiv2_version_file "version.hpp" "exv_conf.h")
+        if(EXISTS "${LibExiv2_INCLUDE_DIRS}/exiv2/${_exiv2_version_file}")
+            file(READ "${LibExiv2_INCLUDE_DIRS}/exiv2/${_exiv2_version_file}" _exiv_version_file_content)
+            string(REGEX MATCH "#define EXIV2_MAJOR_VERSION[ ]+\\([0-9]+\\)" EXIV2_MAJOR_VERSION_MATCH ${_exiv_version_file_content})
+            string(REGEX MATCH "#define EXIV2_MINOR_VERSION[ ]+\\([0-9]+\\)" EXIV2_MINOR_VERSION_MATCH ${_exiv_version_file_content})
+            string(REGEX MATCH "#define EXIV2_PATCH_VERSION[ ]+\\([0-9]+\\)" EXIV2_PATCH_VERSION_MATCH ${_exiv_version_file_content})
+            if(EXIV2_MAJOR_VERSION_MATCH)
+                string(REGEX REPLACE ".*_MAJOR_VERSION[ ]+\\((.*)\\)" "\\1" EXIV2_MAJOR_VERSION ${EXIV2_MAJOR_VERSION_MATCH})
+                string(REGEX REPLACE ".*_MINOR_VERSION[ ]+\\((.*)\\)" "\\1" EXIV2_MINOR_VERSION ${EXIV2_MINOR_VERSION_MATCH})
+                string(REGEX REPLACE ".*_PATCH_VERSION[ ]+\\((.*)\\)" "\\1"  EXIV2_PATCH_VERSION  ${EXIV2_PATCH_VERSION_MATCH})
+            endif()
+        endif()
+    endforeach()
+
+    set(LibExiv2_VERSION "${EXIV2_MAJOR_VERSION}.${EXIV2_MINOR_VERSION}.${EXIV2_PATCH_VERSION}")
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LibExiv2
+    FOUND_VAR LibExiv2_FOUND
+    REQUIRED_VARS  LibExiv2_LIBRARIES LibExiv2_INCLUDE_DIRS
+    VERSION_VAR  LibExiv2_VERSION
+)
+
+mark_as_advanced(LibExiv2_INCLUDE_DIRS LibExiv2_LIBRARIES)
+
+if(LibExiv2_FOUND AND NOT TARGET LibExiv2::LibExiv2)
+    add_library(LibExiv2::LibExiv2 UNKNOWN IMPORTED)
+    set_target_properties(LibExiv2::LibExiv2 PROPERTIES
+        IMPORTED_LOCATION "${LibExiv2_LIBRARIES}"
+        INTERFACE_INCLUDE_DIRECTORIES "${LibExiv2_INCLUDE_DIRS}"
+    )
+endif()
+
+include(FeatureSummary)
+set_package_properties(LibExiv2 PROPERTIES
+    URL "http://www.exiv2.org"
+    DESCRIPTION "Image metadata support"
+)
diff --git a/config-krename.h.cmake b/config-krename.h.cmake
index 862e40b..de25e6f 100644
--- a/config-krename.h.cmake
+++ b/config-krename.h.cmake
@@ -6,6 +6,9 @@
 /* have Exiv2 */
 #cmakedefine01 HAVE_EXIV2
 
+/* Defined if we have libexiv2 >= 0.27 */
+#cmakedefine01 HAVE_LIBEXIV2_0_27
+
 /* have PoDoFo */
 #cmakedefine01 HAVE_PODOFO
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1811fb0..3f262b3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -23,7 +23,7 @@ if(FREETYPE_FOUND)
     include_directories(${FREETYPE_INCLUDE_DIRS})
 endif()
 
-add_definitions(${TAGLIB_CFLAGS} ${EXIV2_CFLAGS})
+add_definitions(${TAGLIB_CFLAGS})
 # Exiv2 needs exceptions
 kde_enable_exceptions()
 
@@ -67,7 +67,7 @@ set(krename_SRCS
     snumplugin.cpp
 )
 
-if(EXIV2_FOUND)
+if(LibExiv2_FOUND)
     set(krename_SRCS ${krename_SRCS}
         exiv2plugin.cpp
     )
@@ -137,9 +137,9 @@ if(TAGLIB_FOUND)
         ${TAGLIB_LIBRARIES}
     )
 endif()
-if(EXIV2_FOUND)
+if(LibExiv2_FOUND)
     target_link_libraries(krename
-        ${EXIV2_LIBRARIES}
+        LibExiv2::LibExiv2
     )
 endif()
 if(PoDoFo_FOUND)
diff --git a/src/exiv2plugin.cpp b/src/exiv2plugin.cpp
index 39ac9e7..8c5c1cf 100644
--- a/src/exiv2plugin.cpp
+++ b/src/exiv2plugin.cpp
@@ -17,13 +17,19 @@
 
 #include "exiv2plugin.h"
 
+#include "../config-krename.h"
+
 #include <KLocalizedString>
 
 #include <exiv2/error.hpp>
 #include <exiv2/exif.hpp>
 #include <exiv2/image.hpp>
 #include <exiv2/iptc.hpp>
-#include <exiv2/xmp.hpp>
+#ifdef HAVE_LIBEXIV2_0_27
+    #include <exiv2/xmp_exiv2.hpp>
+#else
+    #include <exiv2/xmp.hpp>
+#endif
 #include <exiv2/tags.hpp>
 
 #include "batchrenamer.h"
-- 
2.16.4