def build(self): if self.settings.os == "Linux" or self.settings.os == "Macos": autotools = AutoToolsBuildEnvironment(self) env_vars = autotools.vars.copy() # required to correctly find static libssl on Linux if self.options.with_openssl and self.settings.os == "Linux": env_vars['OPENSSL_LIBADD'] = '-ldl' # disable rpath build tools.replace_in_file(os.path.join(self._source_subfolder, "configure"), r"-install_name \$rpath/", "-install_name ") # compose configure options configure_args = [] if not self.options.shared: configure_args.append("--disable-shared") configure_args.append("--enable-openssl" if self.options.with_openssl else "--disable-openssl") if self.options.disable_threads: configure_args.append("--disable-thread-support") with tools.environment_append(env_vars): with tools.chdir(self._source_subfolder): # set LD_LIBRARY_PATH with tools.environment_append(RunEnvironment(self).vars): autotools.configure(args=configure_args) autotools.make() elif self.settings.os == "Windows": vcvars = tools.vcvars_command(self.settings) suffix = '' if self.options.with_openssl: suffix = "OPENSSL_DIR=" + self.deps_cpp_info['OpenSSL'].rootpath # add runtime directives to runtime-unaware nmakefile tools.replace_in_file(os.path.join(self._source_subfolder, "Makefile.nmake"), 'LIBFLAGS=/nologo', 'LIBFLAGS=/nologo\n' 'CFLAGS=$(CFLAGS) /%s' % str(self.settings.compiler.runtime)) # do not build tests. static_libs is the only target, no shared libs at all make_command = "nmake %s -f Makefile.nmake static_libs" % suffix with tools.chdir(self._source_subfolder): self.run("%s && %s" % (vcvars, make_command))
class AutomakeConan(ConanFile): name = "automake" url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.gnu.org/software/automake/" description = "Automake is a tool for automatically generating Makefile.in files compliant with the GNU Coding Standards." topics = ("conan", "automake", "configure", "build") license = ("GPL-2.0-or-later", "GPL-3.0-or-later") settings = "os", "arch", "compiler" exports_sources = "patches/*" _autotools = None @property def _source_subfolder(self): return os.path.join(self.source_folder, "source_subfolder") @property def _version_major_minor(self): [major, minor, _] = self.version.split(".", 2) return '{}.{}'.format(major, minor) @property def _settings_build(self): return getattr(self, "settings_build", self.settings) def configure(self): del self.settings.compiler.cppstd del self.settings.compiler.libcxx def requirements(self): self.requires("autoconf/2.71") # automake requires perl-Thread-Queue package def build_requirements(self): if hasattr(self, "settings_build"): self.build_requires("autoconf/2.71") if self._settings_build.os == "Windows" and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def package_id(self): del self.info.settings.arch del self.info.settings.compiler def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) @property def _datarootdir(self): return os.path.join(self.package_folder, "res") @property def _automake_libdir(self): return os.path.join(self._datarootdir, "automake-{}".format(self._version_major_minor)) def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) conf_args = [ "--datarootdir={}".format(tools.unix_path(self._datarootdir)), "--prefix={}".format(tools.unix_path(self.package_folder)), ] self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder) return self._autotools def _patch_files(self): for patch in self.conan_data["patches"][self.version]: tools.patch(**patch) if self.settings.os == "Windows": # tracing using m4 on Windows returns Windows paths => use cygpath to convert to unix paths tools.replace_in_file( os.path.join(self._source_subfolder, "bin", "aclocal.in"), " $map_traced_defs{$arg1} = $file;", " $file = `cygpath -u $file`;\n" " $file =~ s/^\\s+|\\s+$//g;\n" " $map_traced_defs{$arg1} = $file;") def build(self): self._patch_files() autotools = self._configure_autotools() autotools.make() def package(self): self.copy("COPYING*", src=self._source_subfolder, dst="licenses") autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self._datarootdir, "info")) tools.rmdir(os.path.join(self._datarootdir, "man")) tools.rmdir(os.path.join(self._datarootdir, "doc")) if self.settings.os == "Windows": binpath = os.path.join(self.package_folder, "bin") for filename in os.listdir(binpath): fullpath = os.path.join(binpath, filename) if not os.path.isfile(fullpath): continue os.rename(fullpath, fullpath + ".exe") def package_info(self): self.cpp_info.libdirs = [] bin_path = os.path.join(self.package_folder, "bin") self.output.info( "Appending PATH environment variable:: {}".format(bin_path)) self.env_info.PATH.append(bin_path) bin_ext = ".exe" if self.settings.os == "Windows" else "" aclocal = tools.unix_path( os.path.join(self.package_folder, "bin", "aclocal" + bin_ext)) self.output.info( "Appending ACLOCAL environment variable with: {}".format(aclocal)) self.env_info.ACLOCAL.append(aclocal) automake_datadir = tools.unix_path(self._datarootdir) self.output.info( "Setting AUTOMAKE_DATADIR to {}".format(automake_datadir)) self.env_info.AUTOMAKE_DATADIR = automake_datadir automake_libdir = tools.unix_path(self._automake_libdir) self.output.info( "Setting AUTOMAKE_LIBDIR to {}".format(automake_libdir)) self.env_info.AUTOMAKE_LIBDIR = automake_libdir automake_perllibdir = tools.unix_path(self._automake_libdir) self.output.info( "Setting AUTOMAKE_PERLLIBDIR to {}".format(automake_perllibdir)) self.env_info.AUTOMAKE_PERLLIBDIR = automake_perllibdir automake = tools.unix_path( os.path.join(self.package_folder, "bin", "automake" + bin_ext)) self.output.info("Setting AUTOMAKE to {}".format(automake)) self.env_info.AUTOMAKE = automake self.output.info( "Append M4 include directories to AUTOMAKE_CONAN_INCLUDES environment variable" ) self.user_info.compile = os.path.join(self._automake_libdir, "compile") self.user_info.ar_lib = os.path.join(self._automake_libdir, "ar-lib")
class PupnpConan(ConanFile): name = "pupnp" description = ( "The portable Universal Plug and Play (UPnP) SDK " "provides support for building UPnP-compliant control points, " "devices, and bridges on several operating systems.") license = "BSD-3-Clause" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/pupnp/pupnp" topics = ("conan", "upnp", "networking") settings = "os", "compiler", "build_type", "arch" options = { "shared": [True, False], "fPIC": [True, False], "ipv6": [True, False], "reuseaddr": [True, False], "webserver": [True, False], "client": [True, False], "device": [True, False], "largefile": [True, False], "tools": [True, False], "blocking-tcp": [True, False], "debug": [True, False] } default_options = { "shared": False, "fPIC": True, "ipv6": True, "reuseaddr": True, "webserver": True, "client": True, "device": True, "largefile": True, "tools": True, "blocking-tcp": False, "debug": True # Actually enables logging routines... } _autotools = None @property def _source_subfolder(self): return "source_subfolder" def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): del self.settings.compiler.libcxx del self.settings.compiler.cppstd if self.options.shared: del self.options.fPIC def validate(self): if self.settings.compiler == "Visual Studio": # Note, pupnp has build instructions for Visual Studio but they # include VC 6 and require pthreads-w32 library. # Someone who needs it and has possibility to build it could step in. raise ConanInvalidConfiguration( "Visual Studio not supported yet in this recipe") @property def _settings_build(self): return getattr(self, "settings_build", self.settings) def build_requirements(self): self.build_requires("libtool/2.4.6") self.build_requires("pkgconf/1.7.4") if self._settings_build.os == "Windows" and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def _configure_autotools(self): if not self._autotools: args = [ "--enable-static=%s" % ("no" if self.options.shared else "yes"), "--enable-shared=%s" % ("yes" if self.options.shared else "no"), "--disable-samples", ] def enable_disable(opt): what = "enable" if getattr(self.options, opt) else "disable" return "--{}-{}".format(what, opt) args.extend( map( enable_disable, ("ipv6", "reuseaddr", "webserver", "client", "device", "largefile", "tools", "debug"), )) args.append("--%s-blocking_tcp_connections" % ("enable" if getattr( self.options, "blocking-tcp") else "disable")) self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) self._autotools.configure(configure_dir=self._source_subfolder, args=args) return self._autotools def build(self): with tools.chdir(self._source_subfolder): self.run("{} -fiv".format(tools.get_env("AUTORECONF")), win_bash=tools.os_info.is_windows) autotools = self._configure_autotools() autotools.make() def package(self): self.copy("COPYING", dst="licenses", src=self._source_subfolder) autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") def package_info(self): self.cpp_info.names["pkg_config"] = "libupnp" self.cpp_info.libs = ["upnp", "ixml"] self.cpp_info.includedirs.append(os.path.join("include", "upnp")) if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs.extend(["pthread"]) self.cpp_info.cflags.extend(["-pthread"]) self.cpp_info.cxxflags.extend(["-pthread"]) elif self.settings.os == "Windows": self.cpp_info.system_libs.extend(["iphlpapi", "ws2_32"])
def build(self): # Source should be downloaded in the build step since it depends on specific options self._download_source() if self.settings.os == "Windows": return target_tag = self._target_tag host_tag = "x86_64-linux-gnu" # We currently cannot build with multilib and threads=posix. Otherwise we get the gcc compile error: # checking for ld that supports -Wl,--gc-sections... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES. # Makefile:11275: recipe for target 'configure-target-libstdc++-v3' failed build_multilib = False # Instructions see: # https://sourceforge.net/p/mingw-w64/code/HEAD/tree/trunk/mingw-w64-doc/howto-build/mingw-w64-howto-build.txt # and # https://sourceforge.net/p/mingw-w64/code/HEAD/tree/trunk/mingw-w64-doc/howto-build/mingw-w64-howto-build-adv.txt # also good to see specific commands: # https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/+/lollipop-dev/build-mingw64-toolchain.sh # add binutils to path. Required for gcc build env = {"PATH": os.environ["PATH"] + ":" + os.path.join(self.package_folder, "bin")} with tools.environment_append(env): self.output.info("Building gmp ...") os.mkdir(os.path.join(self.build_folder, "gmp")) with tools.chdir(os.path.join(self.build_folder, "gmp")): autotools = AutoToolsBuildEnvironment(self) conf_args = [ "--enable-silent-rules", "--disable-shared" ] autotools.configure(configure_dir=os.path.join(self.build_folder, "sources", "gmp"), args=conf_args, target=False, host=False, build=False) autotools.make() autotools.install() self.output.info("Building mpfr ...") os.mkdir(os.path.join(self.build_folder, "mpfr")) with tools.chdir(os.path.join(self.build_folder, "mpfr")): autotools = AutoToolsBuildEnvironment(self) conf_args = [ "--enable-silent-rules", "--disable-shared", "--with-gmp={}".format(self.package_folder) ] autotools.configure(configure_dir=os.path.join(self.build_folder, "sources", "mpfr"), args=conf_args, target=False, host=False, build=False) autotools.make() autotools.install() self.output.info("Building mpc ...") os.mkdir(os.path.join(self.build_folder, "mpc")) with tools.chdir(os.path.join(self.build_folder, "mpc")): autotools = AutoToolsBuildEnvironment(self) conf_args = [ "--enable-silent-rules", "--disable-shared", "--with-gmp={}".format(self.package_folder), "--with-mpfr={}".format(self.package_folder) ] autotools.configure(configure_dir=os.path.join(self.build_folder, "sources", "mpc"), args=conf_args, target=False, host=False, build=False) autotools.make() autotools.install() with_gmp_mpfc_mpc = [ "--with-gmp={}".format(self.package_folder), "--with-mpfr={}".format(self.package_folder), "--with-mpc={}".format(self.package_folder) ] # with_gmp_mpfc_mpc = [ # "--with-gmp=system", # "--with-gmp-prefix={}".format(self.deps_cpp_info["gmp"].rootpath.replace("\\", "/")), # "--with-mpfr=system", # "--with-mpfr-prefix={}".format(self.deps_cpp_info["mpfr"].rootpath.replace("\\", "/")), # "--with-mpc=system", # "--with-mpc-prefix={}".format(self.deps_cpp_info["mpc"].rootpath.replace("\\", "/")) # ] self.output.info("Building binutils ...") os.mkdir(os.path.join(self.build_folder, "binutils")) with tools.chdir(os.path.join(self.build_folder, "binutils")): autotools = AutoToolsBuildEnvironment(self) conf_args = [ "--enable-silent-rules", "--with-sysroot={}".format(self.package_folder), "--disable-nls", "--disable-shared" ] if build_multilib: conf_args.append("--enable-targets=x86_64-w64-mingw32,i686-w64-mingw32") conf_args.extend(with_gmp_mpfc_mpc) autotools.configure(configure_dir=os.path.join(self.build_folder, "sources", "binutils"), args=conf_args, target=target_tag, host=False, build=False) autotools.make() autotools.install() self.output.info("Building mingw-w64-tools ...") os.mkdir(os.path.join(self.build_folder, "mingw-w64-tools")) with tools.chdir(os.path.join(self.build_folder, "mingw-w64-tools")): autotools = AutoToolsBuildEnvironment(self) conf_args = [] autotools.configure(configure_dir=os.path.join(self.build_folder, "sources", "mingw-w64", "mingw-w64-tools", "widl"), args=conf_args, target=target_tag, host=False, build=False) autotools.make() autotools.install() self.output.info("Building mingw-w64-headers ...") os.mkdir(os.path.join(self.build_folder, "mingw-w64-headers")) with tools.chdir(os.path.join(self.build_folder, "mingw-w64-headers")): autotools = AutoToolsBuildEnvironment(self) conf_args = [ "--enable-silent-rules", "--with-widl={}".format(os.path.join(self.package_folder, "bin")), "--enable-sdk=all", "--prefix={}".format(os.path.join(self.package_folder, target_tag)) ] autotools.configure(configure_dir=os.path.join(self.build_folder, "sources", "mingw-w64", "mingw-w64-headers"), args=conf_args, target=False, host=target_tag, build=host_tag) autotools.make() autotools.install() # Step 3) GCC requires the x86_64-w64-mingw32 directory be mirrored as a # directory 'mingw' in the same root. So, if using configure default # /usr/local, type: # ln -s /usr/local/x86_64-w64-mingw32 /usr/local/mingw # or, for sysroot, type: # ln -s /mypath/x86_64-w64-mingw32 /mypath/mingw self.run("ln -s {} {}".format(os.path.join(self.package_folder, target_tag), os.path.join(self.package_folder, 'mingw'))) # Step 5) Symlink x86_64-w64-mingw32/lib directory as x86_64-w64-mingw32/lib64: # ln -s /usr/local/x86_64-w64-mingw32/lib /usr/local/x86_64-w64-mingw32/lib64 # or, for sysroot: # ln -s /mypath/x86_64-w64-mingw32/lib /mypath/x86_64-w64-mingw32/lib64 self.run("ln -s {} {}".format(os.path.join(self.package_folder, target_tag, 'lib'), os.path.join(self.package_folder, target_tag, 'lib64'))) self.output.info("Building core gcc ...") os.mkdir(os.path.join(self.build_folder, "gcc")) with tools.chdir(os.path.join(self.build_folder, "gcc")): autotools_gcc = AutoToolsBuildEnvironment(self) conf_args = [ "--enable-silent-rules", "--enable-languages=c,c++", "--with-sysroot={}".format(self.package_folder), "--disable-shared" ] if build_multilib: conf_args.append("--enable-targets=all") conf_args.append("--enable-multilib") else: conf_args.append("--disable-multilib") conf_args.extend(with_gmp_mpfc_mpc) if self.options.exception == "sjlj": conf_args.append("--enable-sjlj-exceptions") if self.options.threads == "posix": # Some specific options which need to be set for posix thread. Otherwise it fails compiling. conf_args.extend([ "--enable-silent-rules", "--enable-threads=posix", # Not 100% sure why, but the following options are required, otherwise # gcc fails to build with posix threads ]) autotools_gcc.configure(configure_dir=os.path.join(self.build_folder, "sources", "gcc"), args=conf_args, target=target_tag, host=False, build=False) autotools_gcc.make(target="all-gcc") autotools_gcc.make(target="install-gcc") env_compiler = dict(env) # The CC and CXX compiler must be set to the mingw compiler. Conan already sets CC and CXX, therefore we need to overwrite it. # If the wrong compiler is used for mingw-w64-crt, then you will get the error # configure: Please check if the mingw-w64 header set and the build/host option are set properly. env_compiler["CC"] = target_tag + "-gcc" env_compiler["CXX"] = target_tag + "-g++" with tools.environment_append(env_compiler): self.output.info("Building mingw-w64-crt ...") os.mkdir(os.path.join(self.build_folder, "mingw-w64-crt")) with tools.chdir(os.path.join(self.build_folder, "mingw-w64-crt")): autotools = AutoToolsBuildEnvironment(self) conf_args = [ "--enable-silent-rules", "--prefix={}".format(os.path.join(self.package_folder, target_tag)), "--with-sysroot={}".format(self.package_folder) ] if build_multilib: conf_args.append("--enable-lib32") autotools.configure(configure_dir=os.path.join(self.build_folder, "sources", "mingw-w64", "mingw-w64-crt"), args=conf_args, target=False, host=target_tag, build=False, use_default_install_dirs=False) autotools.make() autotools.install() if self.options.threads == "posix": self.output.info("Building mingw-w64-libraries-winpthreads ...") os.mkdir(os.path.join(self.build_folder, "mingw-w64-libraries-winpthreads")) with tools.chdir(os.path.join(self.build_folder, "mingw-w64-libraries-winpthreads")): autotools = AutoToolsBuildEnvironment(self) conf_args = [ "--enable-silent-rules", "--disable-shared", "--prefix={}".format(os.path.join(self.package_folder, target_tag)) ] autotools.configure(configure_dir=os.path.join(self.build_folder, "sources", "mingw-w64", "mingw-w64-libraries", "winpthreads"), args=conf_args, target=False, host=target_tag, build=False) autotools.make() autotools.install() self.output.info("Building libgcc ...") with tools.chdir(os.path.join(self.build_folder, "gcc")): autotools_gcc.make() autotools_gcc.install() self.output.info("Building done!")
class ZimgConan(ConanFile): name = "zimg" description = "Scaling, colorspace conversion, and dithering library" topics = ("conan", "zimg", "image", "manipulation") homepage = "https://github.com/sekrit-twc/zimg" url = "https://github.com/conan-io/conan-center-index" license = "WTFPL" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], } default_options = { "shared": False, "fPIC": True, } exports_sources = "patches/**" _autotools = None @property def _source_subfolder(self): return "source_subfolder" def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: del self.options.fPIC if self.settings.build_type not in ("Release", "Debug"): raise ConanInvalidConfiguration( "zimg does not support the build type '{}'.".format( self.settings.build_type)) if self.settings.compiler == "Visual Studio": if self.settings.compiler.version < tools.Version(15): raise ConanInvalidConfiguration( "zimg requires at least Visual Studio 15 2017") def build_requirements(self): if self.settings.compiler != "Visual Studio": self.build_requires("libtool/2.4.6") if tools.os_info.is_windows and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/20200517") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("zimg-release-{}".format(self.version), self._source_subfolder) def _configure_autools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) conf_args = [] if self.options.shared: conf_args.extend(["--enable-shared", "--disable-static"]) else: conf_args.extend(["--disable-shared", "--enable-static"]) self._autotools.configure(configure_dir=self._source_subfolder, args=conf_args) return self._autotools def _build_autotools(self): with tools.chdir(self._source_subfolder): self.run("autoreconf -fiv", win_bash=tools.os_info.is_windows) autotools = self._configure_autools() autotools.make() _sln_platforms = { "x86": "Win32", "x86_64": "x64", "armv6": "ARM", "armv7": "ARM", "armv7hf": "ARM", "armv7s": "ARM", "armv7k": "ARM", "armv8_32": "ARM", "armv8": "ARM64", "armv8.3": "ARM64", } def _build_msvc(self): msbuild = MSBuild(self) msbuild.build(os.path.join(self._source_subfolder, "_msvc", "zimg.sln"), targets=["dll" if self.options.shared else "zimg"], platforms=self._sln_platforms) def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) if self.settings.compiler == "Visual Studio": self._build_msvc() else: self._build_autotools() def _package_autotools(self): autotools = self._configure_autools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.rmdir(os.path.join(self.package_folder, "share")) with tools.chdir(os.path.join(self.package_folder, "lib")): for filename in glob.glob("*.la"): os.unlink(filename) def _package_msvc(self): self.copy("zimg.h", src=os.path.join(self._source_subfolder, "src", "zimg", "api"), dst="include") self.copy("zimg++.hpp", src=os.path.join(self._source_subfolder, "src", "zimg", "api"), dst="include") sln_dir = os.path.join(self._source_subfolder, "_msvc", self._sln_platforms[str(self.settings.arch)], str(self.settings.build_type)) if self.options.shared: self.copy("z_imp.lib", src=sln_dir, dst="lib") self.copy("z.dll", src=sln_dir, dst="bin") os.rename(os.path.join(self.package_folder, "lib", "z_imp.lib"), os.path.join(self.package_folder, "lib", "zimg.lib")) else: self.copy("z.lib", src=sln_dir, dst="lib") os.rename(os.path.join(self.package_folder, "lib", "z.lib"), os.path.join(self.package_folder, "lib", "zimg.lib")) def package(self): self.copy("COPYING", src=self._source_subfolder, dst="licenses") if self.settings.compiler == "Visual Studio": self._package_msvc() else: self._package_autotools() def package_info(self): self.cpp_info.libs = ["zimg"]
class FFMpegConan(ConanFile): name = "ffmpeg" url = "https://github.com/conan-io/conan-center-index" description = "A complete, cross-platform solution to record, convert and stream audio and video" # https://github.com/FFmpeg/FFmpeg/blob/master/LICENSE.md license = ("LGPL-2.1-or-later", "GPL-2.0-or-later") homepage = "https://ffmpeg.org" topics = ("ffmpeg", "multimedia", "audio", "video", "encoder", "decoder", "encoding", "decoding", "transcoding", "multiplexer", "demultiplexer", "streaming") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "avdevice": [True, False], "avcodec": [True, False], "avformat": [True, False], "swresample": [True, False], "swscale": [True, False], "postproc": [True, False], "avfilter": [True, False], "with_zlib": [True, False], "with_bzip2": [True, False], "with_lzma": [True, False], "with_libiconv": [True, False], "with_freetype": [True, False], "with_openjpeg": [True, False], "with_openh264": [True, False], "with_opus": [True, False], "with_vorbis": [True, False], "with_zeromq": [True, False], "with_sdl": [True, False], "with_libx264": [True, False], "with_libx265": [True, False], "with_libvpx": [True, False], "with_libmp3lame": [True, False], "with_libfdk_aac": [True, False], "with_libwebp": [True, False], "with_ssl": [False, "openssl", "securetransport"], "with_libalsa": [True, False], "with_pulse": [True, False], "with_vaapi": [True, False], "with_vdpau": [True, False], "with_vulkan": [True, False], "with_xcb": [True, False], "with_appkit": [True, False], "with_avfoundation": [True, False], "with_coreimage": [True, False], "with_audiotoolbox": [True, False], "with_videotoolbox": [True, False], "with_programs": [True, False], "disable_everything": [True, False], "disable_all_encoders": [True, False], "disable_encoders": "ANY", "enable_encoders": "ANY", "disable_all_decoders": [True, False], "disable_decoders": "ANY", "enable_decoders": "ANY", "disable_all_hardware_accelerators": [True, False], "disable_hardware_accelerators": "ANY", "enable_hardware_accelerators": "ANY", "disable_all_muxers": [True, False], "disable_muxers": "ANY", "enable_muxers": "ANY", "disable_all_demuxers": [True, False], "disable_demuxers": "ANY", "enable_demuxers": "ANY", "disable_all_parsers": [True, False], "disable_parsers": "ANY", "enable_parsers": "ANY", "disable_all_bitstream_filters": [True, False], "disable_bitstream_filters": "ANY", "enable_bitstream_filters": "ANY", "disable_all_protocols": [True, False], "disable_protocols": "ANY", "enable_protocols": "ANY", "disable_all_devices": [True, False], "disable_all_input_devices": [True, False], "disable_input_devices": "ANY", "enable_input_devices": "ANY", "disable_all_output_devices": [True, False], "disable_output_devices": "ANY", "enable_output_devices": "ANY", "disable_all_filters": [True, False], "disable_filters": "ANY", "enable_filters": "ANY", } default_options = { "shared": False, "fPIC": True, "avdevice": True, "avcodec": True, "avformat": True, "swresample": True, "swscale": True, "postproc": True, "avfilter": True, "with_zlib": True, "with_bzip2": True, "with_lzma": True, "with_libiconv": True, "with_freetype": True, "with_openjpeg": True, "with_openh264": True, "with_opus": True, "with_vorbis": True, "with_zeromq": False, "with_sdl": False, "with_libx264": True, "with_libx265": True, "with_libvpx": True, "with_libmp3lame": True, "with_libfdk_aac": True, "with_libwebp": True, "with_ssl": "openssl", "with_libalsa": True, "with_pulse": True, "with_vaapi": True, "with_vdpau": True, "with_vulkan": True, "with_xcb": True, "with_appkit": True, "with_avfoundation": True, "with_coreimage": True, "with_audiotoolbox": True, "with_videotoolbox": True, "with_programs": True, "disable_everything": False, "disable_all_encoders": False, "disable_encoders": None, "enable_encoders": None, "disable_all_decoders": False, "disable_decoders": None, "enable_decoders": None, "disable_all_hardware_accelerators": False, "disable_hardware_accelerators": None, "enable_hardware_accelerators": None, "disable_all_muxers": False, "disable_muxers": None, "enable_muxers": None, "disable_all_demuxers": False, "disable_demuxers": None, "enable_demuxers": None, "disable_all_parsers": False, "disable_parsers": None, "enable_parsers": None, "disable_all_bitstream_filters": False, "disable_bitstream_filters": None, "enable_bitstream_filters": None, "disable_all_protocols": False, "disable_protocols": None, "enable_protocols": None, "disable_all_devices": False, "disable_all_input_devices": False, "disable_input_devices": None, "enable_input_devices": None, "disable_all_output_devices": False, "disable_output_devices": None, "enable_output_devices": None, "disable_all_filters": False, "disable_filters": None, "enable_filters": None, } generators = "pkg_config" _autotools = None @property def _source_subfolder(self): return "source_subfolder" @property def _is_msvc(self): return str(self.settings.compiler) in ["Visual Studio", "msvc"] @property def _settings_build(self): return getattr(self, "settings_build", self.settings) @property def _dependencies(self): return { "avformat": ["avcodec"], "avdevice": ["avcodec", "avformat"], "avfilter": ["avformat"], "with_bzip2": ["avformat"], "with_ssl": ["avformat"], "with_zlib": ["avcodec"], "with_lzma": ["avcodec"], "with_libiconv": ["avcodec"], "with_openjpeg": ["avcodec"], "with_openh264": ["avcodec"], "with_vorbis": ["avcodec"], "with_opus": ["avcodec"], "with_libx264": ["avcodec"], "with_libx265": ["avcodec"], "with_libvpx": ["avcodec"], "with_libmp3lame": ["avcodec"], "with_libfdk_aac": ["avcodec"], "with_libwebp": ["avcodec"], "with_freetype": ["avfilter"], "with_zeromq": ["avfilter", "avformat"], "with_libalsa": ["avdevice"], "with_xcb": ["avdevice"], "with_pulse": ["avdevice"], "with_sdl": ["with_programs"], } def config_options(self): if self.settings.os == "Windows": del self.options.fPIC if not self.settings.os in ["Linux", "FreeBSD"]: del self.options.with_vaapi del self.options.with_vdpau del self.options.with_vulkan del self.options.with_xcb del self.options.with_libalsa del self.options.with_pulse if self.settings.os != "Macos": del self.options.with_appkit if self.settings.os not in ["Macos", "iOS", "tvOS"]: del self.options.with_coreimage del self.options.with_audiotoolbox del self.options.with_videotoolbox if not tools.is_apple_os(self.settings.os): del self.options.with_avfoundation if not self._version_supports_vulkan(): del self.options.with_vulkan def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd def requirements(self): if self.options.with_zlib: self.requires("zlib/1.2.12") if self.options.with_bzip2: self.requires("bzip2/1.0.8") if self.options.with_lzma: self.requires("xz_utils/5.2.5") if self.options.with_libiconv: self.requires("libiconv/1.16") if self.options.with_freetype: self.requires("freetype/2.11.1") if self.options.with_openjpeg: self.requires("openjpeg/2.4.0") if self.options.with_openh264: self.requires("openh264/2.1.1") if self.options.with_vorbis: self.requires("vorbis/1.3.7") if self.options.with_opus: self.requires("opus/1.3.1") if self.options.with_zeromq: self.requires("zeromq/4.3.4") if self.options.with_sdl: self.requires("sdl/2.0.20") if self.options.with_libx264: self.requires("libx264/20191217") if self.options.with_libx265: self.requires("libx265/3.4") if self.options.with_libvpx: self.requires("libvpx/1.11.0") if self.options.with_libmp3lame: self.requires("libmp3lame/3.100") if self.options.with_libfdk_aac: self.requires("libfdk_aac/2.0.2") if self.options.with_libwebp: self.requires("libwebp/1.2.2") if self.options.with_ssl == "openssl": self.requires("openssl/1.1.1o") if self.options.get_safe("with_libalsa"): self.requires("libalsa/1.2.5.1") if self.options.get_safe("with_xcb") or self.options.get_safe( "with_vaapi"): self.requires("xorg/system") if self.options.get_safe("with_pulse"): self.requires("pulseaudio/14.2") if self.options.get_safe("with_vaapi"): self.requires("vaapi/system") if self.options.get_safe("with_vdpau"): self.requires("vdpau/system") if self._version_supports_vulkan() and self.options.get_safe( "with_vulkan"): self.requires("vulkan-loader/1.3.211.0") def validate(self): if self.options.with_ssl == "securetransport" and not tools.is_apple_os( self.settings.os): raise ConanInvalidConfiguration( "securetransport is only available on Apple") for dependency, features in self._dependencies.items(): if not self.options.get_safe(dependency): continue used = False for feature in features: used = used or self.options.get_safe(feature) if not used: raise ConanInvalidConfiguration( "FFmpeg '{}' option requires '{}' option to be enabled". format(dependency, "' or '".join(features))) def build_requirements(self): if self.settings.arch in ("x86", "x86_64"): self.build_requires("yasm/1.3.0") self.build_requires("pkgconf/1.7.4") if self._settings_build.os == "Windows" and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) @property def _target_arch(self): target_arch, _, _ = tools.get_gnu_triplet( "Macos" if tools.is_apple_os(self.settings.os) else str(self.settings.os), str(self.settings.arch), str(self.settings.compiler) if self.settings.os == "Windows" else None, ).split("-") return target_arch @property def _target_os(self): if self._is_msvc: return "win32" else: _, _, target_os = tools.get_gnu_triplet( "Macos" if tools.is_apple_os(self.settings.os) else str( self.settings.os), str(self.settings.arch), str(self.settings.compiler) if self.settings.os == "Windows" else None, ).split("-") return target_os def _patch_sources(self): if self._is_msvc and self.options.with_libx264 and not self.options[ "libx264"].shared: # suppress MSVC linker warnings: https://trac.ffmpeg.org/ticket/7396 # warning LNK4049: locally defined symbol x264_levels imported # warning LNK4049: locally defined symbol x264_bit_depth imported tools.replace_in_file( os.path.join(self._source_subfolder, "libavcodec", "libx264.c"), "#define X264_API_IMPORTS 1", "") if self.options.with_ssl == "openssl": # https://trac.ffmpeg.org/ticket/5675 openssl_libraries = " ".join( ["-l%s" % lib for lib in self.deps_cpp_info["openssl"].libs]) tools.replace_in_file( os.path.join(self._source_subfolder, "configure"), "check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||", "check_lib openssl openssl/ssl.h OPENSSL_init_ssl %s || " % openssl_libraries) @contextlib.contextmanager def _build_context(self): if self._is_msvc: with tools.vcvars(self): yield else: yield def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) self._autotools.libs = [] def opt_enable_disable(what, v): return "--{}-{}".format("enable" if v else "disable", what) def opt_append_disable_if_set(args, what, v): if v: args.append("--disable-{}".format(what)) args = [ "--pkg-config-flags=--static", "--disable-doc", opt_enable_disable("cross-compile", tools.cross_building(self)), # Libraries opt_enable_disable("shared", self.options.shared), opt_enable_disable("static", not self.options.shared), opt_enable_disable("pic", self.options.get_safe("fPIC", True)), # Components opt_enable_disable("avdevice", self.options.avdevice), opt_enable_disable("avcodec", self.options.avcodec), opt_enable_disable("avformat", self.options.avformat), opt_enable_disable("swresample", self.options.swresample), opt_enable_disable("swscale", self.options.swscale), opt_enable_disable("postproc", self.options.postproc), opt_enable_disable("avfilter", self.options.avfilter), # Dependencies opt_enable_disable("bzlib", self.options.with_bzip2), opt_enable_disable("zlib", self.options.with_zlib), opt_enable_disable("lzma", self.options.with_lzma), opt_enable_disable("iconv", self.options.with_libiconv), opt_enable_disable("libopenjpeg", self.options.with_openjpeg), opt_enable_disable("libopenh264", self.options.with_openh264), opt_enable_disable("libvorbis", self.options.with_vorbis), opt_enable_disable("libopus", self.options.with_opus), opt_enable_disable("libzmq", self.options.with_zeromq), opt_enable_disable("sdl2", self.options.with_sdl), opt_enable_disable("libx264", self.options.with_libx264), opt_enable_disable("libx265", self.options.with_libx265), opt_enable_disable("libvpx", self.options.with_libvpx), opt_enable_disable("libmp3lame", self.options.with_libmp3lame), opt_enable_disable("libfdk-aac", self.options.with_libfdk_aac), opt_enable_disable("libwebp", self.options.with_libwebp), opt_enable_disable("openssl", self.options.with_ssl == "openssl"), opt_enable_disable("alsa", self.options.get_safe("with_libalsa")), opt_enable_disable("libpulse", self.options.get_safe("with_pulse")), opt_enable_disable("vaapi", self.options.get_safe("with_vaapi")), opt_enable_disable("vdpau", self.options.get_safe("with_vdpau")), opt_enable_disable("libxcb", self.options.get_safe("with_xcb")), opt_enable_disable("libxcb-shm", self.options.get_safe("with_xcb")), opt_enable_disable("libxcb-shape", self.options.get_safe("with_xcb")), opt_enable_disable("libxcb-xfixes", self.options.get_safe("with_xcb")), opt_enable_disable("appkit", self.options.get_safe("with_appkit")), opt_enable_disable("avfoundation", self.options.get_safe("with_avfoundation")), opt_enable_disable("coreimage", self.options.get_safe("with_coreimage")), opt_enable_disable("audiotoolbox", self.options.get_safe("with_audiotoolbox")), opt_enable_disable("videotoolbox", self.options.get_safe("with_videotoolbox")), opt_enable_disable("securetransport", self.options.with_ssl == "securetransport"), "--disable-cuda", # FIXME: CUDA support "--disable-cuvid", # FIXME: CUVID support # Licenses opt_enable_disable( "nonfree", self.options.with_libfdk_aac or (self.options.with_ssl and (self.options.with_libx264 or self.options.with_libx265 or self.options.postproc))), opt_enable_disable( "gpl", self.options.with_libx264 or self.options.with_libx265 or self.options.postproc) ] # Individual Component Options opt_append_disable_if_set(args, "everything", self.options.disable_everything) opt_append_disable_if_set(args, "encoders", self.options.disable_all_encoders) opt_append_disable_if_set(args, "decoders", self.options.disable_all_decoders) opt_append_disable_if_set( args, "hwaccels", self.options.disable_all_hardware_accelerators) opt_append_disable_if_set(args, "muxers", self.options.disable_all_muxers) opt_append_disable_if_set(args, "demuxers", self.options.disable_all_demuxers) opt_append_disable_if_set(args, "parsers", self.options.disable_all_parsers) opt_append_disable_if_set(args, "bsfs", self.options.disable_all_bitstream_filters) opt_append_disable_if_set(args, "protocols", self.options.disable_all_protocols) opt_append_disable_if_set(args, "devices", self.options.disable_all_devices) opt_append_disable_if_set(args, "indevs", self.options.disable_all_input_devices) opt_append_disable_if_set(args, "outdevs", self.options.disable_all_output_devices) opt_append_disable_if_set(args, "filters", self.options.disable_all_filters) args.extend( self._split_and_format_options_string( "enable-encoder", self.options.enable_encoders)) args.extend( self._split_and_format_options_string( "disable-encoder", self.options.disable_encoders)) args.extend( self._split_and_format_options_string( "enable-decoder", self.options.enable_decoders)) args.extend( self._split_and_format_options_string( "disable-decoder", self.options.disable_decoders)) args.extend( self._split_and_format_options_string( "enable-hwaccel", self.options.enable_hardware_accelerators)) args.extend( self._split_and_format_options_string( "disable-hwaccel", self.options.disable_hardware_accelerators)) args.extend( self._split_and_format_options_string("enable-muxer", self.options.enable_muxers)) args.extend( self._split_and_format_options_string("disable-muxer", self.options.disable_muxers)) args.extend( self._split_and_format_options_string( "enable-demuxer", self.options.enable_demuxers)) args.extend( self._split_and_format_options_string( "disable-demuxer", self.options.disable_demuxers)) args.extend( self._split_and_format_options_string("enable-parser", self.options.enable_parsers)) args.extend( self._split_and_format_options_string( "disable-parser", self.options.disable_parsers)) args.extend( self._split_and_format_options_string( "enable-bsf", self.options.enable_bitstream_filters)) args.extend( self._split_and_format_options_string( "disable-bsf", self.options.disable_bitstream_filters)) args.extend( self._split_and_format_options_string( "enable-protocol", self.options.enable_protocols)) args.extend( self._split_and_format_options_string( "disable-protocol", self.options.disable_protocols)) args.extend( self._split_and_format_options_string( "enable-indev", self.options.enable_input_devices)) args.extend( self._split_and_format_options_string( "disable-indev", self.options.disable_input_devices)) args.extend( self._split_and_format_options_string( "enable-outdev", self.options.enable_output_devices)) args.extend( self._split_and_format_options_string( "disable-outdev", self.options.disable_output_devices)) args.extend( self._split_and_format_options_string("enable-filter", self.options.enable_filters)) args.extend( self._split_and_format_options_string( "disable-filter", self.options.disable_filters)) if self._version_supports_vulkan(): args.append( opt_enable_disable("vulkan", self.options.get_safe("with_vulkan"))) if tools.is_apple_os(self.settings.os): # relocatable shared libs args.append("--install-name-dir=@rpath") args.append("--arch={}".format(self._target_arch)) if self.settings.build_type == "Debug": args.extend([ "--disable-optimizations", "--disable-mmx", "--disable-stripping", "--enable-debug", ]) if not self.options.with_programs: args.append("--disable-programs") # since ffmpeg"s build system ignores CC and CXX if tools.get_env("AS"): args.append("--as={}".format(tools.get_env("AS"))) if tools.get_env("CC"): args.append("--cc={}".format(tools.get_env("CC"))) if tools.get_env("CXX"): args.append("--cxx={}".format(tools.get_env("CXX"))) extra_cflags = [] extra_ldflags = [] if tools.is_apple_os(self.settings.os) and self.settings.os.version: extra_cflags.append( tools.apple_deployment_target_flag(self.settings.os, self.settings.os.version)) extra_ldflags.append( tools.apple_deployment_target_flag(self.settings.os, self.settings.os.version)) if self._is_msvc: args.append("--pkg-config={}".format(tools.get_env("PKG_CONFIG"))) args.append("--toolchain=msvc") if self.settings.compiler == "Visual Studio" and tools.Version( self.settings.compiler.version) <= "12": # Visual Studio 2013 (and earlier) doesn't support "inline" keyword for C (only for C++) self._autotools.defines.append("inline=__inline") if tools.cross_building(self): if self._target_os == "emscripten": args.append("--target-os=none") else: args.append("--target-os={}".format(self._target_os)) if tools.is_apple_os(self.settings.os): xcrun = tools.XCRun(self.settings) apple_arch = tools.to_apple_arch(str(self.settings.arch)) extra_cflags.extend([ "-arch {}".format(apple_arch), "-isysroot {}".format(xcrun.sdk_path) ]) extra_ldflags.extend([ "-arch {}".format(apple_arch), "-isysroot {}".format(xcrun.sdk_path) ]) args.append("--extra-cflags={}".format(" ".join(extra_cflags))) args.append("--extra-ldflags={}".format(" ".join(extra_ldflags))) self._autotools.configure(args=args, configure_dir=self._source_subfolder, build=False, host=False, target=False) return self._autotools def _split_and_format_options_string(self, flag_name, options_list): if not options_list: return [] def _format_options_list_item(flag_name, options_item): return "--{}={}".format(flag_name, options_item) def _split_options_string(options_string): return list( filter(None, "".join(options_string.split()).split(","))) options_string = str(options_list) return [ _format_options_list_item(flag_name, item) for item in _split_options_string(options_string) ] def build(self): self._patch_sources() tools.replace_in_file( os.path.join(self._source_subfolder, "configure"), "echo libx264.lib", "echo x264.lib") if self.options.with_libx264: shutil.copy("x264.pc", "libx264.pc") with self._build_context(): autotools = self._configure_autotools() autotools.make() def package(self): self.copy("LICENSE.md", dst="licenses", src=self._source_subfolder) with self._build_context(): autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.rmdir(os.path.join(self.package_folder, "share")) if self._is_msvc: if self.options.shared: # ffmpeg created `.lib` files in the `/bin` folder for fn in os.listdir(os.path.join(self.package_folder, "bin")): if fn.endswith(".lib"): rename(self, os.path.join(self.package_folder, "bin", fn), os.path.join(self.package_folder, "lib", fn)) tools.remove_files_by_mask( os.path.join(self.package_folder, "lib"), "*.def") else: # ffmpeg produces `.a` files that are actually `.lib` files with tools.chdir(os.path.join(self.package_folder, "lib")): for lib in glob.glob("*.a"): rename(self, lib, lib[3:-2] + ".lib") def _read_component_version(self, component_name): version_file_name = os.path.join(self.package_folder, "include", "lib%s" % component_name, "version.h") version_file = open(version_file_name, "r") pattern = "define LIB%s_VERSION_(MAJOR|MINOR|MICRO)[ \t]+(\\d+)" % ( component_name.upper()) version = dict() for line in version_file: match = re.search(pattern, line) if match: version[match[1]] = match[2] if "MAJOR" in version and "MINOR" in version and "MICRO" in version: return f"{version['MAJOR']}.{version['MINOR']}.{version['MICRO']}" return None def _set_component_version(self, component_name): version = self._read_component_version(component_name) if version is not None: self.cpp_info.components[component_name].version = version else: self.output.warn("cannot determine version of " "lib%s packaged with ffmpeg!" % component_name) def package_info(self): if self.options.with_programs: if self.options.with_sdl: self.cpp_info.components["programs"].requires = [ "sdl::libsdl2" ] if self.options.avdevice: self.cpp_info.components["avdevice"].set_property( "pkg_config_name", "libavdevice") self.cpp_info.components["avdevice"].libs = ["avdevice"] self.cpp_info.components["avdevice"].requires = ["avutil"] if self.options.avfilter: self.cpp_info.components["avdevice"].requires.append( "avfilter") if self.options.swscale: self.cpp_info.components["avdevice"].requires.append("swscale") if self.options.avformat: self.cpp_info.components["avdevice"].requires.append( "avformat") if self.options.avcodec: self.cpp_info.components["avdevice"].requires.append("avcodec") if self.options.swresample: self.cpp_info.components["avdevice"].requires.append( "swresample") if self.options.postproc: self.cpp_info.components["avdevice"].requires.append( "postproc") self._set_component_version("avdevice") if self.options.avfilter: self.cpp_info.components["avfilter"].set_property( "pkg_config_name", "libavfilter") self.cpp_info.components["avfilter"].libs = ["avfilter"] self.cpp_info.components["avfilter"].requires = ["avutil"] if self.options.swscale: self.cpp_info.components["avfilter"].requires.append("swscale") if self.options.avformat: self.cpp_info.components["avfilter"].requires.append( "avformat") if self.options.avcodec: self.cpp_info.components["avfilter"].requires.append("avcodec") if self.options.swresample: self.cpp_info.components["avfilter"].requires.append( "swresample") if self.options.postproc: self.cpp_info.components["avfilter"].requires.append( "postproc") self._set_component_version("avfilter") if self.options.avformat: self.cpp_info.components["avformat"].set_property( "pkg_config_name", "libavformat") self.cpp_info.components["avformat"].libs = ["avformat"] self.cpp_info.components["avformat"].requires = ["avutil"] if self.options.avcodec: self.cpp_info.components["avformat"].requires.append("avcodec") if self.options.swresample: self.cpp_info.components["avformat"].requires.append( "swresample") self._set_component_version("avformat") if self.options.avcodec: self.cpp_info.components["avcodec"].set_property( "pkg_config_name", "libavcodec") self.cpp_info.components["avcodec"].libs = ["avcodec"] self.cpp_info.components["avcodec"].requires = ["avutil"] if self.options.swresample: self.cpp_info.components["avcodec"].requires.append( "swresample") self._set_component_version("avcodec") if self.options.swscale: self.cpp_info.components["swscale"].set_property( "pkg_config_name", "libswscale") self.cpp_info.components["swscale"].libs = ["swscale"] self.cpp_info.components["swscale"].requires = ["avutil"] self._set_component_version("swscale") if self.options.swresample: self.cpp_info.components["swresample"].set_property( "pkg_config_name", "libswresample") self.cpp_info.components["swresample"].libs = ["swresample"] self.cpp_info.components["swresample"].requires = ["avutil"] self._set_component_version("swresample") if self.options.postproc: self.cpp_info.components["postproc"].set_property( "pkg_config_name", "libpostproc") self.cpp_info.components["postproc"].libs = ["postproc"] self.cpp_info.components["postproc"].requires = ["avutil"] self._set_component_version("postproc") self.cpp_info.components["avutil"].set_property( "pkg_config_name", "libavutil") self.cpp_info.components["avutil"].libs = ["avutil"] self._set_component_version("avutil") if self.settings.os in ("FreeBSD", "Linux"): self.cpp_info.components["avutil"].system_libs = [ "pthread", "m", "dl" ] if self.options.swresample: self.cpp_info.components["swresample"].system_libs = ["m"] if self.options.swscale: self.cpp_info.components["swscale"].system_libs = ["m"] if self.options.postproc: self.cpp_info.components["postproc"].system_libs = ["m"] if self.options.get_safe("fPIC"): if self.settings.compiler in ("gcc", "clang"): # https://trac.ffmpeg.org/ticket/1713 # https://ffmpeg.org/platform.html#Advanced-linking-configuration # https://ffmpeg.org/pipermail/libav-user/2014-December/007719.html self.cpp_info.components["avcodec"].exelinkflags.append( "-Wl,-Bsymbolic") self.cpp_info.components["avcodec"].sharedlinkflags.append( "-Wl,-Bsymbolic") if self.options.avformat: self.cpp_info.components["avformat"].system_libs = ["m"] if self.options.avfilter: self.cpp_info.components["avfilter"].system_libs = [ "m", "pthread" ] if self.options.avdevice: self.cpp_info.components["avdevice"].system_libs = ["m"] elif self.settings.os == "Windows": if self.options.avcodec: self.cpp_info.components["avcodec"].system_libs = [ "Mfplat", "Mfuuid", "strmiids" ] if self.options.avdevice: self.cpp_info.components["avdevice"].system_libs = [ "ole32", "psapi", "strmiids", "uuid", "oleaut32", "shlwapi", "gdi32", "vfw32" ] self.cpp_info.components["avutil"].system_libs = [ "user32", "bcrypt" ] self.cpp_info.components["avformat"].system_libs = ["secur32"] elif tools.is_apple_os(self.settings.os): if self.options.avdevice: self.cpp_info.components["avdevice"].frameworks = [ "CoreFoundation", "Foundation", "CoreGraphics" ] if self.options.avfilter: self.cpp_info.components["avfilter"].frameworks = [ "CoreGraphics" ] if self.options.avcodec: self.cpp_info.components["avcodec"].frameworks = [ "CoreVideo", "CoreMedia" ] if self.settings.os == "Macos": if self.options.avdevice: self.cpp_info.components["avdevice"].frameworks.append( "OpenGL") if self.options.avfilter: self.cpp_info.components["avfilter"].frameworks.append( "OpenGL") if self.options.avdevice: if self.options.get_safe("with_libalsa"): self.cpp_info.components["avdevice"].requires.append( "libalsa::libalsa") if self.options.get_safe("with_xcb"): self.cpp_info.components["avdevice"].requires.append( "xorg::xcb") if self.options.get_safe("with_pulse"): self.cpp_info.components["avdevice"].requires.append( "pulseaudio::pulseaudio") if self.options.get_safe("with_appkit"): self.cpp_info.components["avdevice"].frameworks.append( "AppKit") if self.options.get_safe("with_avfoundation"): self.cpp_info.components["avdevice"].frameworks.append( "AVFoundation") if self.options.get_safe("with_audiotoolbox"): self.cpp_info.components["avdevice"].frameworks.append( "CoreAudio") if self.options.avcodec: if self.options.with_zlib: self.cpp_info.components["avcodec"].requires.append( "zlib::zlib") if self.options.with_lzma: self.cpp_info.components["avcodec"].requires.append( "xz_utils::xz_utils") if self.options.with_libiconv: self.cpp_info.components["avcodec"].requires.append( "libiconv::libiconv") if self.options.with_openjpeg: self.cpp_info.components["avcodec"].requires.append( "openjpeg::openjpeg") if self.options.with_openh264: self.cpp_info.components["avcodec"].requires.append( "openh264::openh264") if self.options.with_vorbis: self.cpp_info.components["avcodec"].requires.append( "vorbis::vorbis") if self.options.with_opus: self.cpp_info.components["avcodec"].requires.append( "opus::opus") if self.options.with_libx264: self.cpp_info.components["avcodec"].requires.append( "libx264::libx264") if self.options.with_libx265: self.cpp_info.components["avcodec"].requires.append( "libx265::libx265") if self.options.with_libvpx: self.cpp_info.components["avcodec"].requires.append( "libvpx::libvpx") if self.options.with_libmp3lame: self.cpp_info.components["avcodec"].requires.append( "libmp3lame::libmp3lame") if self.options.with_libfdk_aac: self.cpp_info.components["avcodec"].requires.append( "libfdk_aac::libfdk_aac") if self.options.with_libwebp: self.cpp_info.components["avcodec"].requires.append( "libwebp::libwebp") if self.options.get_safe("with_audiotoolbox"): self.cpp_info.components["avcodec"].frameworks.append( "AudioToolbox") if self.options.get_safe("with_videotoolbox"): self.cpp_info.components["avcodec"].frameworks.append( "VideoToolbox") if self.options.avformat: if self.options.with_bzip2: self.cpp_info.components["avformat"].requires.append( "bzip2::bzip2") if self.options.with_zeromq: self.cpp_info.components["avformat"].requires.append( "zeromq::libzmq") if self.options.with_ssl == "openssl": self.cpp_info.components["avformat"].requires.append( "openssl::ssl") elif self.options.with_ssl == "securetransport": self.cpp_info.components["avformat"].frameworks.append( "Security") if self.options.avfilter: if self.options.with_freetype: self.cpp_info.components["avfilter"].requires.append( "freetype::freetype") if self.options.with_zeromq: self.cpp_info.components["avfilter"].requires.append( "zeromq::libzmq") if self.options.get_safe("with_appkit"): self.cpp_info.components["avfilter"].frameworks.append( "AppKit") if self.options.get_safe("with_coreimage"): self.cpp_info.components["avfilter"].frameworks.append( "CoreImage") if tools.Version(self.version) >= "5.0" and tools.is_apple_os( self.settings.os): self.cpp_info.components["avfilter"].frameworks.append("Metal") if self.options.get_safe("with_vaapi"): self.cpp_info.components["avutil"].requires.extend( ["vaapi::vaapi", "xorg::x11"]) if self.options.get_safe("with_vdpau"): self.cpp_info.components["avutil"].requires.append("vdpau::vdpau") if self._version_supports_vulkan() and self.options.get_safe( "with_vulkan"): self.cpp_info.components["avutil"].requires.append( "vulkan-loader::vulkan-loader") def _version_supports_vulkan(self): return tools.Version(self.version) >= "4.3.0"
class LibpqConan(ConanFile): name = "libpq" description = "The library used by all the standard PostgreSQL tools." topics = ("conan", "libpq", "postgresql", "database", "db") url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.postgresql.org/docs/current/static/libpq.html" author = "Bincrafters <*****@*****.**>" license = "PostgreSQL" exports_sources = ["CMakeLists.txt"] settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "with_zlib": [True, False], "with_openssl": [True, False], "disable_rpath": [True, False]} default_options = {'shared': False, 'fPIC': True, 'with_zlib': True, 'with_openssl': False, 'disable_rpath': False} generators = "cmake" _autotools = None @property def _source_subfolder(self): return "source_subfolder" @property def _is_clang8_x86(self): return self.settings.os == "Linux" and \ self.settings.compiler == "clang" and \ self.settings.compiler.version == "8" and \ self.settings.arch == "x86" def config_options(self): if self.settings.os == 'Windows': del self.options.fPIC def configure(self): del self.settings.compiler.libcxx del self.settings.compiler.cppstd if self.settings.os == 'Windows' and self.options.shared: raise ConanInvalidConfiguration("libpq can not be built as shared library on Windows") def requirements(self): if self.options.with_zlib: self.requires.add("zlib/1.2.11") if self.options.with_openssl: self.requires.add("openssl/1.0.2s") def source(self): tools.get(**self.conan_data["sources"][self.version]) extracted_dir = "postgresql-" + self.version os.rename(extracted_dir, self._source_subfolder) def _configure_autotools(self): if not self._autotools: self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) args = ['--without-readline'] args.append('--with-zlib' if self.options.with_zlib else '--without-zlib') args.append('--with-openssl' if self.options.with_openssl else '--without-openssl') if self.options.disable_rpath: args.append('--disable-rpath') if self._is_clang8_x86: self._autotools.flags.append("-msse2") with tools.chdir(self._source_subfolder): self._autotools.configure(args=args) return self._autotools def _configure_cmake(self): cmake = CMake(self) cmake.configure() return cmake def build(self): if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio": cmake = self._configure_cmake() cmake.definitions["USE_OPENSSL"] = self.options.with_openssl cmake.definitions["USE_ZLIB"] = self.options.with_zlib cmake.build() else: autotools = self._configure_autotools() with tools.chdir(os.path.join(self._source_subfolder, "src", "backend")): autotools.make(target="generated-headers") with tools.chdir(os.path.join(self._source_subfolder, "src", "common")): autotools.make() with tools.chdir(os.path.join(self._source_subfolder, "src", "include")): autotools.make() with tools.chdir(os.path.join(self._source_subfolder, "src", "interfaces", "libpq")): autotools.make() with tools.chdir(os.path.join(self._source_subfolder, "src", "bin", "pg_config")): autotools.make() def package(self): self.copy(pattern="COPYRIGHT", dst="licenses", src=self._source_subfolder) if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio": cmake = self._configure_cmake() cmake.install() else: autotools = self._configure_autotools() with tools.chdir(os.path.join(self._source_subfolder, "src", "common")): autotools.install() with tools.chdir(os.path.join(self._source_subfolder, "src", "include")): autotools.install() with tools.chdir(os.path.join(self._source_subfolder, "src", "interfaces", "libpq")): autotools.install() with tools.chdir(os.path.join(self._source_subfolder, "src", "bin", "pg_config")): autotools.install() tools.rmdir(os.path.join(self.package_folder, "include", "postgresql", "server")) self.copy(pattern="*.h", dst=os.path.join("include", "catalog"), src=os.path.join(self._source_subfolder, "src", "include", "catalog")) self.copy(pattern="*.h", dst=os.path.join("include", "catalog"), src=os.path.join(self._source_subfolder, "src", "backend", "catalog")) tools.rmdir(os.path.join(self.package_folder, "share")) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) def package_info(self): self.env_info.PostgreSQL_ROOT = self.package_folder self.cpp_info.libs = tools.collect_libs(self) if self.settings.os == "Linux": self.cpp_info.libs.append("pthread") elif self.settings.os == "Windows": self.cpp_info.libs.extend(["ws2_32", "secur32", "advapi32", "shell32", "crypt32"])
def _configure_autotools(self): autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) yes_no = lambda v: "yes" if v else "no" internal_no = lambda v: "internal" if v else "no" rootpath = lambda req: tools.unix_path(self.deps_cpp_info[req].rootpath ) rootpath_no = lambda v, req: rootpath(req) if v else "no" args = [] args.append("--datarootdir={}".format( tools.unix_path(os.path.join(self.package_folder, "res")))) # Shared/Static args.extend([ "--enable-static={}".format(yes_no(not self.options.shared)), "--enable-shared={}".format(yes_no(self.options.shared)), ]) # Enable C++14 if requested in conan profile or if with_charls enabled if (self.settings.compiler.cppstd and tools.valid_min_cppstd( self, 14)) or self.options.with_charls: args.append("--with-cpp14") # Debug if self.settings.build_type == "Debug": args.append("--enable-debug") # SIMD Intrinsics simd_intrinsics = self.options.get_safe("simd_intrinsics", False) if not simd_intrinsics: args.extend(["--without-sse", "--without-ssse3", "--without-avx"]) elif simd_intrinsics == "sse": args.extend(["--with-sse", "--without-ssse3", "--without-avx"]) elif simd_intrinsics == "ssse3": args.extend(["--with-sse", "--with-ssse3", "--without-avx"]) elif simd_intrinsics == "avx": args.extend(["--with-sse", "--with-ssse3", "--with-avx"]) # LTO (disabled) args.append("--disable-lto") # Symbols args.append("--with-hide_internal_symbols") # Do not add /usr/local/lib and /usr/local/include args.append("--without-local") # Threadsafe args.append("--with-threads={}".format(yes_no( self.options.threadsafe))) # Depencencies: args.append("--with-proj=yes") # always required ! args.append("--with-libz={}".format(yes_no(self.options.with_zlib))) if self._has_with_libdeflate_option: args.append("--with-libdeflate={}".format( yes_no(self.options.with_libdeflate))) args.append("--with-libiconv-prefix={}".format( rootpath_no(self.options.with_libiconv, "libiconv"))) args.append( "--with-liblzma=no" ) # always disabled: liblzma is an optional transitive dependency of gdal (through libtiff). args.append("--with-zstd={}".format( yes_no(self.options.get_safe("with_zstd")) )) # Optional direct dependency of gdal only if lerc lib enabled if self._has_with_blosc_option: args.append("--with-blosc={}".format( yes_no(self.options.with_blosc))) if self._has_with_lz4_option: args.append("--with-lz4={}".format(yes_no(self.options.with_lz4))) # Drivers: if not (self.options.with_zlib and self.options.with_png and bool(self.options.with_jpeg)): # MRF raster driver always depends on zlib, libpng and libjpeg: https://github.com/OSGeo/gdal/issues/2581 if tools.Version(self.version) < "3.0.0": args.append("--without-mrf") else: args.append("--disable-driver-mrf") args.append("--with-pg={}".format(yes_no(self.options.with_pg))) args.extend(["--without-grass", "--without-libgrass" ]) # TODO: to implement when libgrass lib available args.append("--with-cfitsio={}".format( rootpath_no(self.options.with_cfitsio, "cfitsio"))) args.append("--with-pcraster={}".format( internal_no(self.options.with_pcraster) )) # TODO: use conan recipe when available instead of internal one args.append("--with-png={}".format( rootpath_no(self.options.with_png, "libpng"))) args.append("--with-dds={}".format( rootpath_no(self.options.with_dds, "crunch"))) args.append("--with-gta={}".format( rootpath_no(self.options.with_gta, "libgta"))) args.append("--with-pcidsk={}".format( internal_no(self.options.with_pcidsk) )) # TODO: use conan recipe when available instead of internal one args.append("--with-libtiff={}".format( rootpath("libtiff"))) # always required ! args.append("--with-geotiff={}".format( rootpath("libgeotiff"))) # always required ! if self.options.with_jpeg == "libjpeg": args.append("--with-jpeg={}".format(rootpath("libjpeg"))) elif self.options.with_jpeg == "libjpeg-turbo": args.append("--with-jpeg={}".format(rootpath("libjpeg-turbo"))) else: args.append("--without-jpeg") args.append("--without-jpeg12" ) # disabled: it requires internal libjpeg and libgeotiff args.append("--with-charls={}".format(yes_no( self.options.with_charls))) args.append("--with-gif={}".format( rootpath_no(self.options.with_gif, "giflib"))) args.append( "--without-ogdi" ) # TODO: to implement when ogdi lib available (https://sourceforge.net/projects/ogdi/) args.append("--without-fme") # commercial library args.append( "--without-sosi") # TODO: to implement when fyba lib available args.append("--without-mongocxx") # TODO: handle mongo-cxx-driver v2 args.append("--with-mongocxxv3={}".format( yes_no(self.options.with_mongocxx))) args.append("--with-hdf4={}".format(yes_no(self.options.with_hdf4))) args.append("--with-hdf5={}".format(yes_no(self.options.with_hdf5))) args.append("--with-kea={}".format(yes_no(self.options.with_kea))) args.append("--with-netcdf={}".format( rootpath_no(self.options.with_netcdf, "netcdf"))) args.append("--with-jasper={}".format( rootpath_no(self.options.with_jasper, "jasper"))) args.append("--with-openjpeg={}".format( yes_no(self.options.with_openjpeg))) args.append( "--without-fgdb" ) # TODO: to implement when file-geodatabase-api lib available args.append("--without-ecw") # commercial library args.append("--without-kakadu") # commercial library args.extend( ["--without-mrsid", "--without-jp2mrsid", "--without-mrsid_lidar"]) # commercial library args.append("--without-jp2lura") # commercial library args.append("--without-msg") # commercial library args.append("--without-oci") # TODO args.append("--with-gnm={}".format(yes_no(self.options.with_gnm))) args.append("--with-mysql={}".format(yes_no(self.options.with_mysql))) args.append("--without-ingres") # commercial library args.append("--with-xerces={}".format( rootpath_no(self.options.with_xerces, "xerces-c"))) args.append("--with-expat={}".format(yes_no(self.options.with_expat))) args.append("--with-libkml={}".format( rootpath_no(self.options.with_libkml, "libkml"))) if self.options.with_odbc: args.append("--with-odbc={}".format( "yes" if self.settings.os == "Windows" else rootpath("odbc"))) else: args.append("--without-odbc") args.append("--without-dods-root" ) # TODO: to implement when libdap lib available args.append("--with-curl={}".format(yes_no(self.options.with_curl))) args.append("--with-xml2={}".format(yes_no(self.options.with_xml2))) args.append("--without-spatialite" ) # TODO: to implement when libspatialite lib available args.append("--with-sqlite3={}".format( yes_no(self.options.get_safe("with_sqlite3")))) args.append("--without-rasterlite2" ) # TODO: to implement when rasterlite2 lib available if self._has_with_pcre2_option: args.append("--with-pcre2={}".format( yes_no(self.options.get_safe("with_pcre2")))) args.append("--with-pcre={}".format( yes_no(self.options.get_safe("with_pcre")))) args.append("--without-teigha") # commercial library args.append("--without-idb") # commercial library if tools.Version(self.version) < "3.2.0": args.append("--without-sde") # commercial library if tools.Version(self.version) < "3.3.0": args.append("--without-epsilon") args.append("--with-webp={}".format( rootpath_no(self.options.with_webp, "libwebp"))) args.append("--with-geos={}".format(yes_no(self.options.with_geos))) args.append( "--without-sfcgal") # TODO: to implement when sfcgal lib available args.append("--with-qhull={}".format(yes_no(self.options.with_qhull))) if self.options.with_opencl: args.extend([ "--with-opencl", "--with-opencl-include={}".format( tools.unix_path(self.deps_cpp_info["opencl-headers"]. include_paths[0])), "--with-opencl-lib=-L{}".format( tools.unix_path( self.deps_cpp_info["opencl-icd-loader"].lib_paths[0])) ]) else: args.append("--without-opencl") args.append("--with-freexl={}".format(yes_no( self.options.with_freexl))) args.append("--with-libjson-c={}".format( rootpath("json-c"))) # always required ! if self.options.without_pam: args.append("--without-pam") args.append("--with-poppler={}".format( yes_no(self.options.with_poppler))) args.append("--with-podofo={}".format( rootpath_no(self.options.with_podofo, "podofo"))) if self.options.with_podofo: args.append("--with-podofo-lib=-l{}".format(" -l".join( self._gather_libs("podofo")))) args.append( "--without-pdfium") # TODO: to implement when pdfium lib available args.append("--without-perl") args.append("--without-python") args.append("--without-java") args.append("--without-hdfs") if tools.Version(self.version) >= "3.0.0": args.append("--without-tiledb" ) # TODO: to implement when tiledb lib available args.append("--without-mdb") args.append("--without-rasdaman" ) # TODO: to implement when rasdaman lib available if self._has_with_brunsli_option: args.append("--with-brunsli={}".format( yes_no(self.options.with_brunsli))) if tools.Version(self.version) >= "3.1.0": args.append("--without-rdb") # commercial library args.append("--without-armadillo" ) # TODO: to implement when armadillo lib available args.append("--with-cryptopp={}".format( rootpath_no(self.options.with_cryptopp, "cryptopp"))) args.append("--with-crypto={}".format(yes_no( self.options.with_crypto))) if tools.Version(self.version) >= "3.3.0": args.append("--with-lerc={}".format( internal_no(not self.options.without_lerc))) else: args.append("--with-lerc={}".format( yes_no(not self.options.without_lerc))) if self.options.with_null: args.append("--with-null") if self._has_with_exr_option: args.append("--with-exr={}".format(yes_no(self.options.with_exr))) if self._has_with_heif_option: args.append("--with-heif={}".format(yes_no( self.options.with_heif))) # Inject -stdlib=libc++ for clang with libc++ env_build_vars = autotools.vars if self.settings.compiler == "clang" and \ self.settings.os == "Linux" and tools.stdcpp_library(self) == "c++": env_build_vars["LDFLAGS"] = "-stdlib=libc++ {}".format( env_build_vars["LDFLAGS"]) autotools.configure(args=args, vars=env_build_vars) return autotools
class FreexlConan(ConanFile): name = "freexl" description = "FreeXL is an open source library to extract valid data " \ "from within an Excel (.xls) spreadsheet." license = ["MPL-1.0", "GPL-2.0-only", "LGPL-2.1-only"] topics = ("conan", "freexl", "excel", "xls") homepage = "https://www.gaia-gis.it/fossil/freexl/index" url = "https://github.com/conan-io/conan-center-index" exports_sources = "patches/**" settings = "os", "arch", "compiler", "build_type" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} _autotools = None @property def _source_subfolder(self): return "source_subfolder" def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.cppstd del self.settings.compiler.libcxx def requirements(self): self.requires("libiconv/1.16") def build_requirements(self): if self.settings.compiler != "Visual Studio": self.build_requires("gnu-config/cci.20201022") if tools.os_info.is_windows and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename(self.name + "-" + self.version, self._source_subfolder) @property def _user_info_build(self): return getattr(self, "user_info_build", None) or self.deps_user_info def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) if self.settings.compiler == "Visual Studio": self._build_msvc() else: shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB, os.path.join(self._source_subfolder, "config.sub")) shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS, os.path.join(self._source_subfolder, "config.guess")) autotools = self._configure_autotools() autotools.make() def _build_msvc(self): args = "freexl_i.lib FREEXL_EXPORT=-DDLL_EXPORT" if self.options.shared else "freexl.lib" with tools.chdir(self._source_subfolder): with tools.vcvars(self.settings): with tools.environment_append( VisualStudioBuildEnvironment(self).vars): self.run("nmake -f makefile.vc {}".format(args)) def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) args = [ "--disable-static" if self.options.shared else "--enable-static", "--enable-shared" if self.options.shared else "--disable-shared" ] self._autotools.configure(args=args, configure_dir=self._source_subfolder) return self._autotools def package(self): self.copy("COPYING", dst="licenses", src=self._source_subfolder) if self.settings.compiler == "Visual Studio": self.copy("freexl.h", dst="include", src=os.path.join(self._source_subfolder, "headers")) self.copy("*.lib", dst="lib", src=self._source_subfolder) self.copy("*.dll", dst="bin", src=self._source_subfolder) else: autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) for la_file in glob.glob( os.path.join(self.package_folder, "lib", "*.la")): os.remove(la_file) def package_info(self): self.cpp_info.libs = tools.collect_libs(self) if self.settings.os == "Linux": self.cpp_info.system_libs.append("m")
class YASMConan(ConanFile): name = "yasm" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/yasm/yasm" description = "Yasm is a complete rewrite of the NASM assembler under the 'new' BSD License" topics = ("conan", "yasm", "installer", "assembler") license = "BSD-2-Clause" settings = "os", "arch", "compiler", "build_type" _autotools = None @property def _source_subfolder(self): return "source_subfolder" def configure(self): del self.settings.compiler.libcxx del self.settings.compiler.cppstd def package_id(self): del self.info.settings.compiler def source(self): tools.get(**self.conan_data["sources"][self.version]) extracted_dir = "yasm-%s" % self.version os.rename(extracted_dir, self._source_subfolder) tools.download( "https://raw.githubusercontent.com/yasm/yasm/bcc01c59d8196f857989e6ae718458c296ca20e3/YASM-VERSION-GEN.bat", os.path.join(self._source_subfolder, "YASM-VERSION-GEN.bat")) @property def _msvc_subfolder(self): return os.path.join(self._source_subfolder, "Mkfiles", "vc10") def _build_vs(self): with tools.chdir(self._msvc_subfolder): with tools.vcvars(self.settings, force=True): msbuild = MSBuild(self) if self.settings.arch == "x86": msbuild.build_env.link_flags.append("/MACHINE:X86") elif self.settings.arch == "x86_64": msbuild.build_env.link_flags.append( "/SAFESEH:NO /MACHINE:X64") msbuild.build(project_file="yasm.sln", targets=["yasm"], platforms={"x86": "Win32"}, force_vcvars=True) def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) yes_no = lambda v: "yes" if v else "no" conf_args = [ "--enable-debug={}".format( yes_no(self.settings.build_type == "Debug")), "--disable-rpath", "--disable-nls", ] self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder) return self._autotools def build(self): if self.settings.compiler == "Visual Studio": self._build_vs() else: autotools = self._configure_autotools() autotools.make() def package(self): self.copy(pattern="BSD.txt", dst="licenses", src=self._source_subfolder) self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder) if self.settings.compiler == "Visual Studio": arch = { "x86": "Win32", "x86_64": "x64", }[str(self.settings.arch)] tools.mkdir(os.path.join(self.package_folder, "bin")) shutil.copy( os.path.join(self._msvc_subfolder, arch, str(self.settings.build_type), "yasm.exe"), os.path.join(self.package_folder, "bin", "yasm.exe")) self.copy(pattern="yasm.exe*", src=self._source_subfolder, dst="bin", keep_path=False) else: autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "share")) def package_info(self): bin_path = os.path.join(self.package_folder, "bin") self.output.info( "Appending PATH environment variable: {}".format(bin_path)) self.env_info.PATH.append(bin_path)
class LibcurlConan(ConanFile): name = "libcurl" description = "command line tool and library for transferring data with URLs" topics = ("conan", "curl", "libcurl", "data-transfer") url = "https://github.com/conan-io/conan-center-index" homepage = "https://curl.haxx.se" license = "MIT" exports_sources = ["lib_Makefile_add.am", "CMakeLists.txt", "patches/*"] generators = "cmake", "cmake_find_package_multi", "pkg_config" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "with_ssl": [False, "openssl", "wolfssl", "schannel", "darwinssl"], "with_openssl": [True, False, "deprecated"], "with_wolfssl": [True, False, "deprecated"], "with_winssl": [True, False, "deprecated"], "darwin_ssl": [True, False, "deprecated"], "with_ldap": [True, False], "with_libssh2": [True, False], "with_libidn": [True, False], "with_librtmp": [True, False], "with_libmetalink": [True, False], "with_libpsl": [True, False], "with_largemaxwritesize": [True, False], "with_nghttp2": [True, False], "with_zlib": [True, False], "with_brotli": [True, False], "with_zstd": [True, False], "with_c_ares": [True, False], } default_options = { "shared": False, "fPIC": True, "with_ssl": "openssl", "with_openssl": "deprecated", "with_wolfssl": "deprecated", "with_winssl": "deprecated", "darwin_ssl": "deprecated", "with_ldap": False, "with_libssh2": False, "with_libidn": False, "with_librtmp": False, "with_libmetalink": False, "with_libpsl": False, "with_largemaxwritesize": False, "with_nghttp2": False, "with_zlib": True, "with_brotli": False, "with_zstd": False, "with_c_ares": False, } _autotools = None _autotools_vars = None _cmake = None @property def _source_subfolder(self): return "source_subfolder" @property def _build_subfolder(self): return "build_subfolder" @property def _is_mingw(self): return self.settings.os == "Windows" and self.settings.compiler != "Visual Studio" @property def _is_win_x_android(self): return self.settings.os == "Android" and tools.os_info.is_windows @property def _is_using_cmake_build(self): return self.settings.compiler == "Visual Studio" or self._is_win_x_android @property def _has_zstd_option(self): return tools.Version(self.version) >= "7.72.0" def config_options(self): if self.settings.os == "Windows": del self.options.fPIC if not self._has_zstd_option: del self.options.with_zstd # Default options self.options.with_ssl = "darwinssl" if tools.is_apple_os( self.settings.os) else "openssl" def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd # Deprecated options # =============================== if (any(deprecated_option != "deprecated" for deprecated_option in [ self.options.with_openssl, self.options.with_wolfssl, self.options.with_winssl, self.options.darwin_ssl ])): self.output.warn( "with_openssl, with_winssl, darwin_ssl and with_wolfssl options are deprecated. Use with_ssl option instead." ) if tools.is_apple_os( self.settings.os) and self.options.with_ssl == "darwinssl": if self.options.darwin_ssl == True: self.options.with_ssl = "darwinssl" elif self.options.with_openssl == True: self.options.with_ssl = "openssl" elif self.options.with_wolfssl == True: self.options.with_ssl = "wolfssl" else: self.options.with_ssl = False if not tools.is_apple_os( self.settings.os) and self.options.with_ssl == "openssl": if self.settings.os == "Windows" and self.options.with_winssl == True: self.options.with_ssl = "schannel" elif self.options.with_openssl == True: self.options.with_ssl = "openssl" elif self.options.with_wolfssl == True: self.options.with_ssl = "wolfssl" else: self.options.with_ssl = False # =============================== if self.options.with_ssl == "schannel" and self.settings.os != "Windows": raise ConanInvalidConfiguration( "schannel only suppported on Windows.") if self.options.with_ssl == "darwinssl" and not tools.is_apple_os( self.settings.os): raise ConanInvalidConfiguration( "darwinssl only suppported on Apple like OS (Macos, iOS, watchOS or tvOS)." ) if self.options.with_ssl == "wolfssl" and self._is_using_cmake_build and tools.Version( self.version) < "7.70.0": raise ConanInvalidConfiguration( "Before 7.70.0, libcurl has no wolfssl support for Visual Studio or \"Windows to Android cross compilation\"" ) # These options are not used in CMake build yet if self._is_using_cmake_build: del self.options.with_libidn del self.options.with_librtmp del self.options.with_libmetalink del self.options.with_libpsl def requirements(self): if self.options.with_ssl == "openssl": self.requires("openssl/1.1.1k") elif self.options.with_ssl == "wolfssl": self.requires("wolfssl/4.6.0") if self.options.with_nghttp2: self.requires("libnghttp2/1.43.0") if self.options.with_libssh2: self.requires("libssh2/1.9.0") if self.options.with_zlib: self.requires("zlib/1.2.11") if self.options.with_brotli: self.requires("brotli/1.0.9") if self.options.get_safe("with_zstd"): self.requires("zstd/1.4.9") if self.options.with_c_ares: self.requires("c-ares/1.17.1") def package_id(self): # Deprecated options del self.info.options.with_openssl del self.info.options.with_winssl del self.info.options.darwin_ssl del self.info.options.with_wolfssl def build_requirements(self): if self._is_using_cmake_build: if self._is_win_x_android: self.build_requires("ninja/1.10.2") else: self.build_requires("libtool/2.4.6") self.build_requires("pkgconf/1.7.3") if tools.os_info.is_windows and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/20200517") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) tools.download("https://curl.haxx.se/ca/cacert.pem", "cacert.pem", verify=True) def imports(self): # Copy shared libraries for dependencies to fix DYLD_LIBRARY_PATH problems # # Configure script creates conftest that cannot execute without shared openssl binaries. # Ways to solve the problem: # 1. set *LD_LIBRARY_PATH (works with Linux with RunEnvironment # but does not work on OS X 10.11 with SIP) # 2. copying dylib's to the build directory (fortunately works on OS X) if self.settings.os == "Macos": self.copy("*.dylib*", dst=self._source_subfolder, keep_path=False) def build(self): self._patch_sources() if self._is_using_cmake_build: self._build_with_cmake() else: self._build_with_autotools() def _patch_sources(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) self._patch_misc_files() self._patch_mingw_files() self._patch_cmake() def _patch_misc_files(self): if self.options.with_largemaxwritesize: tools.replace_in_file( os.path.join(self._source_subfolder, "include", "curl", "curl.h"), "define CURL_MAX_WRITE_SIZE 16384", "define CURL_MAX_WRITE_SIZE 10485760") # https://github.com/curl/curl/issues/2835 # for additional info, see this comment https://github.com/conan-io/conan-center-index/pull/1008#discussion_r386122685 if self.settings.compiler == "apple-clang" and self.settings.compiler.version == "9.1": if self.options.with_ssl == "darwinssl": tools.replace_in_file( os.path.join(self._source_subfolder, "lib", "vtls", "sectransp.c"), "#define CURL_BUILD_MAC_10_13 MAC_OS_X_VERSION_MAX_ALLOWED >= 101300", "#define CURL_BUILD_MAC_10_13 0") def _patch_mingw_files(self): if not self._is_mingw: return # patch for zlib naming in mingw if self.options.with_zlib: configure_ac = os.path.join(self._source_subfolder, "configure.ac") zlib_name = self.deps_cpp_info["zlib"].libs[0] tools.replace_in_file(configure_ac, "AC_CHECK_LIB(z,", "AC_CHECK_LIB({},".format(zlib_name)) tools.replace_in_file(configure_ac, "-lz ", "-l{} ".format(zlib_name)) if self.options.shared: # for mingw builds - do not compile curl tool, just library # linking errors are much harder to fix than to exclude curl tool top_makefile = os.path.join(self._source_subfolder, "Makefile.am") tools.replace_in_file(top_makefile, "SUBDIRS = lib src", "SUBDIRS = lib") tools.replace_in_file(top_makefile, "include src/Makefile.inc", "") # patch for shared mingw build lib_makefile = os.path.join(self._source_subfolder, "lib", "Makefile.am") tools.replace_in_file(lib_makefile, "noinst_LTLIBRARIES = libcurlu.la", "") tools.replace_in_file(lib_makefile, "noinst_LTLIBRARIES =", "") tools.replace_in_file(lib_makefile, "lib_LTLIBRARIES = libcurl.la", "noinst_LTLIBRARIES = libcurl.la") # add directives to build dll # used only for native mingw-make if not tools.cross_building(self.settings): added_content = tools.load("lib_Makefile_add.am") tools.save(lib_makefile, added_content, append=True) def _patch_cmake(self): if not self._is_using_cmake_build: return # Custom findZstd.cmake file relies on pkg-config file, make sure that it's consumed on all platforms if self._has_zstd_option: tools.replace_in_file( os.path.join(self._source_subfolder, "CMake", "FindZstd.cmake"), "if(UNIX)", "if(TRUE)") # TODO: check this patch, it's suspicious tools.replace_in_file( os.path.join(self._source_subfolder, "CMakeLists.txt"), "include(CurlSymbolHiding)", "") def _get_configure_command_args(self): yes_no = lambda v: "yes" if v else "no" params = [ "--with-libidn2={}".format(yes_no(self.options.with_libidn)), "--with-librtmp={}".format(yes_no(self.options.with_librtmp)), "--with-libmetalink={}".format( yes_no(self.options.with_libmetalink)), "--with-libpsl={}".format(yes_no(self.options.with_libpsl)), "--with-schannel={}".format( yes_no(self.options.with_ssl == "schannel")), "--with-secure-transport={}".format( yes_no(self.options.with_ssl == "darwinssl")), "--with-brotli={}".format(yes_no(self.options.with_brotli)), "--enable-shared={}".format(yes_no(self.options.shared)), "--enable-static={}".format(yes_no(not self.options.shared)), "--enable-ldap={}".format(yes_no(self.options.with_ldap)), "--enable-debug={}".format( yes_no(self.settings.build_type == "Debug")), "--enable-ares={}".format(yes_no(self.options.with_c_ares)), "--enable-threaded-resolver={}".format( yes_no(self.options.with_c_ares)), ] if self.options.with_ssl == "openssl": params.append("--with-ssl={}".format( tools.unix_path(self.deps_cpp_info["openssl"].rootpath))) else: params.append("--without-ssl") if self.options.with_ssl == "wolfssl": params.append("--with-wolfssl={}".format( tools.unix_path(self.deps_cpp_info["wolfssl"].rootpath))) else: params.append("--without-wolfssl") if self.options.with_libssh2: params.append("--with-libssh2={}".format( tools.unix_path(self.deps_cpp_info["libssh2"].rootpath))) else: params.append("--without-libssh2") if self.options.with_nghttp2: params.append("--with-nghttp2={}".format( tools.unix_path(self.deps_cpp_info["libnghttp2"].rootpath))) else: params.append("--without-nghttp2") if self.options.with_zlib: params.append("--with-zlib={}".format( tools.unix_path(self.deps_cpp_info["zlib"].rootpath))) else: params.append("--without-zlib") if self._has_zstd_option: params.append("--with-zstd={}".format( yes_no(self.options.with_zstd))) # Cross building flags if tools.cross_building(self.settings): if self.settings.os == "Linux" and "arm" in self.settings.arch: params.append("--host=%s" % self._get_linux_arm_host()) elif self.settings.os == "iOS": params.append("--enable-threaded-resolver") params.append("--disable-verbose") elif self.settings.os == "Android": pass # this just works, conan is great! return params def _get_linux_arm_host(self): arch = None if self.settings.os == "Linux": arch = "arm-linux-gnu" # aarch64 could be added by user if "aarch64" in self.settings.arch: arch = "aarch64-linux-gnu" elif "arm" in self.settings.arch and "hf" in self.settings.arch: arch = "arm-linux-gnueabihf" elif "arm" in self.settings.arch and self._arm_version( str(self.settings.arch)) > 4: arch = "arm-linux-gnueabi" return arch # TODO, this should be a inner fuction of _get_linux_arm_host since it is only used from there # it should not polute the class namespace, since there are iOS and Android arm aritectures also def _arm_version(self, arch): version = None match = re.match(r"arm\w*(\d)", arch) if match: version = int(match.group(1)) return version def _build_with_autotools(self): with tools.chdir(self._source_subfolder): # autoreconf self.run("{} -fiv".format( tools.get_env("AUTORECONF") or "autoreconf"), win_bash=tools.os_info.is_windows, run_environment=True) # fix generated autotools files on alle to have relocateable binaries if tools.is_apple_os(self.settings.os): tools.replace_in_file("configure", "-install_name \\$rpath/", "-install_name ") self.run("chmod +x configure") # run configure with *LD_LIBRARY_PATH env vars it allows to pick up shared openssl with tools.run_environment(self): autotools, autotools_vars = self._configure_autotools() autotools.make(vars=autotools_vars) def _configure_autotools_vars(self): autotools_vars = self._autotools.vars # tweaks for mingw if self._is_mingw: autotools_vars["RCFLAGS"] = "-O COFF" if self.settings.arch == "x86": autotools_vars["RCFLAGS"] += " --target=pe-i386" else: autotools_vars["RCFLAGS"] += " --target=pe-x86-64" return autotools_vars def _configure_autotools(self): if self._autotools and self._autotools_vars: return self._autotools, self._autotools_vars self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) if self.settings.os != "Windows": self._autotools.fpic = self.options.get_safe("fPIC", True) self._autotools_vars = self._configure_autotools_vars() # tweaks for mingw if self._is_mingw: self._autotools.defines.append("_AMD64_") if tools.cross_building(self) and tools.is_apple_os(self.settings.os): self._autotools.defines.extend( ['HAVE_SOCKET', 'HAVE_FCNTL_O_NONBLOCK']) configure_args = self._get_configure_command_args() if self.settings.os == "iOS" and self.settings.arch == "x86_64": # please do not autodetect --build for the iOS simulator, thanks! self._autotools.configure(vars=self._autotools_vars, args=configure_args, build=False) else: self._autotools.configure(vars=self._autotools_vars, args=configure_args) return self._autotools, self._autotools_vars def _configure_cmake(self): if self._cmake: return self._cmake if self._is_win_x_android: self._cmake = CMake(self, generator="Ninja") else: self._cmake = CMake(self) self._cmake.definitions["BUILD_TESTING"] = False self._cmake.definitions["BUILD_CURL_EXE"] = False self._cmake.definitions[ "CURL_DISABLE_LDAP"] = not self.options.with_ldap self._cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared self._cmake.definitions["CURL_STATICLIB"] = not self.options.shared self._cmake.definitions["CMAKE_DEBUG_POSTFIX"] = "" if tools.Version(self.version) >= "7.72.0": self._cmake.definitions[ "CMAKE_USE_SCHANNEL"] = self.options.with_ssl == "schannel" else: self._cmake.definitions[ "CMAKE_USE_WINSSL"] = self.options.with_ssl == "schannel" self._cmake.definitions[ "CMAKE_USE_OPENSSL"] = self.options.with_ssl == "openssl" if tools.Version(self.version) >= "7.70.0": self._cmake.definitions[ "CMAKE_USE_WOLFSSL"] = self.options.with_ssl == "wolfssl" self._cmake.definitions["USE_NGHTTP2"] = self.options.with_nghttp2 self._cmake.definitions["CURL_ZLIB"] = self.options.with_zlib self._cmake.definitions["CURL_BROTLI"] = self.options.with_brotli if self._has_zstd_option: self._cmake.definitions["CURL_ZSTD"] = self.options.with_zstd self._cmake.definitions[ "CMAKE_USE_LIBSSH2"] = self.options.with_libssh2 self._cmake.definitions["ENABLE_ARES"] = self.options.with_c_ares self._cmake.configure(build_folder=self._build_subfolder) return self._cmake def _build_with_cmake(self): cmake = self._configure_cmake() cmake.build() def package(self): self.copy("COPYING", dst="licenses", src=self._source_subfolder) self.copy("cacert.pem", dst="res") if self._is_using_cmake_build: cmake = self._configure_cmake() cmake.install() tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) else: with tools.run_environment(self): with tools.chdir(self._source_subfolder): autotools, autotools_vars = self._configure_autotools() autotools.install(vars=autotools_vars) tools.rmdir(os.path.join(self.package_folder, "share")) for la_file in glob.glob( os.path.join(self.package_folder, "lib", "*.la")): os.remove(la_file) if self._is_mingw and self.options.shared: # Handle only mingw libs self.copy(pattern="*.dll", dst="bin", keep_path=False) self.copy(pattern="*.dll.a", dst="lib", keep_path=False) self.copy(pattern="*.lib", dst="lib", keep_path=False) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) def package_info(self): self.cpp_info.names["cmake_find_package"] = "CURL" self.cpp_info.names["cmake_find_package_multi"] = "CURL" self.cpp_info.names["pkg_config"] = "libcurl" self.cpp_info.components["curl"].names[ "cmake_find_package"] = "libcurl" self.cpp_info.components["curl"].names[ "cmake_find_package_multi"] = "libcurl" self.cpp_info.components["curl"].names["pkg_config"] = "libcurl" if self.settings.compiler == "Visual Studio": self.cpp_info.components["curl"].libs = [ "libcurl_imp" ] if self.options.shared else ["libcurl"] else: self.cpp_info.components["curl"].libs = ["curl"] if self.settings.os == "Linux": if self.options.with_libidn: self.cpp_info.components["curl"].libs.append("idn") if self.options.with_librtmp: self.cpp_info.components["curl"].libs.append("rtmp") if self.settings.os == "Linux": self.cpp_info.components["curl"].system_libs = ["rt", "pthread"] elif self.settings.os == "Windows": # used on Windows for VS build, native and cross mingw build self.cpp_info.components["curl"].system_libs = ["ws2_32"] if self.options.with_ldap: self.cpp_info.components["curl"].system_libs.append("wldap32") if self.options.with_ssl == "schannel": self.cpp_info.components["curl"].system_libs.append("crypt32") elif tools.is_apple_os(self.settings.os): if tools.Version(self.version) >= "7.77.0": self.cpp_info.components["curl"].frameworks.append( "SystemConfiguration") if self.options.with_ldap: self.cpp_info.components["curl"].system_libs.append("ldap") if self.options.with_ssl == "darwinssl": self.cpp_info.components["curl"].frameworks.extend( ["CoreFoundation", "Security"]) if self._is_mingw: # provide pthread for dependent packages self.cpp_info.components["curl"].cflags.append("-pthread") self.cpp_info.components["curl"].exelinkflags.append("-pthread") self.cpp_info.components["curl"].sharedlinkflags.append("-pthread") if not self.options.shared: self.cpp_info.components["curl"].defines.append("CURL_STATICLIB=1") if self.options.with_ssl == "openssl": self.cpp_info.components["curl"].requires.append( "openssl::openssl") if self.options.with_ssl == "wolfssl": self.cpp_info.components["curl"].requires.append( "wolfssl::wolfssl") if self.options.with_nghttp2: self.cpp_info.components["curl"].requires.append( "libnghttp2::libnghttp2") if self.options.with_libssh2: self.cpp_info.components["curl"].requires.append( "libssh2::libssh2") if self.options.with_zlib: self.cpp_info.components["curl"].requires.append("zlib::zlib") if self.options.with_brotli: self.cpp_info.components["curl"].requires.append("brotli::brotli") if self.options.get_safe("with_zstd"): self.cpp_info.components["curl"].requires.append("zstd::zstd") if self.options.with_c_ares: self.cpp_info.components["curl"].requires.append("c-ares::c-ares")
def build(self): self.output.info("cwd=%s" % (os.getcwd())) # put conan inclusion into CMakeLists.txt file or fail (strict=True) self.output.info('Patching CMakeLists.txt') tools.replace_in_file(os.sep.join([self.folder_name, "CMakeLists.txt"]), "project(RdKafka)", '''project(RdKafka) include(${CMAKE_BINARY_DIR}/../../conanbuildinfo.cmake) conan_basic_setup()''') # Some situations like using a bad passphrase causes rk to never be initialized # so calling this function would cause a segfault. Input validation would be helpful. tools.replace_in_file(os.sep.join([self.folder_name, "src", "rdkafka.c"]), '''static void rd_kafka_destroy_app (rd_kafka_t *rk, int blocking) { thrd_t thrd; #ifndef _MSC_VER int term_sig = rk->rk_conf.term_sig; #endif''', '''static void rd_kafka_destroy_app (rd_kafka_t *rk, int blocking) { if (rk == NULL) { return; } thrd_t thrd; #ifndef _MSC_VER int term_sig = rk->rk_conf.term_sig; #endif''') if tools.os_info.is_windows: # rdkafka C++ library does not export the special partition and offset constants/values # variables from the DLL, and looks like the library is switching to a preprocessor define # instead. This change includes the C-header file just to get the macro values, and then # changes the constants from being used as imported values to read from the macros. tools.replace_in_file(os.sep.join([self.folder_name, "examples", "rdkafka_example.cpp"]), '#include "rdkafkacpp.h"', '''#include "rdkafkacpp.h" #include "rdkafka.h"''') tools.replace_in_file(os.sep.join([self.folder_name, "examples", "rdkafka_example.cpp"]), 'RdKafka::Topic::PARTITION_UA', 'RD_KAFKA_PARTITION_UA') tools.replace_in_file(os.sep.join([self.folder_name, "examples", "rdkafka_example.cpp"]), 'RdKafka::Topic::OFFSET_BEGINNING', 'RD_KAFKA_OFFSET_BEGINNING') tools.replace_in_file(os.sep.join([self.folder_name, "examples", "rdkafka_example.cpp"]), 'RdKafka::Topic::OFFSET_END', 'RD_KAFKA_OFFSET_END') tools.replace_in_file(os.sep.join([self.folder_name, "examples", "rdkafka_example.cpp"]), 'RdKafka::Topic::OFFSET_STORED', 'RD_KAFKA_OFFSET_STORED') # src/rd.h includes win32_config.h which is not generated by CMake/Conan # so it builds librdkafka with fixed settings (!!!). # This change removes that choice, and both platforms use the generated config.h file self.output.info('Patching src/rd.h file') tools.replace_in_file(os.sep.join([self.folder_name, 'src', 'rd.h']), ''' #ifdef _MSC_VER /* Visual Studio */ #include "win32_config.h" #else /* POSIX / UNIX based systems */ #include "../config.h" /* mklove output */ #endif ''', '#include "../config.h"') files.mkdir("./{}/build".format(self.folder_name)) with tools.chdir("./{}/build".format(self.folder_name)): cmake = CMake(self) cmake.definitions['RDKAFKA_BUILD_STATIC'] = "OFF" if self.options.shared else "ON" cmake.definitions['ENABLE_DEVEL'] = "ON" if self.options.with_devel_asserts else "OFF" cmake.definitions['ENABLE_REFCNT_DEBUG'] = 'ON' if self.options.with_refcount_debug else "OFF" cmake.definitions['ENABLE_SHAREDPTR_DEBUG'] = 'ON' if self.options.with_sharedptr_debug else "OFF" cmake.definitions["RDKAFKA_BUILD_EXAMPLES"] = "ON" if self.options.build_examples else "OFF" cmake.definitions["RDKAFKA_BUILD_TESTS"] = "ON" if self.options.build_tests else "OFF" cmake.definitions["WITH_LIBDL"] = "OFF" cmake.definitions["WITH_PLUGINS"] = "OFF" cmake.definitions["WITH_SASL"] = "OFF" cmake.definitions["WITH_SSL"] = "ON" if self.options.with_openssl else "OFF" cmake.definitions["WITH_ZLIB"] = "ON" if self.options.with_zlib else "OFF" if self.settings.build_type == "Debug": cmake.definitions["WITHOUT_OPTIMIZATION"] = "ON" if self.options.shared: cmake.definitions["BUILD_SHARED_LIBS"] = "ON" # Enables overridding of default window build settings cmake.definitions["WITHOUT_WIN32_CONFIG"] = "ON" cmake.configure(source_dir="..", build_dir=".") cmake.build(build_dir=".") else: configure_args = [ "--prefix=", "--disable-sasl" ] if not self.options.with_openssl: configure_args.append('--disable-ssl') if not self.options.with_zlib: configure_args.append('--disable-lz4') if self.options.shared: ldflags = os.environ.get("LDFLAGS", "") if tools.os_info.is_linux: os.environ["LDFLAGS"] = ldflags + " -Wl,-rpath=\\$$ORIGIN" elif tools.os_info.is_macos: os.environ["LDFLAGS"] = ldflags + " -headerpad_max_install_names" else: configure_args.append("--enable-static") if self.settings.build_type == "Debug": configure_args.append("--disable-optimization") destdir = os.path.join(os.getcwd(), "install") with tools.chdir(self.folder_name): if tools.os_info.is_macos and self.options.shared: path = os.path.join(os.getcwd(), "mklove", "modules", "configure.lib") tools.replace_in_file( path, '-dynamiclib -Wl,-install_name,$(DESTDIR)$(libdir)/$(LIBFILENAME)', '-dynamiclib -Wl,-install_name,@rpath/$(LIBFILENAME)', ) env_build = AutoToolsBuildEnvironment(self) env_build.configure(args=configure_args) env_build.make() env_build.make(args=["install", "DESTDIR="+destdir]) with tools.chdir(self.folder_name): os.rename("LICENSE", "LICENSE.librdkafka")
class MozjpegConan(ConanFile): name = "mozjpeg" description = "MozJPEG is an improved JPEG encoder" url = "https://github.com/conan-io/conan-center-index" topics = ("conan", "image", "format", "mozjpeg", "jpg", "jpeg", "picture", "multimedia", "graphics") license = ("BSD", "BSD-3-Clause", "ZLIB") homepage = "https://github.com/mozilla/mozjpeg" exports_sources = ("CMakeLists.txt", "patches/*") generators = "cmake" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "SIMD": [True, False], "arithmetic_encoder": [True, False], "arithmetic_decoder": [True, False], "libjpeg7_compatibility": [True, False], "libjpeg8_compatibility": [True, False], "mem_src_dst": [True, False], "turbojpeg": [True, False], "java": [True, False], "enable12bit": [True, False], } default_options = { "shared": False, "fPIC": True, "SIMD": True, "arithmetic_encoder": True, "arithmetic_decoder": True, "libjpeg7_compatibility": False, "libjpeg8_compatibility": False, "mem_src_dst": True, "turbojpeg": True, "java": False, "enable12bit": False } _autotools = None _cmake = None @property def _source_subfolder(self): return "source_subfolder" @property def _build_subfolder(self): return "build_subfolder" def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd self.provides = ["libjpeg", "libjpeg-turbo" ] if self.options.turbojpeg else "libjpeg" def build_requirements(self): if self.settings.os != "Windows": self.build_requires("libtool/2.4.6") self.build_requires("pkgconf/1.7.3") if self.options.SIMD: self.build_requires("nasm/2.14") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename(self.name + "-" + self.version, self._source_subfolder) def _configure_cmake(self): if self._cmake: return self._cmake self._cmake = CMake(self) self._cmake.definitions["ENABLE_TESTING"] = False self._cmake.definitions["ENABLE_STATIC"] = not self.options.shared self._cmake.definitions["ENABLE_SHARED"] = self.options.shared self._cmake.definitions["WITH_SIMD"] = self.options.SIMD self._cmake.definitions[ "WITH_ARITH_ENC"] = self.options.arithmetic_encoder self._cmake.definitions[ "WITH_ARITH_DEC"] = self.options.arithmetic_decoder self._cmake.definitions[ "WITH_JPEG7"] = self.options.libjpeg7_compatibility self._cmake.definitions[ "WITH_JPEG8"] = self.options.libjpeg8_compatibility self._cmake.definitions["WITH_MEM_SRCDST"] = self.options.mem_src_dst self._cmake.definitions["WITH_TURBOJPEG"] = self.options.turbojpeg self._cmake.definitions["WITH_JAVA"] = self.options.java self._cmake.definitions["WITH_12BIT"] = self.options.enable12bit if self.settings.compiler == "Visual Studio": self._cmake.definitions["WITH_CRT_DLL"] = "MD" in str( self.settings.compiler.runtime) self._cmake.configure(build_folder=self._build_subfolder) return self._cmake def _configure_autotools(self): if not self._autotools: with tools.chdir(self._source_subfolder): self.run("autoreconf -fiv") self._autotools = AutoToolsBuildEnvironment(self) args = [] if self.options.shared: args.extend(["--disable-static", "--enable-shared"]) else: args.extend(["--disable-shared", "--enable-static"]) args.append("--with-pic" if self.options. get_safe("fPIC", True) else "--without-pic") args.append( "--with-simd" if self.options.SIMD else "--without-simd") args.append("--with-arith-enc" if self.options. arithmetic_encoder else "--without-arith-enc") args.append("--with-arith-dec" if self.options. arithmetic_decoder else "--without-arith-dec") args.append("--with-jpeg7" if self.options. libjpeg7_compatibility else "--without-jpeg7") args.append("--with-jpeg8" if self.options. libjpeg8_compatibility else "--without-jpeg8") args.append("--with-mem-srcdst" if self.options. mem_src_dst else "--without-mem-srcdst") args.append("--with-turbojpeg" if self.options. turbojpeg else "--without-turbojpeg") args.append( "--with-java" if self.options.java else "--without-java") args.append("--with-12bit" if self.options. enable12bit else "--without-12bit") self._autotools.configure(configure_dir=self._source_subfolder, args=args) return self._autotools def build(self): for patch in self.conan_data["patches"][self.version]: tools.patch(**patch) if self.settings.os == "Windows": cmake = self._configure_cmake() cmake.build() else: autotools = self._configure_autotools() autotools.make() def package(self): self.copy(pattern="LICENSE.md", dst="licenses", src=self._source_subfolder) if self.settings.os == "Windows": cmake = self._configure_cmake() cmake.install() tools.rmdir(os.path.join(self.package_folder, "doc")) else: autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "share")) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) for la_file in glob.glob( os.path.join(self.package_folder, "lib", "*.la")): os.remove(la_file) # remove binaries and pdb files for bin_pattern_to_remove in [ "cjpeg*", "djpeg*", "jpegtran*", "tjbench*", "wrjpgcom*", "rdjpgcom*", "*.pdb" ]: for bin_file in glob.glob( os.path.join(self.package_folder, "bin", bin_pattern_to_remove)): os.remove(bin_file) def package_info(self): # libjpeg self.cpp_info.components["libjpeg"].names["pkg_config"] = "libjpeg" self.cpp_info.components["libjpeg"].libs = [self._lib_name("jpeg")] if self.settings.os == "Linux": self.cpp_info.components["libjpeg"].system_libs.append("m") # libturbojpeg if self.options.turbojpeg: self.cpp_info.components["libturbojpeg"].names[ "pkg_config"] = "libturbojpeg" self.cpp_info.components["libturbojpeg"].libs = [ self._lib_name("turbojpeg") ] if self.settings.os == "Linux": self.cpp_info.components["libturbojpeg"].system_libs.append( "m") def _lib_name(self, name): if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio" and not self.options.shared: return name + "-static" return name
class LibUSBConan(ConanFile): name = "libusb" description = "A cross-platform library to access USB devices" license = "LGPL-2.1" homepage = "https://github.com/libusb/libusb" url = "https://github.com/conan-io/conan-center-index" topics = ("conan", "libusb", "usb", "device") settings = "os", "compiler", "build_type", "arch" options = { "shared": [True, False], "fPIC": [True, False], "enable_udev": [True, False], } default_options = { "shared": False, "fPIC": True, "enable_udev": True, } _autotools = None @property def _source_subfolder(self): return "source_subfolder" @property def _is_mingw(self): return self.settings.os == "Windows" and self.settings.compiler == "gcc" @property def _is_msvc(self): return self.settings.os == "Windows" and self.settings.compiler == "Visual Studio" @property def _settings_build(self): return self.settings_build if hasattr(self, "settings_build") else self.settings def config_options(self): if self.settings.os == "Windows": del self.options.fPIC if self.settings.os not in ["Linux", "Android"]: del self.options.enable_udev # FIXME: enable_udev should be True for Android, but libudev recipe is missing if self.settings.os == "Android": self.options.enable_udev = False def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd def build_requirements(self): if self._settings_build.os == "Windows" and not self._is_msvc and not tools.get_env("CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def requirements(self): if self.settings.os == "Linux": if self.options.enable_udev: self.requires("libudev/system") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def _build_visual_studio(self): with tools.chdir(self._source_subfolder): # Assume we're using the latest Visual Studio and default to libusb_2019.sln # (or libusb_2017.sln for libusb < 1.0.24). # If we're not using the latest Visual Studio, select an appropriate solution file. solution_msvc_year = 2019 if tools.Version(self.version) >= "1.0.24" else 2017 solution_msvc_year = { "11": 2012, "12": 2013, "14": 2015, "15": 2017 }.get(str(self.settings.compiler.version), solution_msvc_year) solution_file = os.path.join("msvc", "libusb_{}.sln".format(solution_msvc_year)) platforms = {"x86":"Win32"} properties = { # Enable LTO when CFLAGS contains -GL "WholeProgramOptimization": "true" if any(re.finditer("(^| )[/-]GL($| )", tools.get_env("CFLAGS", ""))) else "false", } msbuild = MSBuild(self) build_type = "Debug" if self.settings.build_type == "Debug" else "Release" msbuild.build(solution_file, platforms=platforms, upgrade_project=False, properties=properties, build_type=build_type) def _configure_autotools(self): if not self._autotools: self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) configure_args = ["--enable-shared" if self.options.shared else "--disable-shared"] configure_args.append("--enable-static" if not self.options.shared else "--disable-static") if self.settings.os in ["Linux", "Android"]: configure_args.append("--enable-udev" if self.options.enable_udev else "--disable-udev") elif self._is_mingw: if self.settings.arch == "x86_64": configure_args.append("--host=x86_64-w64-mingw32") elif self.settings.arch == "x86": configure_args.append("--build=i686-w64-mingw32") configure_args.append("--host=i686-w64-mingw32") self._autotools.configure(args=configure_args, configure_dir=self._source_subfolder) return self._autotools def build(self): if self._is_msvc: if tools.Version(self.version) < "1.0.24": for vcxproj in ["fxload_2017", "getopt_2017", "hotplugtest_2017", "libusb_dll_2017", "libusb_static_2017", "listdevs_2017", "stress_2017", "testlibusb_2017", "xusb_2017"]: vcxproj_path = os.path.join(self._source_subfolder, "msvc", "%s.vcxproj" % vcxproj) tools.replace_in_file(vcxproj_path, "<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>", "") self._build_visual_studio() else: autotools = self._configure_autotools() autotools.make() def _package_visual_studio(self): self.copy(pattern="libusb.h", dst=os.path.join("include", "libusb-1.0"), src=os.path.join(self._source_subfolder, "libusb"), keep_path=False) arch = "x64" if self.settings.arch == "x86_64" else "Win32" source_dir = os.path.join(self._source_subfolder, arch, str(self.settings.build_type), "dll" if self.options.shared else "lib") if self.options.shared: self.copy(pattern="libusb-1.0.dll", dst="bin", src=source_dir, keep_path=False) self.copy(pattern="libusb-1.0.lib", dst="lib", src=source_dir, keep_path=False) self.copy(pattern="libusb-usbdk-1.0.dll", dst="bin", src=source_dir, keep_path=False) self.copy(pattern="libusb-usbdk-1.0.lib", dst="lib", src=source_dir, keep_path=False) else: self.copy(pattern="libusb-1.0.lib", dst="lib", src=source_dir, keep_path=False) self.copy(pattern="libusb-usbdk-1.0.lib", dst="lib", src=source_dir, keep_path=False) def package(self): self.copy("COPYING", src=self._source_subfolder, dst="licenses", keep_path=False) if self._is_msvc: self._package_visual_studio() else: autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") def package_info(self): self.cpp_info.names["pkg_config"] = "libusb-1.0" self.cpp_info.libs = tools.collect_libs(self) self.cpp_info.includedirs.append(os.path.join("include", "libusb-1.0")) if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs.append("pthread") elif self.settings.os == "Macos": self.cpp_info.system_libs = ["objc"] self.cpp_info.frameworks = ["IOKit", "CoreFoundation", "Security"] elif self.settings.os == "Windows": self.cpp_info.system_libs = ["advapi32"]
class AutoconfConan(ConanFile): name = "autoconf" url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.gnu.org/software/autoconf/" description = "Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages" topics = ("conan", "autoconf", "configure", "build") license = ("GPL-2.0-or-later", "GPL-3.0-or-later") exports_sources = "patches/**" settings = "os", "arch", "compiler" _autotools = None @property def _source_subfolder(self): return os.path.join(self.source_folder, "source_subfolder") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("{}-{}".format(self.name, self.version), self._source_subfolder) def requirements(self): self.requires("m4/1.4.18") def package_id(self): del self.info.settings.arch del self.info.settings.compiler # The m4 requirement does not change the contents of this package self.info.requires.clear() def build_requirements(self): if tools.os_info.is_windows and "CONAN_BASH_PATH" not in os.environ: self.build_requires("msys2/20190524") @property def _datarootdir(self): return os.path.join(self.package_folder, "bin", "share") @property def _autoconf_datarootdir(self): return os.path.join(self._datarootdir, "autoconf") def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) datarootdir = self._datarootdir prefix = self.package_folder if self.settings.os == "Windows": datarootdir = tools.unix_path(datarootdir) prefix = tools.unix_path(prefix) conf_args = [ "--datarootdir={}".format(datarootdir), "--prefix={}".format(prefix), ] self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder) return self._autotools def _patch_files(self): for patch in self.conan_data["patches"][self.version]: tools.patch(**patch) def build(self): self._patch_files() autotools = self._configure_autotools() autotools.make() def package(self): self.copy("COPYING*", src=self._source_subfolder, dst="licenses") autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "bin", "share", "info")) tools.rmdir(os.path.join(self.package_folder, "bin", "share", "man")) if self.settings.os == "Windows": binpath = os.path.join(self.package_folder, "bin") for filename in os.listdir(binpath): fullpath = os.path.join(binpath, filename) if not os.path.isfile(fullpath): continue os.rename(fullpath, fullpath + ".exe") def package_info(self): bin_path = os.path.join(self.package_folder, "bin") self.output.info("Appending PATH env var with : {}".format(bin_path)) self.env_info.PATH.append(bin_path) ac_macrodir = self._autoconf_datarootdir self.output.info("Setting AC_MACRODIR to {}".format(ac_macrodir)) self.env_info.AC_MACRODIR = ac_macrodir autoconf = os.path.join(self.package_folder, "bin", "autoconf") if self.settings.os == "Windows": autoconf = tools.unix_path(autoconf) + ".exe" self.output.info("Setting AUTOCONF to {}".format(autoconf)) self.env_info.AUTOCONF = autoconf autoreconf = os.path.join(self.package_folder, "bin", "autoreconf") if self.settings.os == "Windows": autoreconf = tools.unix_path(autoreconf) + ".exe" self.output.info("Setting AUTORECONF to {}".format(autoreconf)) self.env_info.AUTORECONF = autoreconf autoheader = os.path.join(self.package_folder, "bin", "autoheader") if self.settings.os == "Windows": autoheader = tools.unix_path(autoheader) + ".exe" self.output.info("Setting AUTOHEADER to {}".format(autoheader)) self.env_info.AUTOHEADER = autoheader autom4te = os.path.join(self.package_folder, "bin", "autom4te") if self.settings.os == "Windows": autom4te = tools.unix_path(autom4te) + ".exe" self.output.info("Setting AUTOM4TE to {}".format(autom4te)) self.env_info.AUTOM4TE = autom4te autom4te_perllibdir = self._autoconf_datarootdir self.output.info("Setting AUTOM4TE_PERLLIBDIR to {}".format(autom4te_perllibdir)) self.env_info.AUTOM4TE_PERLLIBDIR = autom4te_perllibdir
class LibMP3LameConan(ConanFile): name = "libmp3lame" url = "https://github.com/conan-io/conan-center-index" description = "LAME is a high quality MPEG Audio Layer III (MP3) encoder licensed under the LGPL." homepage = "http://lame.sourceforge.net" topics = ("conan", "libmp3lame", "multimedia", "audio", "mp3", "decoder", "encoding", "decoding") license = "LGPL-2.0" settings = "os", "arch", "compiler", "build_type" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} exports_sources = ["patches/**"] _autotools = None @property def _is_msvc(self): return self.settings.compiler == "Visual Studio" @property def _source_subfolder(self): return "source_subfolder" @property def _settings_build(self): return self.settings_build if hasattr(self, "settings_build") else self.settings def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd def build_requirements(self): if not self._is_msvc: self.build_requires("gnu-config/cci.20201022") if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def _apply_patch(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) tools.replace_in_file(os.path.join(self._source_subfolder, "include", "libmp3lame.sym"), "lame_init_old\n", "") @contextmanager def _msvc_build_environment(self): with tools.chdir(self._source_subfolder): with tools.vcvars(self.settings): with tools.environment_append(VisualStudioBuildEnvironment(self).vars): yield def _build_vs(self): with self._msvc_build_environment(): shutil.copy("configMS.h", "config.h") tools.replace_in_file("Makefile.MSVC", "CC_OPTS = $(CC_OPTS) /MT", "") command = "nmake -f Makefile.MSVC comp=msvc asm=yes" if self.settings.arch == "x86_64": tools.replace_in_file("Makefile.MSVC", "MACHINE = /machine:I386", "MACHINE =/machine:X64") command += " MSVCVER=Win64" command += " libmp3lame.dll" if self.options.shared else " libmp3lame-static.lib" self.run(command) def _configure_autotools(self): if not self._autotools: args = ["--disable-frontend"] if self.options.shared: args.extend(["--disable-static", "-enable-shared"]) else: args.extend(["--disable-shared", "--enable-static"]) if self.settings.build_type == "Debug": args.append("--enable-debug") self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) if self.settings.compiler == "clang" and self.settings.arch in ["x86", "x86_64"]: self._autotools.flags.extend(["-mmmx", "-msse"]) self._autotools.configure(args=args, configure_dir=self._source_subfolder) return self._autotools @property def _user_info_build(self): return getattr(self, "user_info_build", None) or self.deps_user_info def _build_configure(self): shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB, os.path.join(self._source_subfolder, "config.sub")) shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS, os.path.join(self._source_subfolder, "config.guess")) autotools = self._configure_autotools() autotools.make() def build(self): self._apply_patch() if self._is_msvc: self._build_vs() else: self._build_configure() def package(self): self.copy(pattern="LICENSE", src=self._source_subfolder, dst="licenses") if self._is_msvc: self.copy(pattern="*.h", src=os.path.join(self._source_subfolder, "include"), dst=os.path.join("include", "lame")) name = "libmp3lame.lib" if self.options.shared else "libmp3lame-static.lib" self.copy(name, src=os.path.join(self._source_subfolder, "output"), dst="lib") if self.options.shared: self.copy(pattern="*.dll", src=os.path.join(self._source_subfolder, "output"), dst="bin") tools.rename(os.path.join(self.package_folder, "lib", name), os.path.join(self.package_folder, "lib", "mp3lame.lib")) else: autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "share")) tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") def package_info(self): self.cpp_info.libs = ["mp3lame"] if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs = ["m"]
def build_configure(self): without_ext = (tuple( extension for extension in self.extensions if not getattr(self.options, "with_" + extension))) ruby_folder = os.path.join(self.build_folder, self._source_subfolder) if not os.path.exists(ruby_folder): self.source() with tools.chdir(ruby_folder): if self.settings.compiler == "Visual Studio": with tools.environment_append({ "INCLUDE": self.deps_cpp_info.include_paths, "LIB": self.deps_cpp_info.lib_paths }): if self.settings.arch == "x86": target = "i686-mswin32" elif self.settings.arch == "x86_64": target = "x64-mswin64" else: raise Exception("Invalid arch") self.run( "{} --prefix={} --target={} --without-ext=\"{},\" --disable-install-doc" .format(os.path.join("win32", "configure.bat"), self.package_folder, target, ",".join(without_ext))) # Patch in runtime settings def define(line): tools.replace_in_file("Makefile", "CC = cl -nologo", "CC = cl -nologo\n" + line) define("RUNTIMEFLAG = -{}".format( self.settings.compiler.runtime)) if self.settings.build_type == "Debug": define("COMPILERFLAG = -Zi") define("OPTFLAGS = -Od -Ob0") self.run("nmake") self.run("nmake install") else: win_bash = tools.os_info.is_windows if not win_bash: without_ext = (*without_ext, 'win32ole', 'win32') autotools = AutoToolsBuildEnvironment(self, win_bash=win_bash) # Remove our libs; Ruby doesn't like Conan's help autotools.libs = [] if self.settings.compiler == "clang": autotools.link_flags.append("--rtlib=compiler-rt") args = [ "--with-out-ext=" + ",".join(without_ext), "--disable-install-doc", "--without-gmp", "--enable-shared", ] if self.options.with_openssl: openssl_dir = self.deps_cpp_info['openssl'].rootpath args.append('--with-openssl-dir={}'.format(openssl_dir)) if tools.os_info.is_macos: # Mitigates an rbinstall linker bug shutil.copy( os.path.join(openssl_dir, 'lib', 'libssl.1.1.dylib'), './libssl.1.1.dylib') shutil.copy( os.path.join(openssl_dir, 'lib', 'libcrypto.1.1.dylib'), './libcrypto.1.1.dylib') if self.options.with_zlib: zlib_dir = self.deps_cpp_info['zlib'].rootpath args.append('--with-zlib-dir={}'.format(zlib_dir)) if tools.os_info.is_macos: # Mitigates an rbinstall linker bug shutil.copy( os.path.join(zlib_dir, 'lib', 'libz.dylib'), './libz.dylib') # Mitigate macOS ARM -> x86 cross-compiling bug make_program = None if tools.os_info.is_macos and self.settings.arch == "x86_64" and self.settings.arch_build == "armv8": make_program = 'arch -x86_64 make' with tools.environment_append(autotools.vars): # Conan doesn't have a "configure_file" variable, so we have to add the automatically-generated variables ourselves... cmd = "arch -x86_64 ./configure {} --prefix={}".format( ' '.join(args), self.package_folder) self.output.info("Calling:\n > {}".format(cmd)) self.run(cmd) else: autotools.configure(args=args) autotools.make(['miniruby'], make_program) autotools.make(make_program=make_program) autotools.install(make_program=make_program)
class MozjpegConan(ConanFile): name = "mozjpeg" description = "MozJPEG is an improved JPEG encoder" url = "https://github.com/conan-io/conan-center-index" topics = ("conan", "image", "format", "mozjpeg", "jpg", "jpeg", "picture", "multimedia", "graphics") license = ("BSD", "BSD-3-Clause", "ZLIB") homepage = "https://github.com/mozilla/mozjpeg" exports_sources = ("CMakeLists.txt", "patches/*") generators = "cmake" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "SIMD": [True, False], "arithmetic_encoder": [True, False], "arithmetic_decoder": [True, False], "libjpeg7_compatibility": [True, False], "libjpeg8_compatibility": [True, False], "mem_src_dst": [True, False], "turbojpeg": [True, False], "java": [True, False], "enable12bit": [True, False], } default_options = { "shared": False, "fPIC": True, "SIMD": True, "arithmetic_encoder": True, "arithmetic_decoder": True, "libjpeg7_compatibility": False, "libjpeg8_compatibility": False, "mem_src_dst": True, "turbojpeg": True, "java": False, "enable12bit": False, } _autotools = None _cmake = None @property def _source_subfolder(self): return "source_subfolder" @property def _build_subfolder(self): return "build_subfolder" @property def _has_simd_support(self): return self.settings.arch in ["x86", "x86_64"] def config_options(self): if self.settings.os == "Windows": del self.options.fPIC if not self._has_simd_support: del self.options.SIMD def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd self.provides = ["libjpeg", "libjpeg-turbo" ] if self.options.turbojpeg else "libjpeg" @property def _use_cmake(self): return self.settings.os == "Windows" or tools.Version( self.version) >= "4.0.0" def build_requirements(self): if not self._use_cmake: if self.settings.os != "Windows": self.build_requires("libtool/2.4.6") self.build_requires("pkgconf/1.7.4") if self.options.get_safe("SIMD"): self.build_requires("nasm/2.15.05") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def _configure_cmake(self): if self._cmake: return self._cmake self._cmake = CMake(self) if tools.cross_building(self.settings): # FIXME: too specific and error prone, should be delegated to CMake helper cmake_system_processor = { "armv8": "aarch64", "armv8.3": "aarch64", }.get(str(self.settings.arch), str(self.settings.arch)) self._cmake.definitions[ "CMAKE_SYSTEM_PROCESSOR"] = cmake_system_processor self._cmake.definitions["ENABLE_TESTING"] = False self._cmake.definitions["ENABLE_STATIC"] = not self.options.shared self._cmake.definitions["ENABLE_SHARED"] = self.options.shared self._cmake.definitions["REQUIRE_SIMD"] = self.options.get_safe( "SIMD", False) self._cmake.definitions["WITH_SIMD"] = self.options.get_safe( "SIMD", False) self._cmake.definitions[ "WITH_ARITH_ENC"] = self.options.arithmetic_encoder self._cmake.definitions[ "WITH_ARITH_DEC"] = self.options.arithmetic_decoder self._cmake.definitions[ "WITH_JPEG7"] = self.options.libjpeg7_compatibility self._cmake.definitions[ "WITH_JPEG8"] = self.options.libjpeg8_compatibility self._cmake.definitions["WITH_MEM_SRCDST"] = self.options.mem_src_dst self._cmake.definitions["WITH_TURBOJPEG"] = self.options.turbojpeg self._cmake.definitions["WITH_JAVA"] = self.options.java self._cmake.definitions["WITH_12BIT"] = self.options.enable12bit self._cmake.definitions[ "CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT"] = False self._cmake.definitions[ "PNG_SUPPORTED"] = False # PNG and zlib are only required for executables (and static libraries) if self.settings.compiler == "Visual Studio": self._cmake.definitions["WITH_CRT_DLL"] = "MD" in str( self.settings.compiler.runtime) self._cmake.configure(build_folder=self._build_subfolder) return self._cmake def _configure_autotools(self): if not self._autotools: self._autotools = AutoToolsBuildEnvironment(self) yes_no = lambda v: "yes" if v else "no" args = [ "--with-pic={}".format( yes_no(self.options.get_safe("fPIC", True))), "--with-simd={}".format( yes_no(self.options.get_safe("SIMD", False))), "--with-arith-enc={}".format( yes_no(self.options.arithmetic_encoder)), "--with-arith-dec={}".format( yes_no(self.options.arithmetic_decoder)), "--with-jpeg7={}".format( yes_no(self.options.libjpeg7_compatibility)), "--with-jpeg8={}".format( yes_no(self.options.libjpeg8_compatibility)), "--with-mem-srcdst={}".format(yes_no( self.options.mem_src_dst)), "--with-turbojpeg={}".format(yes_no(self.options.turbojpeg)), "--with-java={}".format(yes_no(self.options.java)), "--with-12bit={}".format(yes_no(self.options.enable12bit)), "--enable-shared={}".format(yes_no(self.options.shared)), "--enable-static={}".format(yes_no(not self.options.shared)), ] self._autotools.configure(configure_dir=self._source_subfolder, args=args) return self._autotools def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) if self._use_cmake: cmake = self._configure_cmake() cmake.build() else: with tools.chdir(self._source_subfolder): self.run("{} -fiv".format(tools.get_env("AUTORECONF"))) autotools = self._configure_autotools() autotools.make() def package(self): self.copy(pattern="LICENSE.md", dst="licenses", src=self._source_subfolder) if self._use_cmake: cmake = self._configure_cmake() cmake.install() tools.rmdir(os.path.join(self.package_folder, "doc")) else: autotools = self._configure_autotools() autotools.install() tools.remove_files_by_mask( os.path.join(self.package_folder, "lib"), "*.la") tools.rmdir(os.path.join(self.package_folder, "share")) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) # remove binaries and pdb files for bin_pattern_to_remove in [ "cjpeg*", "djpeg*", "jpegtran*", "tjbench*", "wrjpgcom*", "rdjpgcom*", "*.pdb" ]: tools.remove_files_by_mask( os.path.join(self.package_folder, "bin"), bin_pattern_to_remove) def _lib_name(self, name): if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio" and not self.options.shared: return name + "-static" return name def package_info(self): # libjpeg self.cpp_info.components["libjpeg"].names["pkg_config"] = "libjpeg" self.cpp_info.components["libjpeg"].libs = [self._lib_name("jpeg")] if self.settings.os == "Linux": self.cpp_info.components["libjpeg"].system_libs.append("m") # libturbojpeg if self.options.turbojpeg: self.cpp_info.components["libturbojpeg"].names[ "pkg_config"] = "libturbojpeg" self.cpp_info.components["libturbojpeg"].libs = [ self._lib_name("turbojpeg") ] if self.settings.os == "Linux": self.cpp_info.components["libturbojpeg"].system_libs.append( "m")
class LibpqConan(ConanFile): name = "libpq" description = "The library used by all the standard PostgreSQL tools." topics = ("conan", "libpq", "postgresql", "database", "db") url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.postgresql.org/docs/current/static/libpq.html" license = "PostgreSQL" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "with_zlib": [True, False], "with_openssl": [True, False], "disable_rpath": [True, False] } default_options = { 'shared': False, 'fPIC': True, 'with_zlib': True, 'with_openssl': False, 'disable_rpath': False } _autotools = None def build_requirements(self): if self.settings.compiler == "Visual Studio": self.build_requires("strawberryperl/5.30.0.1") elif tools.os_info.is_windows: if "CONAN_BASH_PATH" not in os.environ and tools.os_info.detect_windows_subsystem( ) != 'msys2': self.build_requires("msys2/20190524") @property def _source_subfolder(self): return "source_subfolder" @property def _is_clang8_x86(self): return self.settings.os == "Linux" and \ self.settings.compiler == "clang" and \ self.settings.compiler.version == "8" and \ self.settings.arch == "x86" def config_options(self): if self.settings.os == 'Windows': del self.options.fPIC del self.options.disable_rpath def configure(self): del self.settings.compiler.libcxx del self.settings.compiler.cppstd if self.settings.compiler != "Visual Studio" and self.settings.os == "Windows": if self.options.shared: raise ConanInvalidConfiguration( "static mingw build is not possible") def requirements(self): if self.options.with_zlib: self.requires("zlib/1.2.11") if self.options.with_openssl: self.requires("openssl/1.1.1h") def source(self): tools.get(**self.conan_data["sources"][self.version]) extracted_dir = "postgresql-" + self.version os.rename(extracted_dir, self._source_subfolder) def _configure_autotools(self): if not self._autotools: self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) args = ['--without-readline'] args.append( '--with-zlib' if self.options.with_zlib else '--without-zlib') args.append('--with-openssl' if self.options. with_openssl else '--without-openssl') if tools.cross_building( self.settings) and not self.options.with_openssl: args.append("--disable-strong-random") if self.settings.os != "Windows" and self.options.disable_rpath: args.append('--disable-rpath') if self._is_clang8_x86: self._autotools.flags.append("-msse2") with tools.chdir(self._source_subfolder): self._autotools.configure(args=args) return self._autotools @property def _make_args(self): args = [] if self.settings.os == "Windows": args.append("MAKE_DLL={}".format(str(self.options.shared).lower())) return args def build(self): if self.settings.compiler == "Visual Studio": # https://www.postgresql.org/docs/8.3/install-win32-libpq.html # https://github.com/postgres/postgres/blob/master/src/tools/msvc/README if not self.options.shared: tools.replace_in_file( os.path.join(self._source_subfolder, "src", "tools", "msvc", "MKvcbuild.pm"), "$libpq = $solution->AddProject('libpq', 'dll', 'interfaces',", "$libpq = $solution->AddProject('libpq', 'lib', 'interfaces'," ) system_libs = ", ".join([ "'{}.lib'".format(lib) for lib in self.deps_cpp_info.system_libs ]) tools.replace_in_file( os.path.join(self._source_subfolder, "src", "tools", "msvc", "Project.pm"), "libraries => [],", "libraries => [{}],".format(system_libs)) runtime = { 'MT': 'MultiThreaded', 'MTd': 'MultiThreadedDebug', 'MD': 'MultiThreadedDLL', 'MDd': 'MultiThreadedDebugDLL' }.get(str(self.settings.compiler.runtime)) msbuild_project_pm = os.path.join(self._source_subfolder, "src", "tools", "msvc", "MSBuildProject.pm") tools.replace_in_file( msbuild_project_pm, "</Link>", """</Link> <Lib> <TargetMachine>$targetmachine</TargetMachine> </Lib>""") tools.replace_in_file(msbuild_project_pm, "'MultiThreadedDebugDLL'", "'%s'" % runtime) tools.replace_in_file(msbuild_project_pm, "'MultiThreadedDLL'", "'%s'" % runtime) config_default_pl = os.path.join(self._source_subfolder, "src", "tools", "msvc", "config_default.pl") solution_pm = os.path.join(self._source_subfolder, "src", "tools", "msvc", "Solution.pm") if self.options.with_zlib: tools.replace_in_file( solution_pm, "zdll.lib", "%s.lib" % self.deps_cpp_info["zlib"].libs[0]) tools.replace_in_file( config_default_pl, "zlib => undef", "zlib => '%s'" % self.deps_cpp_info["zlib"].rootpath.replace("\\", "/")) if self.options.with_openssl: for ssl in ["VC\libssl32", "VC\libssl64", "libssl"]: tools.replace_in_file( solution_pm, "%s.lib" % ssl, "%s.lib" % self.deps_cpp_info["openssl"].libs[0]) for crypto in [ "VC\libcrypto32", "VC\libcrypto64", "libcrypto" ]: tools.replace_in_file( solution_pm, "%s.lib" % crypto, "%s.lib" % self.deps_cpp_info["openssl"].libs[1]) tools.replace_in_file( config_default_pl, "openssl => undef", "openssl => '%s'" % self.deps_cpp_info["openssl"].rootpath.replace("\\", "/")) with tools.vcvars(self.settings): config = "DEBUG" if self.settings.build_type == "Debug" else "RELEASE" with tools.environment_append({"CONFIG": config}): with tools.chdir( os.path.join(self._source_subfolder, "src", "tools", "msvc")): self.run("perl build.pl libpq") if not self.options.shared: self.run("perl build.pl libpgport") else: autotools = self._configure_autotools() with tools.chdir( os.path.join(self._source_subfolder, "src", "backend")): autotools.make(args=self._make_args, target="generated-headers") with tools.chdir( os.path.join(self._source_subfolder, "src", "common")): autotools.make(args=self._make_args) if tools.Version(self.version) >= "12": with tools.chdir( os.path.join(self._source_subfolder, "src", "port")): autotools.make(args=self._make_args) with tools.chdir( os.path.join(self._source_subfolder, "src", "include")): autotools.make(args=self._make_args) with tools.chdir( os.path.join(self._source_subfolder, "src", "interfaces", "libpq")): autotools.make(args=self._make_args) with tools.chdir( os.path.join(self._source_subfolder, "src", "bin", "pg_config")): autotools.make(args=self._make_args) def _remove_unused_libraries_from_package(self): if self.options.shared: if self.settings.os == "Windows": globs = [] else: globs = [os.path.join(self.package_folder, "lib", "*.a")] else: globs = [ os.path.join(self.package_folder, "lib", "libpq.so*"), os.path.join(self.package_folder, "bin", "*.dll"), os.path.join(self.package_folder, "lib", "libpq*.dylib") ] if self.settings.os == "Windows": os.unlink(os.path.join(self.package_folder, "lib", "libpq.dll")) for globi in globs: for file in glob.glob(globi): os.remove(file) def package(self): self.copy(pattern="COPYRIGHT", dst="licenses", src=self._source_subfolder) if self.settings.compiler == "Visual Studio": self.copy("*postgres_ext.h", src=self._source_subfolder, dst="include", keep_path=False) self.copy("*pg_config.h", src=self._source_subfolder, dst="include", keep_path=False) self.copy("*pg_config_ext.h", src=self._source_subfolder, dst="include", keep_path=False) self.copy("*libpq-fe.h", src=self._source_subfolder, dst="include", keep_path=False) self.copy("*libpq-events.h", src=self._source_subfolder, dst="include", keep_path=False) self.copy("*.h", src=os.path.join(self._source_subfolder, "src", "include", "libpq"), dst=os.path.join("include", "libpq"), keep_path=False) self.copy("*genbki.h", src=self._source_subfolder, dst=os.path.join("include", "catalog"), keep_path=False) self.copy("*pg_type.h", src=self._source_subfolder, dst=os.path.join("include", "catalog"), keep_path=False) if self.options.shared: self.copy("**/libpq.dll", src=self._source_subfolder, dst="bin", keep_path=False) self.copy("**/libpq.lib", src=self._source_subfolder, dst="lib", keep_path=False) else: self.copy("*.lib", src=self._source_subfolder, dst="lib", keep_path=False) else: autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows ) #self._configure_autotools() with tools.chdir( os.path.join(self._source_subfolder, "src", "common")): autotools.install(args=self._make_args) with tools.chdir( os.path.join(self._source_subfolder, "src", "include")): autotools.install(args=self._make_args) with tools.chdir( os.path.join(self._source_subfolder, "src", "interfaces", "libpq")): autotools.install(args=self._make_args) if tools.Version(self.version) >= "12": with tools.chdir( os.path.join(self._source_subfolder, "src", "port")): autotools.install(args=self._make_args) with tools.chdir( os.path.join(self._source_subfolder, "src", "bin", "pg_config")): autotools.install(args=self._make_args) self._remove_unused_libraries_from_package() tools.rmdir( os.path.join(self.package_folder, "include", "postgresql", "server")) self.copy(pattern="*.h", dst=os.path.join("include", "catalog"), src=os.path.join(self._source_subfolder, "src", "include", "catalog")) self.copy(pattern="*.h", dst=os.path.join("include", "catalog"), src=os.path.join(self._source_subfolder, "src", "backend", "catalog")) tools.rmdir(os.path.join(self.package_folder, "share")) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) def _construct_library_name(self, name): if self.settings.compiler == "Visual Studio": return "lib{}".format(name) return name def package_info(self): self.cpp_info.names["cmake_find_package"] = "PostgreSQL" self.cpp_info.names["cmake_find_package_multi"] = "PostgreSQL" self.env_info.PostgreSQL_ROOT = self.package_folder self.cpp_info.components["pq"].libs = [ self._construct_library_name("pq") ] if self.options.with_zlib: self.cpp_info.components["pq"].requires.append("zlib::zlib") if self.options.with_openssl: self.cpp_info.components["pq"].requires.append("openssl::openssl") if not self.options.shared: if self.settings.compiler == "Visual Studio": if tools.Version(self.version) < '12': self.cpp_info.components["pgport"].libs = ["libpgport"] self.cpp_info.components["pq"].requires.extend(["pgport"]) else: self.cpp_info.components["pgcommon"].libs = ["libpgcommon"] self.cpp_info.components["pgport"].libs = ["libpgport"] self.cpp_info.components["pq"].requires.extend( ["pgport", "pgcommon"]) else: if tools.Version(self.version) < '12': self.cpp_info.components["pgcommon"].libs = ["pgcommon"] self.cpp_info.components["pq"].requires.extend( ["pgcommon"]) else: self.cpp_info.components["pgcommon"].libs = [ "pgcommon", "pgcommon_shlib" ] self.cpp_info.components["pgport"].libs = [ "pgport", "pgport_shlib" ] self.cpp_info.components["pq"].requires.extend( ["pgport", "pgcommon"]) if self.settings.os == "Linux": self.cpp_info.components["pq"].system_libs = ["pthread"] elif self.settings.os == "Windows": self.cpp_info.components["pq"].system_libs = [ "ws2_32", "secur32", "advapi32", "shell32", "crypt32", "wldap32" ]
class XorgProtoConan(ConanFile): name = "xorg-proto" description = "This package provides the headers and specification documents defining " \ "the core protocol and (many) extensions for the X Window System." topics = ("conan", "xproto", "header", "specification") license = "X11" homepage = "https://gitlab.freedesktop.org/xorg/proto/xorgproto" url = "https://github.com/conan-io/conan-center-index" settings = "os", "arch", "compiler", "build_type" generators = "PkgConfigDeps" _autotools = None @property def _source_subfolder(self): return "source_subfolder" @property def _settings_build(self): return getattr(self, "settings_build", self.settings) @property def _user_info_build(self): return getattr(self, "user_info_build", self.deps_user_info) def build_requirements(self): self.build_requires("automake/1.16.3") self.build_requires("xorg-macros/1.19.3") self.build_requires("pkgconf/1.7.4") if self._settings_build.os == "Windows" and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def requirements(self): if hasattr(self, "settings_build"): self.requires("xorg-macros/1.19.3") def package_id(self): # self.info.header_only() would be fine too, but keep the os to add c3i test coverage for Windows. del self.info.settings.arch del self.info.settings.build_type del self.info.settings.compiler def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) @contextlib.contextmanager def _build_context(self): if self.settings.compiler == "Visual Studio": with tools.vcvars(self.settings): env = { "CC": "{} cl -nologo".format( self._user_info_build["automake"].compile).replace( "\\", "/"), } with tools.environment_append(env): yield else: yield def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=self._settings_build.os == "Windows") self._autotools.libs = [] self._autotools.configure(configure_dir=self._source_subfolder) return self._autotools def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) with self._build_context(): autotools = self._configure_autotools() autotools.make() @property def _pc_data_path(self): return os.path.join(self.package_folder, "res", "pc_data.yml") def package(self): self.copy("COPYING-*", src=self._source_subfolder, dst="licenses") with self._build_context(): autotools = self._configure_autotools() autotools.install() pc_data = {} for fn in glob.glob( os.path.join(self.package_folder, "share", "pkgconfig", "*.pc")): pc_text = load(self, fn) filename = os.path.basename(fn)[:-3] name = next( re.finditer("^Name: ([^\n$]+)[$\n]", pc_text, flags=re.MULTILINE)).group(1) version = next( re.finditer("^Version: ([^\n$]+)[$\n]", pc_text, flags=re.MULTILINE)).group(1) pc_data[filename] = { "version": version, "name": name, } mkdir(self, os.path.dirname(self._pc_data_path)) save(self, self._pc_data_path, yaml.dump(pc_data)) rmdir(self, os.path.join(self.package_folder, "share")) def package_info(self): for filename, name_version in yaml.safe_load(open( self._pc_data_path)).items(): self.cpp_info.components[filename].filenames[ "pkg_config"] = filename self.cpp_info.components[filename].libdirs = [] if hasattr(self, "settings_build"): self.cpp_info.components[filename].requires = [ "xorg-macros::xorg-macros" ] self.cpp_info.components[filename].version = name_version[ "version"] self.cpp_info.components[filename].set_property( "pkg_config_name", filename) self.cpp_info.components["xproto"].includedirs.append( os.path.join("include", "X11"))
class LibPcapConan(ConanFile): name = "libpcap" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/the-tcpdump-group/libpcap" description = "libpcap is an API for capturing network traffic" license = "BSD-3-Clause" topics = ("networking", "pcap", "sniffing", "network-traffic") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "enable_libusb": [True, False], "enable_universal": [True, False] } default_options = { "shared": False, "fPIC": True, "enable_libusb": False, "enable_universal": True } _autotools = None # TODO: Add dbus-glib when available # TODO: Add libnl-genl when available # TODO: Add libbluetooth when available # TODO: Add libibverbs when available @property def _source_subfolder(self): return "source_subfolder" def requirements(self): if self.options.enable_libusb: self.requires("libusb/1.0.23") def build_requirements(self): if self.settings.os == "Linux": self.build_requires("bison/3.7.1") self.build_requires("flex/2.6.4") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd def validate(self): if self.settings.os == "Macos" and self.options.shared: raise ConanInvalidConfiguration("libpcap can not be built as shared on OSX.") if self.settings.os == "Windows": raise ConanInvalidConfiguration("libpcap is not supported on Windows.") def _configure_autotools(self): if not self._autotools: self._autotools = AutoToolsBuildEnvironment(self) configure_args = ["--enable-shared" if self.options.shared else "--disable-shared"] configure_args.append("--disable-universal" if not self.options.enable_universal else "") configure_args.append("--enable-usb" if self.options.enable_libusb else "--disable-usb") configure_args.extend([ "--without-libnl", "--disable-bluetooth", "--disable-packet-ring", "--disable-dbus", "--disable-rdma" ]) if tools.cross_building(self.settings): target_os = "linux" if self.settings.os == "Linux" else "null" configure_args.append("--with-pcap=%s" % target_os) elif "arm" in self.settings.arch and self.settings.os == "Linux": configure_args.append("--host=arm-linux") self._autotools.configure(args=configure_args, configure_dir=self._source_subfolder) return self._autotools def build(self): autotools = self._configure_autotools() autotools.make() def package(self): self.copy("LICENSE", src=self._source_subfolder, dst="licenses") autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "share")) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) if self.options.shared: tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.a") def package_info(self): self.cpp_info.libs = tools.collect_libs(self)
class GperfConan(ConanFile): name = "gperf_installer" version = "3.1" license = "GPL-3.0" url = "https://github.com/conan-community/conan-gperf" homepage = "https://www.gnu.org/software/gperf" description = "GNU gperf is a perfect hash function generator" topics = ("conan", "gperf", "hash-generator", "hash") author = "Conan Community" settings = "os_build", "arch_build", "compiler" exports = "LICENSE.md" _source_subfolder = "source_subfolder" _autotools = None @property def _is_msvc(self): return self.settings.compiler == "Visual Studio" @property def _is_mingw_windows(self): return self.settings.os_build == "Windows" and self.settings.compiler == "gcc" and os.name == "nt" def build_requirements(self): if self.settings.os_build == "Windows": self.build_requires("cygwin_installer/2.9.0@bincrafters/stable") def source(self): sha256 = "588546b945bba4b70b6a3a616e80b4ab466e3f33024a352fc2198112cdbb3ae2" tools.get("https://ftp.gnu.org/pub/gnu/gperf/gperf-{}.tar.gz".format( self.version), sha256=sha256) extracted_dir = "gperf-" + self.version os.rename(extracted_dir, self._source_subfolder) def _configure_autotools(self): if not self._autotools: args = [] cwd = os.getcwd() win_bash = self._is_msvc or self._is_mingw_windows if self._is_msvc: args.extend([ "CC={}/build-aux/compile cl -nologo".format(cwd), "CFLAGS=-{}".format(self.settings.compiler.runtime), "CXX={}/build-aux/compile cl -nologo".format(cwd), "CXXFLAGS=-{}".format(self.settings.compiler.runtime), "CPPFLAGS=-D_WIN32_WINNT=_WIN32_WINNT_WIN8 -I/usr/local/msvc32/include", "LDFLAGS=-L/usr/local/msvc32/lib", "LD=link", "NM=dumpbin -symbols", "STRIP=:", "AR={}/build-aux/ar-lib lib".format(cwd), "RANLIB=:" ]) self._autotools = AutoToolsBuildEnvironment(self, win_bash=win_bash) self._autotools.configure(args=args) return self._autotools def _build_configure(self): with tools.chdir(self._source_subfolder): autotools = self._configure_autotools() autotools.make() def build(self): if self._is_msvc: with tools.vcvars(self.settings): self._build_configure() else: self._build_configure() def package(self): self.copy("COPYING", dst="licenses", src=self._source_subfolder) with tools.chdir(self._source_subfolder): autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "share")) def package_id(self): del self.info.settings.compiler def package_info(self): self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
class TheoraConan(ConanFile): name = "theora" description = "Theora is a free and open video compression format from the Xiph.org Foundation" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/xiph/theora" topics = ("conan", "theora", "video", "video-compressor", "video-format") license = "BSD-3-Clause" settings = "os", "arch", "compiler", "build_type" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} _autotools = None @property def _source_subfolder(self): return "source_subfolder" def config_options(self): if self.settings.os == 'Windows': del self.options.fPIC def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd def requirements(self): self.requires("ogg/1.3.4") @property def _settings_build(self): return getattr(self, "settings_build", self.settings) def build_requirements(self): if self.settings.compiler != "Visual Studio": self.build_requires("gnu-config/cci.20201022") if self._settings_build.os == "Windows" and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def source(self): tools.get(**self.conan_data["sources"][self.version][0], strip_root=True, destination=self._source_subfolder) source = self.conan_data["sources"][self.version][1] url = source["url"] filename = url[url.rfind("/") + 1:] tools.download(url, filename) tools.check_sha256(filename, source["sha256"]) shutil.move(filename, os.path.join(self._source_subfolder, 'lib', filename)) def _build_msvc(self): def format_libs(libs): return " ".join([l + ".lib" for l in libs]) project = "libtheora" config = "dynamic" if self.options.shared else "static" vcproj_dir = os.path.join(self._source_subfolder, "win32", "VS2008", project) vcproj = "{}_{}.vcproj".format(project, config) # fix hard-coded ogg names vcproj_path = os.path.join(vcproj_dir, vcproj) if self.options.shared: tools.replace_in_file(vcproj_path, "libogg.lib", format_libs(self.deps_cpp_info["ogg"].libs)) if "MT" in self.settings.compiler.runtime: tools.replace_in_file(vcproj_path, 'RuntimeLibrary="2"', 'RuntimeLibrary="0"') tools.replace_in_file(vcproj_path, 'RuntimeLibrary="3"', 'RuntimeLibrary="1"') with tools.chdir(vcproj_dir): msbuild = MSBuild(self) try: # upgrade .vcproj msbuild.build(vcproj, platforms={ "x86": "Win32", "x86_64": "x64" }) except: # build .vcxproj vcxproj = "{}_{}.vcxproj".format(project, config) msbuild.build(vcxproj, platforms={ "x86": "Win32", "x86_64": "x64" }) def _configure_autotools(self): if not self._autotools: self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) configure_args = ['--disable-examples'] if self.options.shared: configure_args.extend(['--disable-static', '--enable-shared']) else: configure_args.extend(['--disable-shared', '--enable-static']) self._autotools.configure(configure_dir=self._source_subfolder, args=configure_args) return self._autotools @property def _user_info_build(self): return getattr(self, "user_info_build", self.deps_user_info) def build(self): if self.settings.compiler == 'Visual Studio': self._build_msvc() else: shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB, os.path.join(self._source_subfolder, "config.sub")) shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS, os.path.join(self._source_subfolder, "config.guess")) configure = os.path.join(self._source_subfolder, "configure") permission = stat.S_IMODE(os.lstat(configure).st_mode) os.chmod(configure, (permission | stat.S_IEXEC)) autotools = self._configure_autotools() autotools.make() def package(self): self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder) self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder) if self.settings.compiler == 'Visual Studio': include_folder = os.path.join(self._source_subfolder, "include") self.copy(pattern="*.h", dst="include", src=include_folder) self.copy(pattern="*.dll", dst="bin", keep_path=False) self.copy(pattern="*.lib", dst="lib", keep_path=False) else: autotools = self._configure_autotools() autotools.install() tools.remove_files_by_mask( os.path.join(self.package_folder, "lib"), "*.la") tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.rmdir(os.path.join(self.package_folder, "share")) def package_info(self): if self.settings.compiler == "Visual Studio": self.cpp_info.libs = [ "libtheora" if self.options.shared else "libtheora_static" ] else: self.cpp_info.names[ "pkg_config"] = "theora_full_package" # to avoid conflicts with _theora component self.cpp_info.components["_theora"].names["pkg_config"] = "theora" self.cpp_info.components["_theora"].libs = ["theora"] self.cpp_info.components["_theora"].requires = ["ogg::ogg"] self.cpp_info.components["theoradec"].names[ "pkg_config"] = "theoradec" self.cpp_info.components["theoradec"].libs = ["theoradec"] self.cpp_info.components["theoradec"].requires = ["ogg::ogg"] self.cpp_info.components["theoraenc"].names[ "pkg_config"] = "theoraenc" self.cpp_info.components["theoraenc"].libs = ["theoraenc"] self.cpp_info.components["theoraenc"].requires = [ "theoradec", "ogg::ogg" ]
class CoinCbcConan(ConanFile): name = "coin-cbc" description = "COIN-OR Branch-and-Cut solver" topics = ("clp", "simplex", "solver", "linear", "programming") url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/coin-or/Clp" license = ("EPL-2.0", ) settings = "os", "arch", "build_type", "compiler" options = { "shared": [True, False], "fPIC": [True, False], "parallel": [True, False], } default_options = { "shared": False, "fPIC": True, "parallel": False, } generators = "pkg_config" _autotools = None @property def _source_subfolder(self): return "source_subfolder" @property def _build_subfolder(self): return "build_subfolder" def export_sources(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): self.copy(patch["patch_file"]) def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: del self.options.fPIC def requirements(self): self.requires("coin-utils/2.11.4") self.requires("coin-osi/0.108.6") self.requires("coin-clp/1.17.6") self.requires("coin-cgl/0.60.3") if self.settings.compiler == "Visual Studio" and self.options.parallel: self.requires("pthreads4w/3.0.0") @property def _settings_build(self): return getattr(self, "settings_build", self.settings) @property def _user_info_build(self): return getattr(self, "user_info_build", self.deps_user_info) def build_requirements(self): self.build_requires("gnu-config/cci.20201022") self.build_requires("pkgconf/1.7.4") if self._settings_build.os == "Windows" and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") if self.settings.compiler == "Visual Studio": self.build_requires("automake/1.16.4") def validate(self): if self.settings.os == "Windows" and self.options.shared: raise ConanInvalidConfiguration( "coin-cbc does not support shared builds on Windows") # FIXME: This issue likely comes from very old autotools versions used to produce configure. if hasattr(self, "settings_build") and tools.cross_building( self) and self.options.shared: raise ConanInvalidConfiguration( "coin-cbc shared not supported yet when cross-building") def source(self): tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder) @contextmanager def _build_context(self): if self.settings.compiler == "Visual Studio": with tools.vcvars(self.settings): env = { "CC": "{} cl -nologo".format( tools.unix_path( self._user_info_build["automake"].compile)), "CXX": "{} cl -nologo".format( tools.unix_path( self._user_info_build["automake"].compile)), "LD": "{} link -nologo".format( tools.unix_path( self._user_info_build["automake"].compile)), "AR": "{} lib".format( tools.unix_path( self._user_info_build["automake"].ar_lib)), } with tools.environment_append(env): yield else: yield def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) self._autotools.libs = [] yes_no = lambda v: "yes" if v else "no" configure_args = [ "--enable-shared={}".format(yes_no(self.options.shared)), "--enable-cbc-parallel={}".format(yes_no(self.options.parallel)), "--without-blas", "--without-lapack", ] if self.settings.compiler == "Visual Studio": self._autotools.cxx_flags.append("-EHsc") configure_args.append("--enable-msvc={}".format( self.settings.compiler.runtime)) if tools.Version(self.settings.compiler.version) >= 12: self._autotools.flags.append("-FS") if self.options.parallel: configure_args.append("--with-pthreadsw32-lib={}".format( tools.unix_path( os.path.join( self.deps_cpp_info["pthreads4w"].lib_paths[0], self.deps_cpp_info["pthreads4w"].libs[0] + ".lib")))) configure_args.append("--with-pthreadsw32-incdir={}".format( tools.unix_path( self.deps_cpp_info["pthreads4w"].include_paths[0]))) self._autotools.configure(configure_dir=os.path.join( self.source_folder, self._source_subfolder), args=configure_args) return self._autotools def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB, os.path.join(self._source_subfolder, "config.sub")) shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS, os.path.join(self._source_subfolder, "config.guess")) with self._build_context(): autotools = self._configure_autotools() autotools.make() def package(self): self.copy("LICENSE", src=self._source_subfolder, dst="licenses") # Installation script expects include/coin to already exist tools.mkdir(os.path.join(self.package_folder, "include", "coin")) with self._build_context(): autotools = self._configure_autotools() autotools.install() for l in ("CbcSolver", "Cbc", "OsiCbc"): os.unlink( os.path.join(self.package_folder, "lib", "lib{}.la").format(l)) if self.settings.compiler == "Visual Studio": os.rename( os.path.join(self.package_folder, "lib", "lib{}.a").format(l), os.path.join(self.package_folder, "lib", "{}.lib").format(l)) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.rmdir(os.path.join(self.package_folder, "share")) def package_info(self): self.cpp_info.components["libcbc"].libs = ["CbcSolver", "Cbc"] self.cpp_info.components["libcbc"].includedirs.append( os.path.join("include", "coin")) self.cpp_info.components["libcbc"].requires = [ "coin-clp::osi-clp", "coin-utils::coin-utils", "coin-osi::coin-osi", "coin-cgl::coin-cgl" ] self.cpp_info.components["libcbc"].names["pkg_config"] = "cbc" if self.settings.os in ["Linux", "FreeBSD"] and self.options.parallel: self.cpp_info.components["libcbc"].system_libs.append("pthread") if self.settings.os in ["Windows"] and self.options.parallel: self.cpp_info.components["libcbc"].requires.append( "pthreads4w::pthreads4w") self.cpp_info.components["osi-cbc"].libs = ["OsiCbc"] self.cpp_info.components["osi-cbc"].requires = ["libcbc"] self.cpp_info.components["osi-cbc"].names["pkg_config"] = "osi-cbc" bin_path = os.path.join(self.package_folder, "bin") self.output.info( "Appending PATH environment variable: {}".format(bin_path)) self.env_info.PATH.append(bin_path)
class CunitConan(ConanFile): name = "cunit" description = "A Unit Testing Framework for C" topics = ("conan", "cunit", "testing") url = "https://github.com/conan-io/conan-center-index" homepage = "http://cunit.sourceforge.net/" license = "BSD-3-Clause" settings = "os", "compiler", "build_type", "arch" options = { "shared": [True, False], "fPIC": [True, False], "enable_automated": [True, False], "enable_basic": [True, False], "enable_console": [True, False], "with_curses": [False, "ncurses"], } default_options = { "shared": False, "fPIC": True, "enable_automated": True, "enable_basic": True, "enable_console": True, "with_curses": False, } exports_sources = "patches/**" _autotools = None @property def _source_subfolder(self): return "source_subfolder" def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): del self.settings.compiler.libcxx del self.settings.compiler.cppstd if self.options.shared: del self.options.fPIC def requirements(self): if self.options.with_curses == "ncurses": self.requires("ncurses/6.2") def build_requirements(self): if tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH") and \ tools.os_info.detect_windows_subsystem() != "msys2": self.build_requires("msys2/20190524") self.build_requires("libtool/2.4.6") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("CUnit-{}".format(self.version), self._source_subfolder) with tools.chdir(self._source_subfolder): for f in glob.glob("*.c"): os.chmod(f, 0o644) @contextmanager def _build_context(self): env = {} if self.settings.compiler == "Visual Studio": with tools.vcvars(self.settings): env.update({ "AR": "{} lib".format( tools.unix_path( self.deps_user_info["automake"].ar_lib)), "CC": "{} cl -nologo".format( tools.unix_path( self.deps_user_info["automake"].compile)), "CXX": "{} cl -nologo".format( tools.unix_path( self.deps_user_info["automake"].compile)), "NM": "dumpbin -symbols", "OBJDUMP": ":", "RANLIB": ":", "STRIP": ":", }) with tools.environment_append(env): yield else: with tools.environment_append(env): yield def _configure_autools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) self._autotools.libs = [] conf_args = [ "--datarootdir={}".format( os.path.join(self.package_folder, "bin", "share").replace("\\", "/")), "--enable-debug" if self.settings.build_type == "Debug" else "--disable-debug", "--enable-automated" if self.options.enable_automated else "--disable-automated", "--enable-basic" if self.options.enable_basic else "--disable-basic", "--enable-console" if self.options.enable_console else "--disable-console", "--enable-curses" if self.options.with_curses != False else "--disable-curses", ] if self.options.shared: conf_args.extend(["--enable-shared", "--disable-static"]) else: conf_args.extend(["--disable-shared", "--enable-static"]) self._autotools.configure(args=conf_args) return self._autotools def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) with self._build_context(): with tools.chdir(self._source_subfolder): self.run("autoreconf -fiv".format(os.environ["AUTORECONF"]), win_bash=tools.os_info.is_windows) autotools = self._configure_autools() autotools.make() def package(self): self.copy("COPYING", src=self._source_subfolder, dst="licenses") with self._build_context(): with tools.chdir(self._source_subfolder): autotools = self._configure_autools() autotools.install() os.unlink(os.path.join(self.package_folder, "lib", "libcunit.la")) tools.rmdir(os.path.join(self.package_folder, "bin", "share", "man")) tools.rmdir(os.path.join(self.package_folder, "doc")) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) def package_info(self): self.cpp_info.names["cmake_find_package"] = "CUnit" self.cpp_info.names["cmake_find_package_multi"] = "CUnit" libname = "cunit" if self.settings.os == "Windows" and self.options.shared: libname += ".dll" + (".lib" if self.settings.compiler == "Visual Studio" else ".a") self.cpp_info.libs = [libname] if self.settings.os == "Windows" and self.options.shared: self.cpp_info.defines.append("CU_DLL")
class GfCompleteConan(ConanFile): name = "gf-complete" description = "A library for Galois Field arithmetic" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/ceph/gf-complete" license = "BSD-3-Clause" topics = ("galois field", "math", "algorithms") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "neon": [True, False, "auto"], "sse": [True, False, "auto"], "avx": [True, False, "auto"] } default_options = { "shared": False, "fPIC": True, "neon": "auto", "sse": "auto", "avx": "auto" } _source_subfolder = "source_subfolder" _autotools = None def build_requirements(self): self.build_requires("libtool/2.4.6") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def config_options(self): if self.settings.os == 'Windows': del self.options.fPIC if self.settings.arch not in ["x86", "x86_64"]: del self.options.sse del self.options.avx if "arm" not in self.settings.arch: del self.options.neon def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd def validate(self): if self.settings.os == "Windows" and not self.settings.compiler == "gcc": # Building on Windows is currently only supported using the MSYS2 # subsystem. In theory, the gf-complete library can be build using # MSVC. However, some adjustments to the build-system are needed # and the CLI tools cannot be build. # # A suitable profile for MSYS2 can be found in the documentation: # https://github.com/conan-io/docs/blob/b712aa7c0dc99607c46c57585787ced2ae66ac33/systems_cross_building/windows_subsystems.rst raise ConanInvalidConfiguration( "Windows is only supported using the MSYS2 subsystem") def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=bool(self.settings.os == "Windows")) with tools.environment_append(self._autotools.vars): with tools.chdir(self._source_subfolder): self.run("./autogen.sh", win_bash=bool(self.settings.os == "Windows")) if "x86" in self.settings.arch: self._autotools.flags.append('-mstackrealign') configure_args = [ "--enable-shared=%s" % ("yes" if self.options.shared else "no"), "--enable-static=%s" % ("no" if self.options.shared else "yes") ] if "arm" in self.settings.arch: if self.options.neon != "auto": configure_args.append("--{}-neon".format( "enable" if self.options.neon else "disable")) if self.settings.arch in ["x86", "x86_64"]: if self.options.sse != "auto": configure_args.append("--{}-sse".format( "enable" if self.options.sse else "disable")) if self.options.avx != "auto": configure_args.append("--{}-avx".format( "enable" if self.options.avx else "disable")) self._autotools.configure(args=configure_args, configure_dir=self._source_subfolder) return self._autotools def build(self): autotools = self._configure_autotools() autotools.make() def package(self): self.copy("COPYING", dst="licenses", src=self._source_subfolder) autotools = self._configure_autotools() autotools.install() # don't package la file la_file = os.path.join(self.package_folder, "lib", "libgf_complete.la") if os.path.isfile(la_file): os.unlink(la_file) def package_info(self): self.cpp_info.libs = tools.collect_libs(self)
def build_autotools(self): prefix = os.path.abspath(self.package_folder) win_bash = False rc = None host = None build = None if self.is_mingw or self.is_msvc: prefix = prefix.replace('\\', '/') win_bash = True build = False if self.settings.arch == "x86": host = "i686-w64-mingw32" rc = "windres --target=pe-i386" elif self.settings.arch == "x86_64": host = "x86_64-w64-mingw32" rc = "windres --target=pe-x86-64" # # If you pass --build when building for iPhoneSimulator, the configure script halts. # So, disable passing --build by setting it to False. # if self.settings.os == "iOS" and self.settings.arch == "x86_64": build = False env_build = AutoToolsBuildEnvironment(self, win_bash=win_bash) if self.settings.os != "Windows": env_build.fpic = self.options.fPIC configure_args = ['--prefix=%s' % prefix] if self.options.shared: configure_args.extend(['--disable-static', '--enable-shared']) else: configure_args.extend(['--enable-static', '--disable-shared']) env_vars = {} if self.is_mingw: configure_args.extend([ 'CPPFLAGS=-I%s/include' % prefix, 'LDFLAGS=-L%s/lib' % prefix, 'RANLIB=:' ]) if self.is_msvc: runtime = str(self.settings.compiler.runtime) configure_args.extend([ 'CC=$PWD/build-aux/compile cl -nologo', 'CFLAGS=-%s' % runtime, 'CXX=$PWD/build-aux/compile cl -nologo', 'CXXFLAGS=-%s' % runtime, 'CPPFLAGS=-D_WIN32_WINNT=0x0600 -I%s/include' % prefix, 'LDFLAGS=-L%s/lib' % prefix, 'LD=link', 'NM=dumpbin -symbols', 'STRIP=:', 'AR=$PWD/build-aux/ar-lib lib', 'RANLIB=:' ]) env_vars['win32_target'] = '_WIN32_WINNT_VISTA' with tools.chdir(self.archive_name): tools.run_in_windows_bash( self, 'chmod +x build-aux/ar-lib build-aux/compile') if rc: configure_args.extend(['RC=%s' % rc, 'WINDRES=%s' % rc]) with tools.chdir(self.archive_name): with tools.environment_append(env_vars): env_build.configure(args=configure_args, host=host, build=build) env_build.make() env_build.make(args=["install"])
class LibIdn(ConanFile): name = "libidn2" description = "GNU Libidn is a fully documented implementation of the Stringprep, Punycode and IDNA 2003 specifications." homepage = "https://www.gnu.org/software/libidn/" topics = ("conan", "libidn", "encode", "decode", "internationalized", "domain", "name") license = "GPL-3.0-or-later" url = "https://github.com/conan-io/conan-center-index" options = { "shared": [True, False], "fPIC": [True, False], } default_options = { "shared": False, "fPIC": True, } settings = "os", "arch", "compiler", "build_type" exports_sources = "patches/**" _autotools = None @property def _source_subfolder(self): return "source_subfolder" def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: del self.options.fPIC if self.settings.os == "Windows" and self.options.shared: raise ConanInvalidConfiguration( "Shared libraries are not supported on Windows due to libtool limitation" ) del self.settings.compiler.libcxx del self.settings.compiler.cppstd def requirements(self): self.requires("libiconv/1.16") def build_requirements(self): if tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH"): self.build_requires("msys2/20200517") if self.settings.compiler == "Visual Studio": self.build_requires("automake/1.16.2") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("libidn2-{}".format(self.version), self._source_subfolder) @contextmanager def _build_context(self): if self.settings.compiler == "Visual Studio": with tools.vcvars(self.settings): env = { "CC": "{} cl -nologo".format( tools.unix_path( self.deps_user_info["automake"].compile)), "CXX": "{} cl -nologo".format( tools.unix_path( self.deps_user_info["automake"].compile)), "LD": "{} link -nologo".format( tools.unix_path( self.deps_user_info["automake"].compile)), "AR": "{} lib".format( tools.unix_path( self.deps_user_info["automake"].ar_lib)), } with tools.environment_append(env): yield else: yield def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) self._autotools.libs = [] if not self.options.shared: self._autotools.defines.append("IDN2_STATIC") if self.settings.compiler == "Visual Studio": self._autotools.flags.append("-FS") self._autotools.link_flags.extend( "-L{}".format(p.replace("\\", "/")) for p in self.deps_cpp_info.lib_paths) yes_no = lambda v: "yes" if v else "no" conf_args = [ "--enable-shared={}".format(yes_no(self.options.shared)), "--enable-static={}".format(yes_no(not self.options.shared)), "--with-libiconv-prefix={}".format( tools.unix_path(self.deps_cpp_info["libiconv"].rootpath)), "--disable-nls", "--disable-rpath", ] self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder) return self._autotools def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) with self._build_context(): autotools = self._configure_autotools() autotools.make() def package(self): self.copy("COPYING", src=self._source_subfolder, dst="licenses") with self._build_context(): autotools = self._configure_autotools() autotools.install() os.unlink(os.path.join(self.package_folder, "lib", "libidn2.la")) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.rmdir(os.path.join(self.package_folder, "share")) def package_info(self): libname = "idn2" if self.options.shared and self.settings.os == "Windows": libname += ".dll" + (".lib" if self.settings.compiler == "Visual Studio" else ".a") self.cpp_info.libs = [libname] self.cpp_info.names["pkg_config"] = "libidn2" if self.settings.os == "Windows": if not self.options.shared: self.cpp_info.defines = ["IDN2_STATIC"] bin_path = os.path.join(self.package_folder, "bin") self.output.info( "Appending PATH environment variable: {}".format(bin_path)) self.env_info.PATH.append(bin_path)
class LibDaemonConan(ConanFile): name = "libdaemon" description = "a lightweight C library that eases the writing of UNIX daemons" topics = ("daemon") url = "https://github.com/conan-io/conan-center-index" homepage = "http://0pointer.de/lennart/projects/libdaemon/" license = "LGPL-2.1-or-later" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False] } default_options = { "shared": False, "fPIC": True } _autotools = None @property def _source_subfolder(self): return "source_subfolder" @property def _settings_build(self): return getattr(self, "settings_build", self.settings) @property def _user_info_build(self): return getattr(self, "user_info_build", self.deps_user_info) def configure(self): del self.settings.compiler.cppstd del self.settings.compiler.libcxx if self.options.shared: del self.options.fPIC def validate(self): if self.settings.compiler == "Visual Studio": raise ConanInvalidConfiguration("Visual Studio not supported") def build_requirements(self): self.build_requires("gnu-config/cci.20201022") if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) yes_no = lambda v: "yes" if v else "no" args = [ "--enable-shared={}".format(yes_no(self.options.shared)), "--enable-static={}".format(yes_no(not self.options.shared)), "--disable-examples", ] if tools.cross_building(self): args.append("ac_cv_func_setpgrp_void=yes") self._autotools.configure(configure_dir=self._source_subfolder, args=args) return self._autotools def build(self): shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB, os.path.join(self._source_subfolder, "config.sub")) shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS, os.path.join(self._source_subfolder, "config.guess")) autotools = self._configure_autotools() autotools.make() def package(self): autotools = self._configure_autotools() autotools.install() self.copy("LICENSE", dst="licenses", src=self._source_subfolder) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") tools.rmdir(os.path.join(self.package_folder, "share")) def package_info(self): self.cpp_info.names["pkg_config"] = "libdaemon" self.cpp_info.libs = ["daemon"]
class LibX264Conan(ConanFile): name = "libx264" url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.videolan.org/developers/x264.html" description = "x264 is a free software library and application for encoding video streams into the " \ "H.264/MPEG-4 AVC compression format" topics = ("conan", "libx264", "video", "encoding") license = "GPL-2.0" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "bit_depth": [8, 10, "all"], } default_options = { "shared": False, "fPIC": True, "bit_depth": "all", } _autotools = None _override_env = {} @property def _is_msvc(self): return self.settings.compiler == "Visual Studio" @property def _source_subfolder(self): return "source_subfolder" @property def _settings_build(self): return getattr(self, "settings_build", self.settings) def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd @property def _with_nasm(self): return self.settings.arch in ("x86", "x86_64") def build_requirements(self): if self._with_nasm: self.build_requires("nasm/2.15.05") if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) @contextlib.contextmanager def _build_context(self): with tools.vcvars(self) if self._is_msvc else tools.no_op(): yield @property def env(self): ret = super(LibX264Conan, self).env ret.update(self._override_env) return ret def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) args = [ "--bit-depth=%s" % str(self.options.bit_depth), "--disable-cli", "--prefix={}".format(tools.unix_path(self.package_folder)), ] if self.options.shared: args.append("--enable-shared") else: args.append("--enable-static") if self.options.get_safe("fPIC", self.settings.os != "Windows"): args.append("--enable-pic") if self.settings.build_type == "Debug": args.append("--enable-debug") if self.settings.os == "Macos" and self.settings.arch == "armv8": # bitstream-a.S:29:18: error: unknown token in expression args.append("--extra-asflags=-arch arm64") args.append("--extra-ldflags=-arch arm64") if self._with_nasm: # FIXME: get using user_build_info self._override_env["AS"] = os.path.join(self.deps_cpp_info["nasm"].rootpath, "bin", "nasm{}".format(".exe" if tools.os_info.is_windows else "")).replace("\\", "/") if tools.cross_building(self): if self.settings.os == "Android": # the as of ndk does not work well for building libx264 self._override_env["AS"] = os.environ["CC"] ndk_root = tools.unix_path(os.environ["NDK_ROOT"]) arch = { "armv7": "arm", "armv8": "aarch64", "x86": "i686", "x86_64": "x86_64", }.get(str(self.settings.arch)) abi = "androideabi" if self.settings.arch == "armv7" else "android" args.append("--cross-prefix={}".format("{}/bin/{}-linux-{}-".format(ndk_root, arch, abi))) if self._is_msvc: self._override_env["CC"] = "cl -nologo" self._autotools.flags.append("-%s" % str(self.settings.compiler.runtime)) # cannot open program database ... if multiple CL.EXE write to the same .PDB file, please use /FS self._autotools.flags.append("-FS") build_canonical_name = None host_canonical_name = None if self._is_msvc: # autotools does not know about the msvc canonical name(s) build_canonical_name = False host_canonical_name = False self._autotools.configure(args=args, vars=self._override_env, configure_dir=self._source_subfolder, build=build_canonical_name, host=host_canonical_name) return self._autotools def build(self): with self._build_context(): autotools = self._configure_autotools() autotools.make() def package(self): self.copy(pattern="COPYING", src=self._source_subfolder, dst="licenses") with self._build_context(): autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) if self._is_msvc: ext = ".dll.lib" if self.options.shared else ".lib" tools.rename(os.path.join(self.package_folder, "lib", "libx264{}".format(ext)), os.path.join(self.package_folder, "lib", "x264.lib")) def package_info(self): self.cpp_info.libs = ["x264"] if self._is_msvc and self.options.shared: self.cpp_info.defines.append("X264_API_IMPORTS") if self.settings.os in ("FreeBSD", "Linux"): self.cpp_info.system_libs.extend(["dl", "pthread", "m"]) elif self.settings.os == "Android": self.cpp_info.system_libs.extend(["dl", "m"]) self.cpp_info.names["pkg_config"] = "x264"
class LibffiConan(ConanFile): name = "libffi" description = "A portable, high level programming interface to various calling conventions" topics = ("libffi", "runtime", "foreign-function-interface", "runtime-library") url = "https://github.com/conan-io/conan-center-index" homepage = "https://sourceware.org/libffi/" license = "MIT" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], } default_options = { "shared": False, "fPIC": True, } _autotools = None @property def _source_subfolder(self): return "source_subfolder" @property def _is_msvc(self): return str(self.settings.compiler) in ["Visual Studio", "msvc"] @property def _settings_build(self): return getattr(self, "settings_build", self.settings) @property def _user_info_build(self): return getattr(self, "user_info_build", self.deps_user_info) def export_sources(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): self.copy(patch["patch_file"]) def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd def build_requirements(self): if self._settings_build.os == "Windows" and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") self.build_requires("gnu-config/cci.20201022") def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def _patch_sources(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) # Generate rpath friendly shared lib on macOS configure_path = os.path.join(self._source_subfolder, "configure") tools.replace_in_file(configure_path, "-install_name \\$rpath/", "-install_name @rpath/") if tools.Version(self.version) < "3.3": if self.settings.compiler == "clang" and tools.Version( str(self.settings.compiler.version)) >= 7.0: # https://android.googlesource.com/platform/external/libffi/+/ca22c3cb49a8cca299828c5ffad6fcfa76fdfa77 sysv_s_src = os.path.join(self._source_subfolder, "src", "arm", "sysv.S") tools.replace_in_file(sysv_s_src, "fldmiad", "vldmia") tools.replace_in_file(sysv_s_src, "fstmiad", "vstmia") tools.replace_in_file(sysv_s_src, "fstmfdd\tsp!,", "vpush") # https://android.googlesource.com/platform/external/libffi/+/7748bd0e4a8f7d7c67b2867a3afdd92420e95a9f tools.replace_in_file(sysv_s_src, "stmeqia", "stmiaeq") @contextlib.contextmanager def _build_context(self): extra_env_vars = {} if tools.os_info.is_windows and (self._is_msvc or self.settings.compiler == "clang"): msvcc = tools.unix_path( os.path.join(self.source_folder, self._source_subfolder, "msvcc.sh")) msvcc_args = [] if self._is_msvc: if self.settings.arch == "x86_64": msvcc_args.append("-m64") elif self.settings.arch == "x86": msvcc_args.append("-m32") elif self.settings.compiler == "clang": msvcc_args.append("-clang-cl") if msvcc_args: msvcc = "{} {}".format(msvcc, " ".join(msvcc_args)) extra_env_vars.update(tools.vcvars_dict(self.settings)) extra_env_vars.update({ "INSTALL": tools.unix_path( os.path.join(self.source_folder, self._source_subfolder, "install-sh")), "LIBTOOL": tools.unix_path( os.path.join(self.source_folder, self._source_subfolder, "ltmain.sh")), "CC": msvcc, "CXX": msvcc, "LD": "link", "CPP": "cl -nologo -EP", "CXXCPP": "cl -nologo -EP", }) with tools.environment_append(extra_env_vars): yield def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) yes_no = lambda v: "yes" if v else "no" config_args = [ "--enable-debug={}".format( yes_no(self.settings.build_type == "Debug")), "--enable-shared={}".format(yes_no(self.options.shared)), "--enable-static={}".format(yes_no(not self.options.shared)), ] self._autotools.defines.append("FFI_BUILDING") if self.options.shared: self._autotools.defines.append("FFI_BUILDING_DLL") if self._is_msvc: if "MT" in msvc_runtime_flag(self): self._autotools.defines.append("USE_STATIC_RTL") if "d" in msvc_runtime_flag(self): self._autotools.defines.append("USE_DEBUG_RTL") build = None host = None if self._is_msvc: build = "{}-{}-{}".format( "x86_64" if self._settings_build.arch == "x86_64" else "i686", "pc" if self._settings_build.arch == "x86" else "w64", "cygwin") host = "{}-{}-{}".format( "x86_64" if self.settings.arch == "x86_64" else "i686", "pc" if self.settings.arch == "x86" else "w64", "cygwin") else: if self._autotools.host and "x86-" in self._autotools.host: self._autotools.host = self._autotools.host.replace( "x86", "i686") self._autotools.configure(args=config_args, configure_dir=self._source_subfolder, build=build, host=host) return self._autotools def build(self): self._patch_sources() shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB, os.path.join(self._source_subfolder, "config.sub")) shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS, os.path.join(self._source_subfolder, "config.guess")) with self._build_context(): autotools = self._configure_autotools() autotools.make() if tools.get_env("CONAN_RUN_TESTS", False): autotools.make(target="check") def package(self): self.copy("LICENSE", src=self._source_subfolder, dst="licenses") if self._is_msvc: if self.options.shared: self.copy("libffi.dll", src=".libs", dst="bin") self.copy("libffi.lib", src=".libs", dst="lib") self.copy("*.h", src="include", dst="include") else: with self._build_context(): autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.rmdir(os.path.join(self.package_folder, "share")) tools.remove_files_by_mask( os.path.join(self.package_folder, "lib"), "*.la") def package_info(self): self.cpp_info.set_property("pkg_config_name", "libffi") self.cpp_info.libs = ["{}ffi".format("lib" if self._is_msvc else "")] if not self.options.shared: self.cpp_info.defines = ["FFI_BUILDING"]
def build(self): env_build = AutoToolsBuildEnvironment(self) env_build.configure(configure_dir="cmake-3.10.2",args=[ '--prefix=`pwd`/build' ]) env_build.make()
class Nanos5Conan(ConanFile): name = "nanos5_internal" version = "2.2.0" git_clone_name = "nanos5_source" git_url = "https://gitlab.bsc.es/ompss-at-fpga/nanox" settings = "os", "compiler", "build_type", "arch" requires = ["xtasks/2.2.0-stub", "extrae/2.2.0"] build_policy="missing" _autotools = None def source(self): self.run("git clone -b ompss-at-fpga-release/2.2.0 {0} {1}".format(self.git_url, self.git_clone_name)) @property def _datarootdir(self): return os.path.join(self.package_folder, "bin", "share") def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) args =[ "--datarootdir={}".format(tools.unix_path(self._datarootdir)), "--prefix={}".format(tools.unix_path(self.package_folder)), '--with-xtasks=%s' % self.deps_cpp_info["xtasks"].rootpath, '--with-extrae={}'.format(self.deps_cpp_info["extrae"].rootpath) ] self._autotools.cxx_flags.append("-Wno-unused-variable") if(str(self.settings.arch) == platform.machine()): self._autotools.configure(args=args, configure_dir=self.source_folder+"/%s"%self.git_clone_name, host=False, build=False, target=False) else: self._autotools.configure(args=args, configure_dir=self.source_folder+"/%s"%self.git_clone_name) return self._autotools def build(self): if "PKGM4" in os.environ: self.run("cd {0}/{1} && autoreconf -fiv -I{2}".format(self.build_folder, self.git_clone_name, os.environ["PKGM4"])) else: self.run("cd {0}/{1} && autoreconf -fiv".format(self.build_folder, self.git_clone_name)) autotools = self._configure_autotools() autotools.make() def package(self): autotools = self._configure_autotools() autotools.install() self.run("cd {} && rm -rf *.la".format(self.package_folder+"/lib/debug")) self.run("cd {} && rm -rf *.la".format(self.package_folder+"/lib/performance")) self.run("cd {} && rm -rf *.la".format(self.package_folder+"/lib/instrumentation")) def getRunPath(self, file): command = "readelf -d {} | grep runpath || true ".format(file) uname = subprocess.check_output(command, shell=True).decode() prog = re.compile("(?<=\\[).+?(?=\\])") result = prog.search(uname) if result == None: return "" return result.group(0) def patchRunPath(self, file): home_dir = str(subprocess.check_output("conan config home", shell=True)).replace(".conan","").replace("b'","").replace("\\n'","").replace("/","\\/") rpath = self.getRunPath(file) if rpath == "": return old_home_dir = rpath[:rpath.find(".conan")] modified_rpath = rpath.replace(old_home_dir,home_dir) self.run("patchelf --set-rpath {} {}".format(modified_rpath, file)) def patchAllInFolder(self, directory): for filename in os.listdir(directory): if filename.endswith(".so"): self.patchRunPath(os.path.join(directory, filename)) else: continue def package_info(self): self.cpp_info.libs = [] # not propagate linking... self.cpp_info.system_libs = [] # System libs to link again self.cpp_info.sharedlinkflags = [] self.cpp_info.exelinkflags = [] self.env_info.NANOS6_INCLUDE=self.package_folder+"/include" self.env_info.NANOS6_HOME= self.package_folder self.env_info.NANOS6_LIBS=self.package_folder+"/lib" self.env_info.LD_LIBRARY_PATH.append(self.package_folder+"/lib") self.patchAllInFolder(self.package_folder+"/lib/debug") self.patchAllInFolder(self.package_folder+"/lib/performance") self.patchAllInFolder(self.package_folder+"/lib/instrumentation")