Build Environment: fix alembic, openvdb, ffmpeg, osl build on Linux.
[blender.git] / build_files / build_environment / cmake / ffmpeg.cmake
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ***** END GPL LICENSE BLOCK *****
18
19 set(FFMPEG_CFLAGS "-I${mingw_LIBDIR}/lame/include -I${mingw_LIBDIR}/openjpeg/include/ -I${mingw_LIBDIR}/ogg/include -I${mingw_LIBDIR}/vorbis/include -I${mingw_LIBDIR}/theora/include -I${mingw_LIBDIR}/vpx/include -I${mingw_LIBDIR}/x264/include -I${mingw_LIBDIR}/xvidcore/include -I${mingw_LIBDIR}/zlib/include")
20 set(FFMPEG_LDFLAGS "-L${mingw_LIBDIR}/lame/lib -L${mingw_LIBDIR}/openjpeg/lib -L${mingw_LIBDIR}/ogg/lib -L${mingw_LIBDIR}/vorbis/lib -L${mingw_LIBDIR}/theora/lib -L${mingw_LIBDIR}/vpx/lib -L${mingw_LIBDIR}/x264/lib -L${mingw_LIBDIR}/xvidcore/lib -L${mingw_LIBDIR}/zlib/lib")
21 set(FFMPEG_EXTRA_FLAGS --pkg-config-flags=--static --extra-cflags=${FFMPEG_CFLAGS} --extra-ldflags=${FFMPEG_LDFLAGS})
22 set(FFMPEG_ENV PKG_CONFIG_PATH=${mingw_LIBDIR}/openjpeg/lib/pkgconfig:${mingw_LIBDIR}/x264/lib/pkgconfig:${mingw_LIBDIR}/vorbis/lib/pkgconfig:${mingw_LIBDIR}/ogg/lib/pkgconfig:${mingw_LIBDIR})
23
24 if(WIN32)
25         set(FFMPEG_ENV set ${FFMPEG_ENV} &&)
26         set(FFMPEG_EXTRA_FLAGS
27                 ${FFMPEG_EXTRA_FLAGS}
28                 --disable-static
29                 --enable-shared
30                 --enable-w32threads
31                 --disable-pthreads
32                 --enable-libopenjpeg
33         )
34         if("${CMAKE_SIZEOF_VOID_P}" EQUAL "4")
35                 set(FFMPEG_EXTRA_FLAGS
36                         ${FFMPEG_EXTRA_FLAGS}
37                         --x86asmexe=yasm
38                 )
39         endif()
40 else()
41         set(FFMPEG_EXTRA_FLAGS
42                 ${FFMPEG_EXTRA_FLAGS}
43                 --enable-static
44                 --disable-shared
45                 --enable-libopenjpeg
46         )
47 endif()
48
49 if(APPLE)
50         set(FFMPEG_EXTRA_FLAGS
51                 ${FFMPEG_EXTRA_FLAGS}
52                 --target-os=darwin
53                 )
54 endif()
55
56 ExternalProject_Add(external_ffmpeg
57         URL ${FFMPEG_URI}
58         DOWNLOAD_DIR ${DOWNLOAD_DIR}
59         URL_HASH MD5=${FFMPEG_HASH}
60         # OpenJpeg is compiled with pthread support on Linux, which is all fine and is what we
61         # want for maximum runtime performance, but due to static nature of that library we
62         # need to force ffmpeg to link against pthread, otherwise test program used by autoconf
63         # will fail. This patch does that in a way that is compatible with multiple distributions.
64         PATCH_COMMAND ${PATCH_CMD} --verbose -p 1 -N -d ${BUILD_DIR}/ffmpeg/src/external_ffmpeg < ${PATCH_DIR}/ffmpeg.diff
65         PREFIX ${BUILD_DIR}/ffmpeg
66         CONFIGURE_COMMAND ${CONFIGURE_ENV_NO_PERL} &&
67                 cd ${BUILD_DIR}/ffmpeg/src/external_ffmpeg/ &&
68                 ${FFMPEG_ENV} ${CONFIGURE_COMMAND_NO_TARGET} ${FFMPEG_EXTRA_FLAGS}
69                 --disable-lzma
70                 --disable-avfilter
71                 --disable-vdpau
72                 --disable-bzlib
73                 --disable-libgsm
74                 --disable-libspeex
75                 --enable-libvpx
76                 --prefix=${LIBDIR}/ffmpeg
77                 --enable-libtheora
78                 --enable-libvorbis
79                 --enable-zlib
80                 --enable-stripping
81                 --enable-runtime-cpudetect
82                 --disable-vaapi
83                 --disable-nonfree
84                 --enable-gpl
85                 --disable-postproc
86                 --enable-libmp3lame
87                 --disable-librtmp
88                 --enable-libx264
89                 --enable-libxvid
90                 --disable-libopencore-amrnb
91                 --disable-libopencore-amrwb
92                 --disable-libdc1394
93                 --disable-version3
94                 --disable-debug
95                 --enable-optimizations
96                 --disable-sse
97                 --disable-ssse3
98                 --enable-ffplay
99                 --disable-openssl
100                 --disable-securetransport
101                 --disable-indev=avfoundation
102                 --disable-indev=qtkit
103                 --disable-sdl2
104                 --disable-gnutls
105                 --disable-videotoolbox
106                 --disable-libxcb
107                 --disable-xlib
108                 --disable-audiotoolbox
109                 --disable-cuvid
110                 --disable-nvenc
111                 --disable-indev=jack
112                 --disable-indev=alsa
113                 --disable-outdev=alsa
114                 --disable-crystalhd
115         BUILD_COMMAND ${CONFIGURE_ENV_NO_PERL} && cd ${BUILD_DIR}/ffmpeg/src/external_ffmpeg/ && make -j${MAKE_THREADS}
116         INSTALL_COMMAND ${CONFIGURE_ENV_NO_PERL} && cd ${BUILD_DIR}/ffmpeg/src/external_ffmpeg/ && make install
117         CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBDIR}/ffmpeg ${DEFAULT_CMAKE_FLAGS}
118         INSTALL_DIR ${LIBDIR}/ffmpeg
119 )
120
121 if(MSVC)
122         set_target_properties(external_ffmpeg PROPERTIES FOLDER Mingw)
123 endif()
124
125 add_dependencies(
126         external_ffmpeg
127         external_zlib
128         external_faad
129         external_openjpeg
130         external_xvidcore
131         external_x264
132         external_vpx
133         external_theora
134         external_vorbis
135         external_ogg
136         external_lame
137 )
138 if(WIN32)
139         add_dependencies(
140                 external_ffmpeg
141                 external_zlib_mingw
142         )
143 endif()
144
145 if(BUILD_MODE STREQUAL Release AND WIN32)
146         ExternalProject_Add_Step(external_ffmpeg after_install
147                 COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/ffmpeg/include ${HARVEST_TARGET}/ffmpeg/include
148                 COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/ffmpeg/bin ${HARVEST_TARGET}/ffmpeg/lib
149                 DEPENDEES install
150         )
151 endif()