1from conans import CMake, ConanFile, tools 2from conans.errors import ConanException 3 4 5class GerberaConan(ConanFile): 6 name = "gerbera" 7 license = "GPLv2" 8 9 generators = ("cmake", "cmake_find_package", "virtualrunenv") 10 settings = "os", "arch", "compiler", "build_type" 11 options = { 12 "js": [True, False], 13 "debug_logging": [True, False], 14 "tests": [True, False], 15 "magic": [True, False], 16 "curl": [True, False], 17 "taglib": [True, False], 18 "exif": [True, False], 19 "matroska": [True, False], 20 "mysql": [True, False], 21 "ffmpeg": [True, False], 22 "ffmpegthumbnailer": [True, False], 23 } 24 default_options = { 25 "js": True, 26 "debug_logging": False, 27 "tests": False, 28 "magic": True, 29 "curl": True, 30 "taglib": True, 31 "exif": True, 32 "matroska": True, 33 # The following are false in CMakeLists.txt, but almost always turned on. 34 "mysql": True, 35 "ffmpeg": True, 36 "ffmpegthumbnailer": True, 37 } 38 39 scm = {"type": "git", "url": "auto", "revision": "auto"} 40 41 requires = [ 42 "cmake/[>=3.18.0]", 43 "fmt/7.1.3", 44 "spdlog/1.8.5", 45 "pugixml/1.10", 46 "libiconv/1.16", 47 "sqlite3/[>=3.35.5]", 48 "zlib/1.2.11", 49 "pupnp/[>=1.14.0]", 50 ] 51 52 def configure(self): 53 tools.check_min_cppstd(self, "17") 54 if self.options.tests: 55 # We have our own main function, 56 # Moreover, if "shared" is True then main is an .so... 57 self.options["gtest"].no_main = True 58 59 @property 60 def _needs_system_uuid(self): 61 if self.options.ffmpeg: 62 os_info = tools.OSInfo() 63 # ffmpeg on Ubuntu has libuuid as a deep transitive dependency 64 # and fails to link otherwise. 65 return os_info.with_apt 66 67 def requirements(self): 68 if self.options.tests: 69 self.requires("gtest/1.10.0") 70 71 if self.options.js: 72 self.requires("duktape/2.5.0") 73 74 if self.options.curl: 75 self.requires("libcurl/[>=7.74.0]") 76 77 if self.options.mysql: 78 self.requires("mariadb-connector-c/3.1.11") 79 80 if not self._needs_system_uuid: 81 self.requires("libuuid/1.0.3") 82 83 def system_requirements(self): 84 if tools.cross_building(self): 85 self.output.info("Cross-compiling, not installing system packages") 86 return 87 88 os_info = tools.OSInfo() 89 if os_info.with_apt: 90 pm = "apt" 91 elif os_info.with_pacman: 92 pm = "pacman" 93 elif os_info.with_yum: 94 pm = "yum" 95 elif os_info.is_freebsd: 96 pm = "freebsd" 97 else: 98 self.output.warn("Don't know how to install packages.") 99 return 100 101 installer = tools.SystemPackageTool(conanfile=self) 102 if self.options.magic: 103 installer.install( 104 { 105 "apt": "libmagic-dev", 106 "pacman": "file", 107 "yum": "file-devel", 108 "freebsd": [], 109 }[pm] 110 ) 111 112 if self.options.taglib: 113 installer.install( 114 { 115 "apt": "libtag1-dev", 116 "pacman": "taglib", 117 "yum": "libtag-devel", 118 "freebsd": "taglib", 119 }[pm] 120 ) 121 122 if self.options.exif: 123 installer.install( 124 { 125 "apt": "libexif-dev", 126 "pacman": "libexif", 127 "yum": "libexif-devel", 128 "freebsd": "libexif", 129 }[pm] 130 ) 131 132 if self.options.matroska: 133 installer.install( 134 { 135 "apt": "libmatroska-dev", 136 "pacman": "libmatroska", 137 "yum": "libmatroska-devel", 138 "freebsd": "libmatroska", 139 }[pm] 140 ) 141 142 if self.options.ffmpeg: 143 installer.install( 144 { 145 "apt": "libavformat-dev", 146 "pacman": "ffmpeg", 147 "yum": "ffmpeg-devel", 148 "freebsd": "ffmpeg", 149 }[pm] 150 ) 151 152 if self._needs_system_uuid: 153 installer.install( 154 {"apt": "uuid-dev", "pacman": [], "yum": [], "freebsd": []}[pm] 155 ) 156 157 if self.options.ffmpegthumbnailer: 158 installer.install( 159 { 160 "apt": "libffmpegthumbnailer-dev", 161 "pacman": "ffmpegthumbnailer", 162 "yum": "ffmpegthumbnailer-devel", 163 "freebsd": "ffmpegthumbnailer", 164 }[pm] 165 ) 166 167 def build(self): 168 cmake = CMake(self) 169 cmake.definitions["WITH_JS"] = self.options.js 170 cmake.definitions["WITH_DEBUG"] = self.options.debug_logging 171 cmake.definitions["WITH_TESTS"] = self.options.tests 172 cmake.definitions["WITH_MAGIC"] = self.options.magic 173 cmake.definitions["WITH_CURL"] = self.options.curl 174 cmake.definitions["WITH_TAGLIB"] = self.options.taglib 175 cmake.definitions["WITH_EXIF"] = self.options.exif 176 cmake.definitions["WITH_MATROSKA"] = self.options.matroska 177 cmake.definitions["WITH_MYSQL"] = self.options.mysql 178 cmake.definitions["WITH_AVCODEC"] = self.options.ffmpeg 179 cmake.definitions["WITH_FFMPEGTHUMBNAILER"] = self.options.ffmpegthumbnailer 180 181 if self.settings.os != "Linux" or tools.cross_building(self): 182 cmake.definitions["WITH_SYSTEMD"] = False 183 184 cmake.configure() 185 cmake.build() 186 187 if tools.get_env("CONAN_RUN_TESTS", True): 188 with tools.run_environment(self): 189 cmake.test(output_on_failure=True) 190