0029296: Data Exchange - implement import of mesh data from files in OBJ format
[occt.git] / adm / cmake / ffmpeg.cmake
1 # FFmpeg
2
3 if (NOT DEFINED INSTALL_FFMPEG)
4   set (INSTALL_FFMPEG OFF CACHE BOOL "${INSTALL_FFMPEG_DESCR}")
5 endif()
6
7 if (NOT DEFINED 3RDPARTY_FFMPEG_DIR)
8   set (3RDPARTY_FFMPEG_DIR "" CACHE PATH "The directory containing FFmpeg")
9 endif()
10
11 # include occt macros. compiler_bitness, os_with_bit, compiler
12 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
13
14 # specify FFMPEG folder in connection with 3RDPARTY_DIR
15 if (3RDPARTY_DIR AND EXISTS "${3RDPARTY_DIR}")
16   if (NOT 3RDPARTY_FFMPEG_DIR OR NOT EXISTS "${3RDPARTY_FFMPEG_DIR}")
17     FIND_PRODUCT_DIR ("${3RDPARTY_DIR}" FFMPEG FFMPEG_DIR_NAME)
18     if (FFMPEG_DIR_NAME)
19       set (3RDPARTY_FFMPEG_DIR "${3RDPARTY_DIR}/${FFMPEG_DIR_NAME}" CACHE PATH "The directory containing FFmpeg" FORCE)
20     endif()
21   endif()
22 else()
23 endif()
24
25 # define required FFMPEG variables
26 if (NOT DEFINED 3RDPARTY_FFMPEG_INCLUDE_DIR)
27   set (3RDPARTY_FFMPEG_INCLUDE_DIR  "" CACHE PATH "the path of headers directory")
28 endif()
29
30 separate_arguments (CSF_FFmpeg)
31 foreach (LIBRARY_NAME ${CSF_FFmpeg})
32   if (NOT DEFINED 3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} OR NOT 3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME} OR NOT EXISTS "${3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME}}")
33     set (3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}               "" CACHE FILEPATH "FFmpeg framework (${LIBRARY_NAME})" FORCE)
34   endif()
35
36   if (NOT DEFINED 3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME})
37     set (3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME}           "" CACHE PATH "The directory containing FFmpeg framework (${LIBRARY_NAME})")
38   endif()
39
40   if (NOT DEFINED 3RDPARTY_FFMPEG_LIBRARY_DIR)
41     set (3RDPARTY_FFMPEG_LIBRARY_DIR                           "" CACHE PATH "The directory containing FFmpeg libraries")
42   endif()
43
44   if (WIN32)
45     if (NOT DEFINED 3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME} OR NOT 3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME} OR NOT EXISTS "${3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME}}")
46       set (3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}                 "" CACHE FILEPATH "FFmpeg shared libraries (${LIBRARY_NAME})" FORCE)
47     endif()
48   endif()
49
50   if (WIN32)
51     if (NOT DEFINED 3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME})
52       set (3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME}               "" CACHE PATH "The directory containing FFmpeg shared libraries (${LIBRARY_NAME})")
53     endif()
54     if (NOT DEFINED 3RDPARTY_FFMPEG_DLL_DIR)
55       set (3RDPARTY_FFMPEG_DLL_DIR                               "" CACHE PATH "The directory containing FFmpeg shared libraries")
56     endif()
57   endif()
58
59   # check 3RDPARTY_${PRODUCT_NAME}_ paths for consistency with specified 3RDPARTY_${PRODUCT_NAME}_DIR
60   if (3RDPARTY_FFMPEG_DIR AND EXISTS "${3RDPARTY_FFMPEG_DIR}")
61     CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_FFMPEG_DIR 3RDPARTY_FFMPEG_INCLUDE_DIR PATH "the path to FFmpeg")
62     CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_FFMPEG_DIR 3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} FILEPATH "the path to FFmpeg framework (${LIBRARY_NAME})")
63
64     if (3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} AND EXISTS "${3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}}")
65       get_filename_component (3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}}" PATH)
66       set (3RDPARTY_FFMPEG_LIBRARY_DIR "${3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME}}" CACHE PATH "The directory containing FFmpeg libraries" FORCE)
67       set (3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME}}" CACHE PATH "The directory containing FFmpeg library (${LIBRARY_NAME})" FORCE)
68     else()
69       CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_FFMPEG_DIR 3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME} PATH "The directory containing FFmpeg library (${LIBRARY_NAME})")
70     endif()
71
72     if (WIN32)
73       CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_FFMPEG_DIR 3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME} FILEPATH "the path to FFmpeg shared library (${LIBRARY_NAME})")
74
75       if (3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME} AND EXISTS "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}")
76         get_filename_component (3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}" PATH)
77         set (3RDPARTY_FFMPEG_DLL_DIR "${3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME}}" CACHE PATH "The directory containing FFmpeg shared libraries" FORCE)
78         set (3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME}}" CACHE PATH "The directory containing FFmpeg shared library (${LIBRARY_NAME})" FORCE)
79       else()
80         CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_FFMPEG_DIR 3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME} PATH "The directory containing FFmpeg shared library (${LIBRARY_NAME})")
81       endif()
82     endif()
83   endif()
84 endforeach()
85
86 # header
87 if (NOT 3RDPARTY_FFMPEG_INCLUDE_DIR OR NOT EXISTS "${3RDPARTY_FFMPEG_INCLUDE_DIR}")
88   set (HEADER_NAMES avutil.h libavutil/avutil.h)
89
90   # set 3RDPARTY_FFMPEG_INCLUDE_DIR as notfound, otherwise find_library can't assign a new value to 3RDPARTY_FFMPEG_INCLUDE_DIR
91   set (3RDPARTY_FFMPEG_INCLUDE_DIR "3RDPARTY_FFMPEG_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "the path to header directory" FORCE)
92
93   if (3RDPARTY_FFMPEG_DIR AND EXISTS "${3RDPARTY_FFMPEG_DIR}")
94     find_path (3RDPARTY_FFMPEG_INCLUDE_DIR NAMES ${HEADER_NAMES}
95                                                  PATHS ${3RDPARTY_FFMPEG_DIR}
96                                                  PATH_SUFFIXES include
97                                                  CMAKE_FIND_ROOT_PATH_BOTH
98                                                  NO_DEFAULT_PATH)
99   else()
100     find_path (3RDPARTY_FFMPEG_INCLUDE_DIR NAMES ${HEADER_NAMES}
101                                                  PATH_SUFFIXES include
102                                                  CMAKE_FIND_ROOT_PATH_BOTH)
103   endif()
104 endif()
105
106 if (3RDPARTY_FFMPEG_INCLUDE_DIR AND EXISTS "${3RDPARTY_FFMPEG_INCLUDE_DIR}")
107   list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_FFMPEG_INCLUDE_DIR}")
108 else()
109   list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_FFMPEG_INCLUDE_DIR)
110
111   set (3RDPARTY_FFMPEG_INCLUDE_DIR "" CACHE FILEPATH "the path to avutil.h" FORCE)
112 endif()
113
114 # libraries
115 foreach (LIBRARY_NAME ${CSF_FFmpeg})
116   if (NOT 3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} OR NOT EXISTS "${3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}}")
117     set (CMAKE_FIND_LIBRARY_SUFFIXES .lib .so .dylib .a)
118
119     set (FFMPEG_PATH_SUFFIXES lib)
120     if (ANDROID)
121       set (FFMPEG_PATH_SUFFIXES ${FFMPEG_PATH_SUFFIXES} libs/${ANDROID_ABI})
122     elseif(APPLE)
123       set (FFMPEG_PATH_SUFFIXES ${FFMPEG_PATH_SUFFIXES} Frameworks)
124     endif()
125
126     # set 3RDPARTY_FFMPEG_LIBRARY as notfound, otherwise find_library can't assign a new value to 3RDPARTY_FFMPEG_LIBRARY
127     set (3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} "3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}-NOTFOUND" CACHE FILEPATH "The path to FFmpeg library (${LIBRARY_NAME})" FORCE)
128
129     if (3RDPARTY_FFMPEG_DIR AND EXISTS "${3RDPARTY_FFMPEG_DIR}")
130       find_library (3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} NAMES ${LIBRARY_NAME}
131                     PATHS "${3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME}}" "${3RDPARTY_FFMPEG_DIR}"
132                     PATH_SUFFIXES ${FFMPEG_PATH_SUFFIXES}
133                     CMAKE_FIND_ROOT_PATH_BOTH
134                     NO_DEFAULT_PATH)
135     else()
136       find_library (3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} NAMES ${LIBRARY_NAME}
137                     PATH_SUFFIXES ${FFMPEG_PATH_SUFFIXES}
138                     CMAKE_FIND_ROOT_PATH_BOTH)
139     endif()
140
141     if (3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} AND EXISTS "${3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}}")
142       get_filename_component (3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}}" PATH)
143       set (3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME}}" CACHE PATH "The directory containing FFmpeg library (${LIBRARY_NAME})" FORCE)
144     else()
145       set (3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME} "" CACHE PATH "The directory containing FFmpeg library (${LIBRARY_NAME})" FORCE)
146     endif()
147   endif()
148
149   if (3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME} AND EXISTS "${3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME}}")
150     list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME}}")
151   else()
152     list (APPEND 3RDPARTY_NO_LIBS 3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME})
153
154     set (3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} "" CACHE FILEPATH "The path to FFmpeg library (${LIBRARY_NAME})" FORCE)
155   endif()
156
157   # shared library
158   if (WIN32)
159     if (NOT 3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME} OR NOT EXISTS "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}")
160
161       set (CMAKE_FIND_LIBRARY_SUFFIXES .dll)
162       set (3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME} "3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}-NOTFOUND" CACHE FILEPATH "The path to FFmpeg shared library (${LIBRARY_NAME})" FORCE)
163
164       # find FFmpeg shared library
165       file (GLOB 3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_DIR}/bin/${LIBRARY_NAME}[-][0-9]*")
166
167       if (3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME} AND EXISTS "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}")
168         set (3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}" CACHE FILEPATH "FFmpeg shared library (${LIBRARY_NAME})" FORCE)
169         get_filename_component (3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}" PATH)
170         set (3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME} "${3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME}}" CACHE PATH "The directory containing FFmpeg library (${LIBRARY_NAME})" FORCE)
171       else()
172         set (3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME} "" CACHE PATH "The directory containing FFmpeg shared library (${LIBRARY_NAME})" FORCE)
173       endif()
174     endif()
175
176     if (3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME} OR EXISTS "${3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME}}")
177       list (APPEND 3RDPARTY_DLL_DIRS "${3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME}}")
178     else()
179       list (APPEND 3RDPARTY_NO_DLLS 3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME})
180     endif()
181   endif()
182
183   # install instructions
184   if (INSTALL_FFMPEG)
185     OCCT_MAKE_OS_WITH_BITNESS()
186     OCCT_MAKE_COMPILER_SHORT_NAME()
187
188     if (WIN32)
189       if (DEFINED INSTALL_BIN_DIR)
190         install (FILES "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}" DESTINATION "${INSTALL_BIN_DIR}")
191       else()
192         install (FILES "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}"
193                  CONFIGURATIONS Release
194                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
195         install (FILES "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}"
196                  CONFIGURATIONS RelWithDebInfo
197                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
198         install (FILES "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}"
199                  CONFIGURATIONS Debug
200                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
201       endif()
202     else()
203       get_filename_component(3RDPARTY_FFMPEG_LIBRARY_ABS ${3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}} REALPATH)
204       get_filename_component(3RDPARTY_FFMPEG_LIBRARY_NAME ${3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}} NAME)
205
206       if (DEFINED INSTALL_LIB_DIR)
207         install (FILES "${3RDPARTY_FFMPEG_LIBRARY_ABS}"
208                  DESTINATION "${INSTALL_LIB_DIR}"
209                  RENAME ${3RDPARTY_FFMPEG_LIBRARY_NAME}.6)
210       else()
211         install (FILES "${3RDPARTY_FFMPEG_LIBRARY_ABS}"
212                  CONFIGURATIONS Release
213                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
214                  RENAME ${3RDPARTY_FFMPEG_LIBRARY_NAME}.6)
215         install (FILES "${3RDPARTY_FFMPEG_LIBRARY_ABS}"
216                  CONFIGURATIONS RelWithDebInfo
217                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi"
218                  RENAME ${3RDPARTY_FFMPEG_LIBRARY_NAME}.6)
219         install (FILES "${3RDPARTY_FFMPEG_LIBRARY_ABS}"
220                  CONFIGURATIONS Debug
221                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
222                  RENAME ${3RDPARTY_FFMPEG_LIBRARY_NAME}.6)
223       endif()
224     endif()
225
226     set (USED_3RDPARTY_FFMPEG_DIR "")
227   else()
228     # the library directory for using by the executable
229     if (WIN32)
230       set (USED_3RDPARTY_FFMPEG_DIR ${3RDPARTY_FFMPEG_DLL_DIR_${LIBRARY_NAME}})
231     else()
232       set (USED_3RDPARTY_FFMPEG_DIR ${3RDPARTY_FFMPEG_LIBRARY_DIR_${LIBRARY_NAME}})
233     endif()
234   endif()
235
236   mark_as_advanced (3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME} 3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME})
237 endforeach()
238
239 # unset all redundant variables
240 OCCT_CHECK_AND_UNSET (FFMPEG_INCLUDE_DIRS)
241 OCCT_CHECK_AND_UNSET (FFMPEG_LIBRARY_DIRS)
242 OCCT_CHECK_AND_UNSET (FFMPEG_DIR)