2
2
# CMake module to search for LIBVLC (VLC library)
3
3
# Authors: Rohit Yadav <[email protected] >
4
4
# Harald Sitter <[email protected] >
5
+ # Alexander Grund <[email protected] >
5
6
#
6
- # If it's found it sets LIBVLC_FOUND to TRUE
7
- # and following variables are set:
8
- # LIBVLC_INCLUDE_DIR
9
- # LIBVLC_LIBRARY
10
- # LIBVLC_VERSION
11
-
12
- if (NOT LIBVLC_MIN_VERSION)
13
- set (LIBVLC_MIN_VERSION "0.0" )
14
- endif (NOT LIBVLC_MIN_VERSION)
15
-
16
- # find_path and find_library normally search standard locations
17
- # before the specified paths. To search non-standard paths first,
18
- # FIND_* is invoked first with specified paths and NO_DEFAULT_PATH
19
- # and then again with no specified paths to search the default
20
- # locations. When an earlier FIND_* succeeds, subsequent FIND_*s
21
- # searching for the same item do nothing.
7
+ # If it's found it defines the following targets:
8
+ # - libvlc::libvlc
9
+ # - libvlc::plugin
22
10
23
11
if (NOT WIN32 )
24
- find_package (PkgConfig)
25
- pkg_check_modules(PC_LIBVLC libvlc)
12
+ find_package (PkgConfig REQUIRED )
13
+ pkg_check_modules(PC_LIBVLC libvlc QUIET )
26
14
set (LIBVLC_DEFINITIONS ${PC_LIBVLC_CFLAGS_OTHER} )
27
- set (LIBVLC_INCLUDE_DIRS ${PC_LIBVLC_INCLUDEDIR} ${PC_LIBVLC_INCLUDE_DIRS} )
28
15
29
- pkg_check_modules(PC_VLCPLUGIN vlc-plugin)
16
+ pkg_check_modules(PC_VLCPLUGIN vlc-plugin QUIET )
30
17
set (VLCPLUGIN_DEFINITIONS ${PC_VLCPLUGIN_CFLAGS_OTHER} )
31
- set (VLCPLUGIN_INCLUDE_DIRS ${PC_VLCPLUGIN_INCLUDEDIR} ${PC_VLCPLUGIN_INCLUDE_DIRS} )
32
18
33
19
pkg_get_variable(PC_VLCPLUGIN_PLUGINS_PATH vlc-plugin pluginsdir)
34
20
set (VLCPLUGIN_CODEC_INSTALL_PATH ${PC_VLCPLUGIN_PLUGINS_PATH} /codec)
35
-
36
- message ("-- VLC Lib include path is \" ${LIBVLC_INCLUDE_DIRS} \" ==" )
37
- message ("-- VLC Plugins include path is \" ${VLCPLUGIN_INCLUDE_DIRS} \" ==" )
38
- message ("-- VLC Plugins path is \" ${VLCPLUGIN_CODEC_INSTALL_PATH} \" ==" )
39
21
else ()
40
22
set (LIBVLC_DEFINITIONS)
41
23
# FIXME: Is "_FILE_OFFSET_BITS=64" correct for Windows?
@@ -49,70 +31,73 @@ else()
49
31
set (VLCPLUGIN_CODEC_INSTALL_PATH "C:/Program Files/VideoLAN/VLC/plugins/codec" )
50
32
endif ()
51
33
52
- #Put here path to custom location
53
- #example: /home/user/vlc/include etc..
54
- find_path (LIBVLC_INCLUDE_DIR vlc/vlc.h
55
- HINTS "$ENV{LIBVLC_INCLUDE_PATH} "
56
- PATHS
57
- "$ENV{LIB_DIR} /include"
58
- "$ENV{LIB_DIR} /include/vlc"
59
- "/usr/include"
60
- "/usr/include/vlc"
61
- "/usr/local/include"
62
- "/usr/local/include/vlc"
63
- #mingw
64
- ${CMAKE_PREFIX_PATH} /include
65
- c:/msys/local/include
66
- )
67
- find_path (LIBVLC_INCLUDE_DIR PATHS "${CMAKE_INCLUDE_PATH} /vlc" NAMES vlc.h
68
- HINTS ${PC_LIBVLC_INCLUDEDIR} ${PC_LIBVLC_INCLUDE_DIRS} )
34
+ foreach (lib libvlc vlcplugin)
35
+ string (TOUPPER ${lib} upperLib)
36
+ if (lib STREQUAL "vlcplugin" )
37
+ set (headerFile vlc_common.h)
38
+ set (suffixes vlc/plugins include /vlc/plugins)
39
+ else ()
40
+ set (headerFile vlc/libvlc.h)
41
+ set (suffixes )
42
+ endif ()
43
+ find_path (${upperLib} _INCLUDE_DIR ${headerFile}
44
+ HINTS ${PC_${upperLib} _INCLUDEDIR} ${PC_${upperLib} _INCLUDE_DIRS} $ENV{LIBVLC_INCLUDE_PATH}
45
+ PATH_SUFFIXES include ${suffixes}
46
+ NO_DEFAULT_PATH
47
+ )
48
+ find_path (${upperLib} _INCLUDE_DIR ${headerFile}
49
+ PATHS $ENV{LIB_DIR}
50
+ C:/msys/local #mingw
51
+ PATH_SUFFIXES include ${suffixes}
52
+ )
53
+ endforeach ()
69
54
70
- #Put here path to custom location
71
- #example: /home/user/vlc/lib etc..
72
- find_library (LIBVLC_LIBRARY NAMES vlc libvlc
73
- HINTS "$ENV{LIBVLC_LIBRARY_PATH} " ${PC_LIBVLC_LIBDIR} ${PC_LIBVLC_LIBRARY_DIRS}
74
- PATHS
75
- "$ENV{LIB_DIR} /lib"
76
- #mingw
77
- ${CMAKE_PREFIX_PATH} /lib
78
- c:/msys/local/lib
79
- )
80
- find_library (LIBVLC_LIBRARY NAMES vlc libvlc)
81
- find_library (LIBVLCCORE_LIBRARY NAMES vlccore libvlccore
82
- HINTS "$ENV{LIBVLC_LIBRARY_PATH} " ${PC_LIBVLC_LIBDIR} ${PC_LIBVLC_LIBRARY_DIRS}
83
- PATHS
84
- "$ENV{LIB_DIR} /lib"
85
- #mingw
86
- ${CMAKE_PREFIX_PATH} /lib
87
- c:/msys/local/lib
88
- )
89
- find_library (LIBVLCCORE_LIBRARY NAMES vlccore libvlccore)
55
+ foreach (lib vlc vlccore)
56
+ string (TOUPPER ${lib} upperLib)
57
+ find_library (LIB${upperLib} _LIBRARY ${lib} lib${lib}
58
+ HINTS ${PC_LIBVLC_LIBDIR} ${PC_LIBVLC_LIBRARY_DIRS} $ENV{LIBVLC_LIBRARY_PATH}
59
+ PATH_SUFFIXES lib
60
+ NO_DEFAULT_PATH
61
+ )
62
+ find_library (LIB${upperLib} _LIBRARY ${lib} lib${lib}
63
+ PATHS $ENV{LIB_DIR}
64
+ C:/msys/local #mingw
65
+ PATH_SUFFIXES lib
66
+ )
67
+ endforeach ()
90
68
91
- set (LIBVLC_VERSION ${PC_LIBVLC_VERSION} )
92
- if (NOT LIBVLC_VERSION)
93
- # TODO: implement means to detect version on windows (vlc --version && regex? ... ultimately we would get it from a header though...)
94
- endif (NOT LIBVLC_VERSION)
69
+ if (LIBVLC_INCLUDE_DIR)
70
+ set (vlcVersionFile ${LIBVLC_INCLUDE_DIR} /vlc/libvlc_version.h)
71
+ if (EXISTS ${vlcVersionFile} )
72
+ file (STRINGS ${vlcVersionFile} versionStrings REGEX "#[ \t ]*define[ \t ]+LIBVLC_VERSION_(MAJOR|MINOR|REVISION|EXTRA)[ \t ]+\\ (?[0-9]+\\ )?" )
73
+ if (NOT versionStrings)
74
+ message (FATAL_ERROR "Could not read version from ${vlcVersionFile} " )
75
+ endif ()
76
+ foreach (item MAJOR MINOR REVISION EXTRA)
77
+ string (REGEX REPLACE "#[ \t ]*define[ \t ]+LIBVLC_VERSION_${item} [ \t ]+\\ (?([0-9]+)\\ )?" "\\ 1" LIBVLC_VERSION_${item} ${versionStrings} )
78
+ endforeach ()
79
+ set (LIBVLC_VERSION ${LIBVLC_VERSION_MAJOR} .${LIBVLC_VERSION_MINOR} .${LIBVLC_VERSION_REVISION} .${LIBVLC_VERSION_EXTRA} )
80
+ endif ()
81
+ endif ()
95
82
96
- if (LIBVLC_INCLUDE_DIR AND LIBVLC_LIBRARY AND LIBVLCCORE_LIBRARY)
97
- set (LIBVLC_FOUND TRUE )
98
- endif (LIBVLC_INCLUDE_DIR AND LIBVLC_LIBRARY AND LIBVLCCORE_LIBRARY)
83
+ include (FindPackageHandleStandardArgs)
99
84
100
- if (LIBVLC_VERSION STRLESS "${LIBVLC_MIN_VERSION} " )
101
- message (WARNING "LibVLC version not found: version searched: ${LIBVLC_MIN_VERSION} , found ${LIBVLC_VERSION} \n Unless you are on Windows this is bound to fail." )
102
- # TODO: only activate once version detection can be garunteed (which is currently not the case on windows)
103
- # set(LIBVLC_FOUND FALSE)
104
- endif (LIBVLC_VERSION STRLESS "${LIBVLC_MIN_VERSION} " )
85
+ find_package_handle_standard_args(LIBVLC
86
+ REQUIRED_VARS LIBVLC_INCLUDE_DIR VLCPLUGIN_INCLUDE_DIR LIBVLC_LIBRARY LIBVLCCORE_LIBRARY
87
+ VERSION_VAR LIBVLC_VERSION
88
+ )
105
89
106
- if (LIBVLC_FOUND)
107
- if (NOT LIBVLC_FIND_QUIETLY)
108
- message (STATUS "Found LibVLC include-dir path: ${LIBVLC_INCLUDE_DIR} " )
109
- message (STATUS "Found LibVLC library path:${LIBVLC_LIBRARY} " )
110
- message (STATUS "Found LibVLCcore library path:${LIBVLCCORE_LIBRARY} " )
111
- message (STATUS "Found LibVLC version: ${LIBVLC_VERSION} (searched for: ${LIBVLC_MIN_VERSION} )" )
112
- endif (NOT LIBVLC_FIND_QUIETLY)
113
- else (LIBVLC_FOUND)
114
- if (LIBVLC_FIND_REQUIRED)
115
- message (FATAL_ERROR "Could not find LibVLC" )
116
- endif (LIBVLC_FIND_REQUIRED)
117
- endif (LIBVLC_FOUND)
90
+ if (LIBVLC_FOUND)
91
+ add_library (libvlc_libvlc INTERFACE )
92
+ target_compile_definitions (libvlc_libvlc INTERFACE ${LIBVLC_DEFINITIONS} )
93
+ target_include_directories (libvlc_libvlc INTERFACE ${LIBVLC_INCLUDE_DIR} )
94
+ target_link_libraries (libvlc_libvlc INTERFACE ${LIBVLC_LIBRARY} )
95
+
96
+ add_library (libvlc_plugin INTERFACE )
97
+ target_include_directories (libvlc_plugin INTERFACE ${LIBVLC_INCLUDE_DIR} ${VLCPLUGIN_INCLUDE_DIR} )
98
+ target_compile_definitions (libvlc_plugin INTERFACE ${VLCPLUGIN_DEFINITIONS} )
99
+ target_link_libraries (libvlc_plugin INTERFACE ${LIBVLCCORE_LIBRARY} )
118
100
101
+ add_library (libvlc::libvlc ALIAS libvlc_libvlc)
102
+ add_library (libvlc::plugin ALIAS libvlc_plugin)
103
+ endif ()
0 commit comments