summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBe <be@mixxx.org>2020-11-15 18:49:14 -0600
committerBe <be@mixxx.org>2020-11-15 19:08:25 -0600
commit32f242c10574e16713f4db0f188ea391421a20bf (patch)
treeefdf4285acd372e0196486345c545f32c9170f6c
parent3838247eed3b2c89a5578ec2484a75c9ea227095 (diff)
CMake: fix TagLib linking on macOS
The old module relied on the taglib-config script that taglib's build system writes hardcoded absolute paths into. That was problematic for the macOS build environment which required replacing those absolute paths before building. This new CMake module does not require modifying any taglib files.
-rw-r--r--CMakeLists.txt5
-rw-r--r--cmake/modules/FindTagLib.cmake87
-rw-r--r--cmake/modules/FindTaglib.cmake133
3 files changed, 89 insertions, 136 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8fc17dc634..74c79e29c5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1924,9 +1924,8 @@ else()
endif()
# TagLib
-find_package(Taglib REQUIRED)
-target_include_directories(mixxx-lib SYSTEM PUBLIC ${TAGLIB_INCLUDE_DIRS})
-target_link_libraries(mixxx-lib PUBLIC ${TAGLIB_LIBRARIES})
+find_package(TagLib REQUIRED)
+target_link_libraries(mixxx-lib PUBLIC TagLib::TagLib)
if(WIN32 AND STATIC_DEPS)
target_compile_definitions(mixxx-lib PUBLIC TAGLIB_STATIC)
endif()
diff --git a/cmake/modules/FindTagLib.cmake b/cmake/modules/FindTagLib.cmake
new file mode 100644
index 0000000000..36da772b01
--- /dev/null
+++ b/cmake/modules/FindTagLib.cmake
@@ -0,0 +1,87 @@
+# This file is part of Mixxx, Digital DJ'ing software.
+# Copyright (C) 2001-2020 Mixxx Development Team
+# Distributed under the GNU General Public Licence (GPL) version 2 or any later
+# later version. See the LICENSE file for details.
+
+#[=======================================================================[.rst:
+FindTagLib
+-----------
+
+Finds the TagLib library.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+This module provides the following imported targets, if found:
+
+``TagLib::TagLib``
+ The TagLib library
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This will define the following variables:
+
+``TagLib_FOUND``
+ True if the system has the TagLib library.
+``TagLib_INCLUDE_DIRS``
+ Include directories needed to use TagLib.
+``TagLib_LIBRARIES``
+ Libraries needed to link to TagLib.
+``TagLib_DEFINITIONS``
+ Compile definitions needed to use TagLib.
+
+Cache Variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``TagLib_INCLUDE_DIR``
+ The directory containing ``ebur128.h``.
+``TagLib_LIBRARY``
+ The path to the TagLib library.
+
+#]=======================================================================]
+
+find_package(PkgConfig QUIET)
+if(PkgConfig_FOUND)
+ pkg_check_modules(PC_TagLib QUIET taglib)
+endif()
+
+find_path(TagLib_INCLUDE_DIR
+ NAMES tag.h
+ PATHS ${PC_TagLib_INCLUDE_DIRS}
+ PATH_SUFFIXES taglib
+ DOC "TagLib include directory")
+mark_as_advanced(TagLib_INCLUDE_DIR)
+
+find_library(TagLib_LIBRARY
+ NAMES tag
+ PATHS ${PC_TagLib_LIBRARY_DIRS}
+ DOC "TagLib library"
+)
+mark_as_advanced(TagLib_LIBRARY)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+ TagLib
+ DEFAULT_MSG
+ TagLib_LIBRARY
+ TagLib_INCLUDE_DIR
+)
+
+if(TagLib_FOUND)
+ set(TagLib_LIBRARIES "${TagLib_LIBRARY}")
+ set(TagLib_INCLUDE_DIRS "${TagLib_INCLUDE_DIR}")
+ set(TagLib_DEFINITIONS ${PC_TagLib_CFLAGS_OTHER})
+
+ if(NOT TARGET TagLib::TagLib)
+ add_library(TagLib::TagLib UNKNOWN IMPORTED)
+ set_target_properties(TagLib::TagLib
+ PROPERTIES
+ IMPORTED_LOCATION "${TagLib_LIBRARY}"
+ INTERFACE_COMPILE_OPTIONS "${PC_TagLib_CFLAGS_OTHER}"
+ INTERFACE_INCLUDE_DIRECTORIES "${TagLib_INCLUDE_DIR}"
+ )
+ endif()
+endif()
diff --git a/cmake/modules/FindTaglib.cmake b/cmake/modules/FindTaglib.cmake
deleted file mode 100644
index 0ed3b3d39f..0000000000
--- a/cmake/modules/FindTaglib.cmake
+++ /dev/null
@@ -1,133 +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.7")
-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 VERSION_LESS "${TAGLIB_MIN_VERSION}")
- message(STATUS "TagLib version too old: 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)
- endif()
-
- string(REGEX REPLACE " *-I" ";" TAGLIB_INCLUDE_DIRS "${TAGLIB_CFLAGS}")
- string(SUBSTRING ${TAGLIB_INCLUDE_DIRS} 0 -1 TAGLIB_INCLUDE_DIRS) #we remove the initial ;
-endif()
-
-mark_as_advanced(TAGLIB_CFLAGS TAGLIB_LIBRARIES TAGLIB_INCLUDES)
-
-else()
-
- find_path(TAGLIB_INCLUDE_DIRS
- NAMES tag.h
- PATH_SUFFIXES taglib
- PATHS ${INCLUDE_INSTALL_DIR}
- )
-
- if(NOT WIN32)
- # on non-win32 we don't need to take care about WIN32_DEBUG_POSTFIX
- find_library(TAGLIB_LIBRARIES tag PATHS ${LIB_INSTALL_DIR})
-
- else()
-
- # 1. get all possible libnames
- set(args PATHS ${LIB_INSTALL_DIR})
- set(newargs "")
- set(libnames_release "")
- set(libnames_debug "")
-
- list(LENGTH args listCount)
-
- # just one name
- list(APPEND libnames_release "tag")
- list(APPEND libnames_debug "tagd")
-
- set(newargs ${args})
-
- # search the release lib
- find_library(TAGLIB_LIBRARIES_RELEASE
- NAMES ${libnames_release}
- ${newargs}
- )
-
- # search the debug lib
- find_library(TAGLIB_LIBRARIES_DEBUG
- NAMES ${libnames_debug}
- ${newargs}
- )
-
- if(TAGLIB_LIBRARIES_RELEASE AND TAGLIB_LIBRARIES_DEBUG)
-
- # both libs found
- set(TAGLIB_LIBRARIES optimized ${TAGLIB_LIBRARIES_RELEASE}
- debug ${TAGLIB_LIBRARIES_DEBUG}
- )
-
- else()
-
- if(TAGLIB_LIBRARIES_RELEASE)
- # only release found
- set(TAGLIB_LIBRARIES ${TAGLIB_LIBRARIES_RELEASE})
-
- else()
- # only debug (or nothing) found
- set(TAGLIB_LIBRARIES ${TAGLIB_LIBRARIES_DEBUG})
-
- endif()
-
- endif()
-
- mark_as_advanced(TAGLIB_LIBRARIES_RELEASE)
- mark_as_advanced(TAGLIB_LIBRARIES_DEBUG)
-
- endif()
-
- include(FindPackageMessage)
- include(FindPackageHandleStandardArgs)
- find_package_handle_standard_args(Taglib DEFAULT_MSG TAGLIB_LIBRARIES TAGLIB_INCLUDE_DIRS)
-
-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()