1# - Try to find the Taglib library
2# Once done this will define
3#
4#  TAGLIB_FOUND - system has the taglib library
5#  TAGLIB_CFLAGS - the taglib cflags
6#  TAGLIB_LIBRARIES - The libraries needed to use taglib
7
8# Copyright (c) 2006, Laurent Montel, <montel@kde.org>
9#
10# Redistribution and use is allowed according to the terms of the BSD license.
11# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
12
13if(NOT TAGLIB_MIN_VERSION)
14  set(TAGLIB_MIN_VERSION "1.6")
15endif(NOT TAGLIB_MIN_VERSION)
16
17if(NOT WIN32)
18    find_program(TAGLIBCONFIG_EXECUTABLE NAMES taglib-config PATHS
19       ${BIN_INSTALL_DIR}
20    )
21endif(NOT WIN32)
22
23#reset vars
24set(TAGLIB_LIBRARIES)
25set(TAGLIB_CFLAGS)
26
27# if taglib-config has been found
28if(TAGLIBCONFIG_EXECUTABLE)
29
30  exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --version RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_VERSION)
31
32  if(TAGLIB_VERSION VERSION_LESS "${TAGLIB_MIN_VERSION}")
33     message(STATUS "TagLib version too old: version searched :${TAGLIB_MIN_VERSION}, found ${TAGLIB_VERSION}")
34     set(TAGLIB_FOUND FALSE)
35  else(TAGLIB_VERSION VERSION_LESS "${TAGLIB_MIN_VERSION}")
36
37     exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --libs RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_LIBRARIES)
38
39     exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --cflags RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_CFLAGS)
40
41     if(TAGLIB_LIBRARIES AND TAGLIB_CFLAGS)
42        set(TAGLIB_FOUND TRUE)
43     endif(TAGLIB_LIBRARIES AND TAGLIB_CFLAGS)
44     string(REGEX REPLACE " *-I" ";" TAGLIB_INCLUDES "${TAGLIB_CFLAGS}")
45  endif(TAGLIB_VERSION VERSION_LESS "${TAGLIB_MIN_VERSION}")
46  mark_as_advanced(TAGLIB_CFLAGS TAGLIB_LIBRARIES TAGLIB_INCLUDES)
47
48else(TAGLIBCONFIG_EXECUTABLE)
49
50  find_path(TAGLIB_INCLUDES
51    NAMES
52    tag.h
53    PATH_SUFFIXES taglib
54    PATHS
55    ${KDE4_INCLUDE_DIR}
56    ${INCLUDE_INSTALL_DIR}
57  )
58
59    IF(NOT WIN32)
60      # on non-win32 we don't need to take care about WIN32_DEBUG_POSTFIX
61
62      FIND_LIBRARY(TAGLIB_LIBRARIES tag PATHS ${KDE4_LIB_DIR} ${LIB_INSTALL_DIR})
63
64    ELSE(NOT WIN32)
65
66      # 1. get all possible libnames
67      SET(args PATHS ${KDE4_LIB_DIR} ${LIB_INSTALL_DIR})
68      SET(newargs "")
69      SET(libnames_release "")
70      SET(libnames_debug "")
71
72      LIST(LENGTH args listCount)
73
74        # just one name
75        LIST(APPEND libnames_release "tag")
76        LIST(APPEND libnames_debug   "tagd")
77
78        SET(newargs ${args})
79
80      # search the release lib
81      FIND_LIBRARY(TAGLIB_LIBRARIES_RELEASE
82                   NAMES ${libnames_release}
83                   ${newargs}
84      )
85
86      # search the debug lib
87      FIND_LIBRARY(TAGLIB_LIBRARIES_DEBUG
88                   NAMES ${libnames_debug}
89                   ${newargs}
90      )
91
92      IF(TAGLIB_LIBRARIES_RELEASE AND TAGLIB_LIBRARIES_DEBUG)
93
94        # both libs found
95        SET(TAGLIB_LIBRARIES optimized ${TAGLIB_LIBRARIES_RELEASE}
96                        debug     ${TAGLIB_LIBRARIES_DEBUG})
97
98      ELSE(TAGLIB_LIBRARIES_RELEASE AND TAGLIB_LIBRARIES_DEBUG)
99
100        IF(TAGLIB_LIBRARIES_RELEASE)
101
102          # only release found
103          SET(TAGLIB_LIBRARIES ${TAGLIB_LIBRARIES_RELEASE})
104
105        ELSE(TAGLIB_LIBRARIES_RELEASE)
106
107          # only debug (or nothing) found
108          SET(TAGLIB_LIBRARIES ${TAGLIB_LIBRARIES_DEBUG})
109
110        ENDIF(TAGLIB_LIBRARIES_RELEASE)
111
112      ENDIF(TAGLIB_LIBRARIES_RELEASE AND TAGLIB_LIBRARIES_DEBUG)
113
114      MARK_AS_ADVANCED(TAGLIB_LIBRARIES_RELEASE)
115      MARK_AS_ADVANCED(TAGLIB_LIBRARIES_DEBUG)
116
117    ENDIF(NOT WIN32)
118
119  INCLUDE(FindPackageMessage)
120  INCLUDE(FindPackageHandleStandardArgs)
121  FIND_PACKAGE_HANDLE_STANDARD_ARGS(Taglib DEFAULT_MSG TAGLIB_INCLUDES TAGLIB_LIBRARIES)
122
123endif(TAGLIBCONFIG_EXECUTABLE)
124
125
126if(TAGLIB_FOUND)
127  if(NOT Taglib_FIND_QUIETLY AND TAGLIBCONFIG_EXECUTABLE)
128    message(STATUS "Taglib found: ${TAGLIB_LIBRARIES}")
129  endif(NOT Taglib_FIND_QUIETLY AND TAGLIBCONFIG_EXECUTABLE)
130else(TAGLIB_FOUND)
131  if(Taglib_FIND_REQUIRED)
132    message(FATAL_ERROR "Could not find Taglib")
133  endif(Taglib_FIND_REQUIRED)
134endif(TAGLIB_FOUND)
135
136