Commit 025988c6 authored by Harald Sitter's avatar Harald Sitter 🌈
Browse files

copy FindTaglib from ECM

slighlty more modern and sports an imported target which makes the using
more idiomatic from a modern cmake POV.
this was introduced in kf5.72 and is still super new, so I'm not too
excited about bumping the kf5 requirement just yet
parent 6a131bf0
......@@ -14,6 +14,7 @@ project(kio-extras VERSION ${RELEASE_SERVICE_VERSION})
include(FeatureSummary)
set(QT_MIN_VERSION "5.11.0")
# TODO: when bumping to 5.72+ drop FindTaglib.cmake
set(KF5_MIN_VERSION "5.66.0")
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS DBus Network Widgets Svg)
......
# - Try to find the Taglib library
# Once done this will define
#
# TAGLIB_FOUND - system has the taglib library
# TAGLIB_INCLUDES - the taglib includes
# TAGLIB_LIBRARIES - The libraries needed to use taglib
# !!!! This is a copy from ECM, change there (as well) !!!!
# SPDX-License-Identifier: BSD-3-Clause
#.rst:
# FindTaglib
# ----------
#
# Try to find the Taglib library.
#
# This will define the following variables:
#
# ``Taglib_FOUND``
# True if the system has the taglib library of at least the minimum
# version specified by the version parameter to find_package()
# ``Taglib_INCLUDE_DIRS``
# The taglib include dirs for use with target_include_directories
# ``Taglib_LIBRARIES``
# The taglib libraries for use with target_link_libraries()
# ``Taglib_VERSION``
# The version of taglib that was found
#
# If ``Taglib_FOUND`` is TRUE, it will also define the following imported
# target:
#
# ``Taglib::Taglib``
# The Taglib library
#
# Since 5.72.0
#
# SPDX-FileCopyrightText: 2006 Laurent Montel <montel@kde.org>
# SPDX-FileCopyrightText: 2019 Heiko Becker <heirecka@exherbo.org>
# SPDX-FileCopyrightText: 2020 Elvis Angelaccio <elvis.angelaccio@kde.org>
# SPDX-License-Identifier: BSD-3-Clause
if(NOT TAGLIB_MIN_VERSION)
set(TAGLIB_MIN_VERSION "1.4")
endif(NOT TAGLIB_MIN_VERSION)
if(NOT WIN32)
find_program(TAGLIBCONFIG_EXECUTABLE NAMES taglib-config PATHS
${BIN_INSTALL_DIR}
)
endif(NOT WIN32)
find_package(PkgConfig QUIET)
#reset vars
set(TAGLIB_LIBRARIES)
set(TAGLIB_CFLAGS)
pkg_search_module(PC_TAGLIB QUIET taglib)
# if taglib-config has been found
if(TAGLIBCONFIG_EXECUTABLE)
find_path(Taglib_INCLUDE_DIRS
NAMES tag.h
PATH_SUFFIXES taglib
HINTS ${PC_TAGLIB_INCLUDEDIR}
)
exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --version RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_VERSION)
find_library(Taglib_LIBRARIES
NAMES tag
HINTS ${PC_TAGLIB_LIBDIR}
)
exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --libs RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_LIBRARIES)
set(Taglib_VERSION ${PC_TAGLIB_VERSION})
exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --cflags RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_CFLAGS)
if (Taglib_INCLUDE_DIRS AND NOT Taglib_VERSION)
if(EXISTS "${Taglib_INCLUDE_DIRS}/taglib.h")
file(READ "${Taglib_INCLUDE_DIRS}/taglib.h" TAGLIB_H)
# Assume software will include by things like #include <taglib/tfile.h> instead of <tfile.h>
string(REPLACE "/taglib" "" TAGLIB_STRIPPED_INCLUDE_PATHS "${TAGLIB_CFLAGS}")
string(REGEX REPLACE " *-I" ";" TAGLIB_INCLUDES "${TAGLIB_STRIPPED_INCLUDE_PATHS}")
string(REGEX MATCH "#define TAGLIB_MAJOR_VERSION[ ]+[0-9]+" TAGLIB_MAJOR_VERSION_MATCH ${TAGLIB_H})
string(REGEX MATCH "#define TAGLIB_MINOR_VERSION[ ]+[0-9]+" TAGLIB_MINOR_VERSION_MATCH ${TAGLIB_H})
string(REGEX MATCH "#define TAGLIB_PATCH_VERSION[ ]+[0-9]+" TAGLIB_PATCH_VERSION_MATCH ${TAGLIB_H})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Taglib FOUND_VAR TAGLIB_FOUND
REQUIRED_VARS TAGLIB_LIBRARIES TAGLIB_INCLUDES
VERSION_VAR TAGLIB_VERSION)
mark_as_advanced(TAGLIB_CFLAGS TAGLIB_LIBRARIES TAGLIB_INCLUDES)
string(REGEX REPLACE ".*_MAJOR_VERSION[ ]+(.*)" "\\1" TAGLIB_MAJOR_VERSION "${TAGLIB_MAJOR_VERSION_MATCH}")
string(REGEX REPLACE ".*_MINOR_VERSION[ ]+(.*)" "\\1" TAGLIB_MINOR_VERSION "${TAGLIB_MINOR_VERSION_MATCH}")
string(REGEX REPLACE ".*_PATCH_VERSION[ ]+(.*)" "\\1" TAGLIB_PATCH_VERSION "${TAGLIB_PATCH_VERSION_MATCH}")
else(TAGLIBCONFIG_EXECUTABLE)
set(Taglib_VERSION "${TAGLIB_MAJOR_VERSION}.${TAGLIB_MINOR_VERSION}.${TAGLIB_PATCH_VERSION}")
endif()
endif()
include(FindPackageHandleStandardArgs)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Taglib
FOUND_VAR
Taglib_FOUND
REQUIRED_VARS
Taglib_LIBRARIES
Taglib_INCLUDE_DIRS
VERSION_VAR
Taglib_VERSION
)
# To avoid issues, make the same assumption as above:
# Assume software will include by things like #include <taglib/tfile.h> instead of <tfile.h>
find_path(TAGLIB_INCLUDES
NAMES
taglib/tag.h
PATHS
${INCLUDE_INSTALL_DIR}
)
if (Taglib_FOUND AND NOT TARGET Taglib::Taglib)
add_library(Taglib::Taglib UNKNOWN IMPORTED)
set_target_properties(Taglib::Taglib PROPERTIES
IMPORTED_LOCATION "${Taglib_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${Taglib_INCLUDE_DIRS}"
)
endif()
# TODO: this originally used find_library_with_debug(),
# which is only available with KDELibs4Support, with
# arguments "WIN32_DEBUG_POSTFIX d". It is equivalent
# to find_library on all platforms other than Win32.
find_library(TAGLIB_LIBRARIES
NAMES tag
PATHS
${LIB_INSTALL_DIR}
)
mark_as_advanced(Taglib_LIBRARIES Taglib_INCLUDE_DIRS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Taglib DEFAULT_MSG
TAGLIB_INCLUDES TAGLIB_LIBRARIES)
endif(TAGLIBCONFIG_EXECUTABLE)
include(FeatureSummary)
set_package_properties(Taglib PROPERTIES
URL "https://taglib.org/"
DESCRIPTION "A library for reading and editing the meta-data of audio formats"
)
......@@ -216,14 +216,12 @@ install(TARGETS kritathumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
find_package(Taglib 1.11)
if(TAGLIB_FOUND)
set(audiothumbnail_SRCS audiocreator.cpp)
add_library(audiothumbnail MODULE ${audiothumbnail_SRCS})
target_include_directories(audiothumbnail BEFORE PRIVATE ${TAGLIB_INCLUDES})
target_link_libraries(audiothumbnail ${TAGLIB_LIBRARIES} KF5::KIOWidgets)
if(Taglib_FOUND)
add_library(audiothumbnail MODULE audiocreator.cpp)
target_link_libraries(audiothumbnail Taglib::Taglib KF5::KIOWidgets)
install(TARGETS audiothumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
set(audiothumbnail_desktop audiothumbnail.desktop)
endif(TAGLIB_FOUND)
endif()
# ########### next target ###############
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment