|
| 1 | +import conans |
| 2 | +import filecmp |
| 3 | +import io |
| 4 | +import os |
| 5 | +import re |
| 6 | +import shutil |
| 7 | + |
| 8 | +class FfmpegConan(conans.ConanFile): |
| 9 | + name = 'ffmpeg' |
| 10 | + version = '4.4' |
| 11 | + settings = 'os', 'arch', 'build_type' |
| 12 | + requires = 'openh264/2.1.1@froglogic/dist' |
| 13 | + generators = 'pkg_config' |
| 14 | + no_copy_source = True |
| 15 | + win_bash = True |
| 16 | + revision_mode = 'scm' |
| 17 | + python_requires = 'dockerRecipe/1.0.0@froglogic/util' |
| 18 | + python_requires_extend = 'dockerRecipe.DockerRecipe' |
| 19 | + |
| 20 | + options = { |
| 21 | + 'buildSuffix': 'ANY', |
| 22 | + } |
| 23 | + default_options = { |
| 24 | + 'buildSuffix': None, |
| 25 | + } |
| 26 | + scm = { |
| 27 | + 'type': 'git', |
| 28 | + 'url': 'auto', |
| 29 | + 'revision': 'auto', |
| 30 | + } |
| 31 | + docker = { |
| 32 | + 'Linux': { |
| 33 | + 'image': '/squishbuild/centos6:6.8.0', |
| 34 | + }, |
| 35 | + } |
| 36 | + |
| 37 | + def __libLinkExt(self): |
| 38 | + if self.settings.os == 'Windows': |
| 39 | + return 'lib' |
| 40 | + elif self.settings.os == 'Linux': |
| 41 | + return 'so' |
| 42 | + elif self.settings.os == 'Macos': |
| 43 | + return 'dylib' |
| 44 | + else: |
| 45 | + return '' |
| 46 | + |
| 47 | + def configure(self): |
| 48 | + if self.settings.os != 'Windows': |
| 49 | + self.build_requires = [ 'nasm/2.10.09@froglogic/util' ] |
| 50 | + if self.settings.os == 'Macos': |
| 51 | + del self.settings.arch |
| 52 | + |
| 53 | + def cmdPrefix(self): |
| 54 | + if self.settings.os == 'Linux': |
| 55 | + paths = [*self.deps_cpp_info['nasm'].bin_paths, '$PATH'] |
| 56 | + return 'export PATH=' + ':'.join(paths) + '; ' |
| 57 | + elif self.settings.os == 'Windows': |
| 58 | + return 'export PKG_CONFIG_PATH=' + conans.tools.unix_path(self.build_folder, path_flavor='msys2') + ' && ' |
| 59 | + else: |
| 60 | + return '' |
| 61 | + |
| 62 | + def buildFor(self, arch, prefix): |
| 63 | + configure = os.path.join(self.source_folder, 'configure') |
| 64 | + configure = conans.tools.unix_path(configure, path_flavor='msys2') |
| 65 | + prefix = conans.tools.unix_path(prefix, path_flavor='msys2') |
| 66 | + cmd = self.cmdPrefix() |
| 67 | + cmd += configure |
| 68 | + cmd += ' --prefix=%s' % prefix |
| 69 | + cmd += ' --disable-static' |
| 70 | + cmd += ' --enable-shared' |
| 71 | + cmd += ' --disable-all' |
| 72 | + cmd += ' --disable-autodetect' |
| 73 | + cmd += ' --enable-ffmpeg' |
| 74 | + cmd += ' --disable-doc' |
| 75 | + cmd += ' --enable-avcodec' |
| 76 | + cmd += ' --enable-avformat' |
| 77 | + cmd += ' --enable-swscale' |
| 78 | + cmd += ' --disable-everything' |
| 79 | + cmd += ' --enable-libopenh264' |
| 80 | + cmd += ' --enable-encoder=libopenh264' |
| 81 | + cmd += ' --enable-protocol=file' |
| 82 | + cmd += ' --enable-muxer=mp4' |
| 83 | + cmd += ' --enable-debug' |
| 84 | + cmd += ' --disable-rpath' |
| 85 | + cmd += ' --disable-stripping' |
| 86 | + cmd += ' --install-name-dir=@rpath' |
| 87 | + |
| 88 | + if self.options.buildSuffix: |
| 89 | + cmd += ' --build-suffix=%s' % self.options.buildSuffix |
| 90 | + |
| 91 | + if self.settings.os == 'Windows': |
| 92 | + cmd += ' --toolchain=msvc' |
| 93 | + |
| 94 | + archMap = { |
| 95 | + 'x86': 'i686', |
| 96 | + 'x86_64': 'x86_64', |
| 97 | + 'armv8': 'arm64', |
| 98 | + } |
| 99 | + |
| 100 | + cmd += ' --arch=%s' % archMap[str(arch)] |
| 101 | + |
| 102 | + if self.settings.os == 'Linux' and arch == 'x86': |
| 103 | + cmd += ' --extra-cflags=-m32' |
| 104 | + cmd += ' --extra-cxxflags=-m32' |
| 105 | + cmd += ' --extra-ldflags=-m32' |
| 106 | + |
| 107 | + if self.settings.os == 'Macos' and arch == 'x86_64': |
| 108 | + cmd += ' --extra-cflags=--target=x86_64-apple-darwin17.7.0' |
| 109 | + cmd += ' --extra-cxxflags=--target=x86_64-apple-darwin17.7.0' |
| 110 | + cmd += ' --extra-ldflags=--target=x86_64-apple-darwin17.7.0' |
| 111 | + |
| 112 | + self.run(cmd) |
| 113 | + |
| 114 | + cmd = self.cmdPrefix() |
| 115 | + cmd += 'make -j%d' % conans.tools.cpu_count() |
| 116 | + self.run(cmd) |
| 117 | + |
| 118 | + def buildWindows(self): |
| 119 | + msvcEnv = conans.client.tools.vcvars_dict(self, compiler_version='14') |
| 120 | + for name, value in msvcEnv.items(): |
| 121 | + if isinstance(value, list): |
| 122 | + value = os.pathsep.join(value) |
| 123 | + os.environ[name] = value |
| 124 | + self.buildFor(self.settings.arch, self.package_folder) |
| 125 | + |
| 126 | + def buildLinux(self): |
| 127 | + os.environ['PKG_CONFIG_PATH'] = self.build_folder |
| 128 | + self.buildFor(self.settings.arch, self.package_folder) |
| 129 | + |
| 130 | + def buildMacos(self): |
| 131 | + os.environ['PKG_CONFIG_PATH'] = self.build_folder |
| 132 | + bld = os.path.join(self.build_folder, 'x86_64') |
| 133 | + os.mkdir(bld) |
| 134 | + os.chdir(bld) |
| 135 | + self.buildFor('x86_64', self.package_folder) |
| 136 | + |
| 137 | + bld = os.path.join(self.build_folder, 'armv8') |
| 138 | + os.mkdir(bld) |
| 139 | + os.chdir(bld) |
| 140 | + self.buildFor('armv8', bld + '-install') |
| 141 | + cmd = self.cmdPrefix() |
| 142 | + cmd += 'make install' |
| 143 | + self.run(cmd) |
| 144 | + |
| 145 | + def build(self): |
| 146 | + getattr(self, 'build%s' % self.settings.os)() |
| 147 | + |
| 148 | + def compareDirs(self, dir1, dir2): |
| 149 | + for entry in os.scandir(dir1): |
| 150 | + entry2 = os.path.join(dir2, entry.name) |
| 151 | + if entry.is_dir(): |
| 152 | + if os.path.islink(entry2) or not os.path.isdir(entry2): |
| 153 | + raise Exception("Difference: %s is not a directory" % entry2) |
| 154 | + self.compareDirs(entry.path, entry2) |
| 155 | + |
| 156 | + elif entry.is_file() and not entry.is_symlink(): |
| 157 | + if os.path.islink(entry2) or not os.path.isfile(entry2): |
| 158 | + raise Exception("Difference: %s is not a file" % entry2) |
| 159 | + if not filecmp.cmp(entry.path, entry2, shallow=False): |
| 160 | + raise Exception("Difference: %s and %s are different" % (entry.path, entry2)) |
| 161 | + |
| 162 | + def query(self, *args, **kwargs): |
| 163 | + outBuf = io.StringIO() |
| 164 | + kwargs['output'] = outBuf |
| 165 | + self.run(*args, **kwargs) |
| 166 | + return outBuf.getvalue().strip() |
| 167 | + |
| 168 | + def package(self): |
| 169 | + if self.settings.os == 'Macos': |
| 170 | + bld = os.path.join(self.build_folder, 'x86_64') |
| 171 | + os.chdir(bld) |
| 172 | + |
| 173 | + cmd = self.cmdPrefix() |
| 174 | + cmd += 'make install' |
| 175 | + self.run(cmd) |
| 176 | + |
| 177 | + suffix = self.options.buildSuffix if self.options.buildSuffix else '' |
| 178 | + libPrefix = '' if self.settings.os == 'Windows' else 'lib' |
| 179 | + linkPattern = re.compile('^(%s[^.]+)%s(\\.%s)$' % (libPrefix, suffix, self.__libLinkExt())) |
| 180 | + libraryPattern = re.compile('^%s.+%s\\..+\\.%s$' % (libPrefix, suffix, self.__libLinkExt())) |
| 181 | + |
| 182 | + libdir = 'bin' if self.settings.os == 'Windows' else 'lib' |
| 183 | + libdir = os.path.join(self.package_folder, libdir) |
| 184 | + if self.options.buildSuffix: |
| 185 | + for entry in os.scandir(libdir): |
| 186 | + match = linkPattern.match(entry.name) |
| 187 | + if match: |
| 188 | + linkPath = os.path.join(libdir, match.group(1) + match.group(2)) |
| 189 | + shutil.copy(entry.path, linkPath, follow_symlinks=False) |
| 190 | + |
| 191 | + if self.settings.os == 'Macos': |
| 192 | + armLibdir = os.path.join(self.build_folder, 'armv8-install', 'lib') |
| 193 | + for entry in os.scandir(libdir): |
| 194 | + if entry.is_file() and not entry.is_symlink(): |
| 195 | + if libraryPattern.match(entry.name): |
| 196 | + tmpName = entry.path + '-tmp' |
| 197 | + armName = os.path.join(armLibdir, entry.name) |
| 198 | + os.rename(entry.path, tmpName) |
| 199 | + self.run('lipo %s %s -create -output %s' % (tmpName, armName, entry.path)) |
| 200 | + os.unlink(tmpName) |
| 201 | + |
| 202 | + self.run('install_name_tool -add_rpath "@loader_path" "%s"' % entry.path) |
| 203 | + |
| 204 | + |
| 205 | + incdir = os.path.join(self.package_folder, 'include') |
| 206 | + armIncdir = os.path.join(self.build_folder, 'armv8-install', 'include') |
| 207 | + self.compareDirs(incdir, armIncdir) |
| 208 | + self.compareDirs(armIncdir, incdir) |
0 commit comments