diff --git a/find-modules/FindTaglib.cmake b/find-modules/FindTaglib.cmake new file mode 100644 --- /dev/null +++ b/find-modules/FindTaglib.cmake @@ -0,0 +1,140 @@ +#.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::Talib`` +# The Taglib library +# +# Since 5.60.0 + +# ============================================================================ +# Copyright (c) 2006, Laurent Montel, +# Copyright (c) 2019, Heiko Becker, +# +# 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. +# ============================================================================ + +# The minimum version of Taglib we require +if(NOT Taglib_FIND_VERSION) + set(TAGLIB_FIND_VERSION "1.4") +endif() + +find_program(TaglibConfig_EXECUTABLE NAMES taglib-config) + +if(TaglibConfig_EXECUTABLE) + execute_process(COMMAND ${TaglibConfig_EXECUTABLE} --version + OUTPUT_VARIABLE TC_Taglib_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + execute_process(COMMAND ${TaglibConfig_EXECUTABLE} --libs + OUTPUT_VARIABLE TC_Taglib_LIBRARIES + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + execute_process(COMMAND ${TaglibConfig_EXECUTABLE} --cflags + OUTPUT_VARIABLE TC_Taglib_CFLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + set(Taglib_VERSION ${TC_Taglib_VERSION}) + set(Taglib_CFLAGS ${TC_Taglib_CFLAGS}) + string(REGEX REPLACE " *-I" ";" Taglib_INCLUDE_DIRS "${Taglib_CFLAGS}") +endif() + +find_path(Taglib_INCLUDE_DIRS + NAMES tag.h taglib/tag.h + HINTS ${TC_Taglib_INCLUDE_DIRS} + ) + +find_library(Taglib_LIBRARIES + NAMES tag + HINTS ${TC_Taglib_LIBRARIES} +) + +if (Taglib_INCLUDE_DIRS AND NOT Taglib_VERSION) + if(EXISTS "Taglib_INCLUDE_DIRS}/taglib/taglib.h") + file(READ "${Taglib_INCLUDE_DIRS}/taglib/taglib.h" TAGLIB_H) + string(REGEX MATCH "#define TAGLIB_MAJOR_VERSION[ ]+[0-9]+" TAGLIB_MAJOR_VERSION_MATCH) + string(REGEX MATCH "#define TAGLIB_MINOR_VERSION[ ]+[0-9]+" TAGLIB_MINOR_VERSION_MATCH) + string(REGEX MATCH "#define TAGLIB_PATCH_VERSION[ ]+[0-9]+" TAGLIB_PATCH_VERSION_MATCH) + + string(REGEX REPLACE ".*_MAJOR[ ]+(.*)" "\\1" TAGLIB_MAJOR_VERSION ${TAGLIB_MAJOR_VERSION_MATCH}) + string(REGEX REPLACE ".*_MINOR[ ]+(.*)" "\\1" TAGLIB_MINOR_VERSION ${TAGLIB_MINOR_VERSION_MATCH}) + string(REGEX REPLACE ".*_PATCH[ ]+(.*)" "\\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 +) + +# Deprecated synonyms +set(TAGLIB_CFLAGS "${Taglib_CFLAGS}") +set(TAGLIB_INCLUDES "${Taglib_INCLUDE_DIRS}") +set(TAGLIB_LIBRARIES "${Taglib_LIBRARIES}") +set(TAGLIB_FOUND "${Taglib_FOUND}") + +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_COMPILE_OPTIONS "${Taglib_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${Taglib_INCLUDE_DIRS}" + ) +endif() + +mark_as_advanced(Taglib_CFLAGS 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" +)