aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2020-06-17 06:33:22 +0000
committerChristophe Giboudeaux <christophe@krop.fr>2020-06-17 06:33:22 +0000
commit8f26aba22be46099e0bb443ab27de4eb8c4d8a06 (patch)
tree2774f1ede8de28283c56037400a5d236c688a620
parent110f62d69b9529a901889c3998817eb406a22c8f (diff)
downloadextra-cmake-modules-8f26aba22be46099e0bb443ab27de4eb8c4d8a06.tar.gz
extra-cmake-modules-8f26aba22be46099e0bb443ab27de4eb8c4d8a06.tar.bz2
Add FindTaglib find module
Based on https://phabricator.kde.org/D21695 Several KDE projects use taglib, so we really need to provide a proper find module in ECM. AFAIK taglib-config should not be portable, so we don't try to run it on WIN32. See also: https://invent.kde.org/network/kio-extras/-/commit/548f525f4308810888c85f42a570139029c40618
-rw-r--r--attic/modules/FindTaglib.cmake85
-rw-r--r--docs/find-module/FindTaglib.rst1
-rw-r--r--find-modules/FindTaglib.cmake90
3 files changed, 91 insertions, 85 deletions
diff --git a/attic/modules/FindTaglib.cmake b/attic/modules/FindTaglib.cmake
deleted file mode 100644
index 4b58bf6c..00000000
--- a/attic/modules/FindTaglib.cmake
+++ /dev/null
@@ -1,85 +0,0 @@
-# - Try to find the Taglib library
-# Once done this will define
-#
-# TAGLIB_FOUND - system has the taglib library
-# TAGLIB_CFLAGS - the taglib cflags
-# TAGLIB_LIBRARIES - The libraries needed to use taglib
-
-# Copyright (c) 2006, Laurent Montel, <montel@kde.org>
-#
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
-
-if(NOT TAGLIB_MIN_VERSION)
- set(TAGLIB_MIN_VERSION "1.4")
-endif()
-
-if(NOT WIN32)
- find_program(TAGLIBCONFIG_EXECUTABLE NAMES taglib-config PATHS
- ${BIN_INSTALL_DIR}
- )
-endif()
-
-#reset vars
-set(TAGLIB_LIBRARIES)
-set(TAGLIB_CFLAGS)
-
-# if taglib-config has been found
-if(TAGLIBCONFIG_EXECUTABLE)
-
- exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --version RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_VERSION)
-
- if(TAGLIB_VERSION STRLESS "${TAGLIB_MIN_VERSION}")
- message(STATUS "TagLib version not found: version searched :${TAGLIB_MIN_VERSION}, found ${TAGLIB_VERSION}")
- set(TAGLIB_FOUND FALSE)
- else()
-
- exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --libs RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_LIBRARIES)
-
- exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --cflags RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_CFLAGS)
-
- if(TAGLIB_LIBRARIES AND TAGLIB_CFLAGS)
- set(TAGLIB_FOUND TRUE)
- message(STATUS "Found taglib: ${TAGLIB_LIBRARIES}")
- endif()
- string(REGEX REPLACE " *-I" ";" TAGLIB_INCLUDES "${TAGLIB_CFLAGS}")
- endif()
- mark_as_advanced(TAGLIB_CFLAGS TAGLIB_LIBRARIES TAGLIB_INCLUDES)
-
-else()
-
- include(FindLibraryWithDebug)
- include(FindPackageHandleStandardArgs)
-
- find_path(TAGLIB_INCLUDES
- NAMES
- tag.h
- PATH_SUFFIXES taglib
- PATHS
- ${KDE4_INCLUDE_DIR}
- ${INCLUDE_INSTALL_DIR}
- )
-
- find_library_with_debug(TAGLIB_LIBRARIES
- WIN32_DEBUG_POSTFIX d
- NAMES tag
- PATHS
- ${KDE4_LIB_DIR}
- ${LIB_INSTALL_DIR}
- )
-
- find_package_handle_standard_args(Taglib DEFAULT_MSG
- TAGLIB_INCLUDES TAGLIB_LIBRARIES)
-endif()
-
-
-if(TAGLIB_FOUND)
- if(NOT Taglib_FIND_QUIETLY AND TAGLIBCONFIG_EXECUTABLE)
- message(STATUS "Taglib found: ${TAGLIB_LIBRARIES}")
- endif()
-else()
- if(Taglib_FIND_REQUIRED)
- message(FATAL_ERROR "Could not find Taglib")
- endif()
-endif()
-
diff --git a/docs/find-module/FindTaglib.rst b/docs/find-module/FindTaglib.rst
new file mode 100644
index 00000000..dbd4e1e8
--- /dev/null
+++ b/docs/find-module/FindTaglib.rst
@@ -0,0 +1 @@
+.. ecm-module:: ../../find-modules/FindTaglib.cmake
diff --git a/find-modules/FindTaglib.cmake b/find-modules/FindTaglib.cmake
new file mode 100644
index 00000000..1e1b9075
--- /dev/null
+++ b/find-modules/FindTaglib.cmake
@@ -0,0 +1,90 @@
+#.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
+
+find_package(PkgConfig QUIET)
+
+pkg_search_module(PC_TAGLIB QUIET taglib)
+
+find_path(Taglib_INCLUDE_DIRS
+ NAMES tag.h
+ PATH_SUFFIXES taglib
+ HINTS ${PC_TAGLIB_INCLUDEDIR}
+)
+
+find_library(Taglib_LIBRARIES
+ NAMES tag
+ HINTS ${PC_TAGLIB_LIBDIR}
+)
+
+set(Taglib_VERSION ${PC_TAGLIB_VERSION})
+
+if (Taglib_INCLUDE_DIRS AND NOT Taglib_VERSION)
+ if(EXISTS "${Taglib_INCLUDE_DIRS}/taglib.h")
+ file(READ "${Taglib_INCLUDE_DIRS}/taglib.h" TAGLIB_H)
+
+ 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})
+
+ 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}")
+
+ set(Taglib_VERSION "${TAGLIB_MAJOR_VERSION}.${TAGLIB_MINOR_VERSION}.${TAGLIB_PATCH_VERSION}")
+ endif()
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Taglib
+ FOUND_VAR
+ Taglib_FOUND
+ REQUIRED_VARS
+ Taglib_LIBRARIES
+ Taglib_INCLUDE_DIRS
+ VERSION_VAR
+ Taglib_VERSION
+)
+
+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()
+
+mark_as_advanced(Taglib_LIBRARIES Taglib_INCLUDE_DIRS)
+
+include(FeatureSummary)
+set_package_properties(Taglib PROPERTIES
+ URL "https://taglib.org/"
+ DESCRIPTION "A library for reading and editing the meta-data of audio formats"
+)