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))
def build(self): autoTools = AutoToolsBuildEnvironment(self) autoTools.configure(configure_dir=os.path.join(self.source_folder, self._source_subfolder)) autoTools.make()
class Libxml2Conan(ConanFile): name = "libxml2" url = "https://github.com/conan-io/conan-center-index" description = "libxml2 is a software library for parsing XML documents" topics = ("XML", "parser", "validation") homepage = "https://xmlsoft.org" license = "MIT" settings = "os", "arch", "compiler", "build_type" generators = "pkg_config" # from ./configure and ./win32/configure.js default_options = { 'shared': False, 'fPIC': True, 'include_utils': True, "c14n": True, "catalog": True, "docbook": True, "ftp": True, "http": True, "html": True, "iconv": True, "icu": False, "iso8859x": True, "legacy": True, "mem-debug": False, "output": True, "pattern": True, "push": True, "python": False, "reader": True, "regexps": True, "run-debug": False, "sax1": True, "schemas": True, "schematron": True, "threads": True, "tree": True, "valid": True, "writer": True, "xinclude": True, "xpath": True, "xptr": True, "zlib": True, "lzma": False, } options = {name: [True, False] for name in default_options.keys()} _option_names = [ name for name in default_options.keys() if name not in ["shared", "fPIC", "include_utils"] ] _autotools = None _source_subfolder = "source_subfolder" def requirements(self): if self.options.zlib: self.requires("zlib/1.2.11") if self.options.lzma: self.requires("xz_utils/5.2.5") if self.options.iconv: self.requires("libiconv/1.16") if self.options.icu: self.requires("icu/68.1") def build_requirements(self): if self.settings.compiler != "Visual Studio" and tools.os_info.is_windows and os.environ.get( "CONAN_BASH_PATH", None) is None: self.build_requires("msys2/20190524") @property def _is_msvc(self): return self.settings.compiler == 'Visual Studio' @property def _is_mingw(self): return self.settings.compiler == 'gcc' and self.settings.os == 'Windows' def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("libxml2-{0}".format(self.version), self._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 @contextmanager def _msvc_build_environment(self): with tools.chdir(os.path.join(self._source_subfolder, 'win32')): with tools.vcvars(self.settings): with tools.environment_append( VisualStudioBuildEnvironment(self).vars): yield def _build_msvc(self): with self._msvc_build_environment(): debug = "yes" if self.settings.build_type == "Debug" else "no" static = "no" if self.options.shared else "yes" args = [ "cscript", "configure.js", "compiler=msvc", "prefix=%s" % self.package_folder, "cruntime=/%s" % self.settings.compiler.runtime, "debug=%s" % debug, "static=%s" % static, 'include="%s"' % ";".join(self.deps_cpp_info.include_paths), 'lib="%s"' % ";".join(self.deps_cpp_info.lib_paths) ] for name in self._option_names: cname = { "mem-debug": "mem_debug", "run-debug": "run_debug", "docbook": "docb" }.get(name, name) value = getattr(self.options, name) value = "yes" if value else "no" args.append("%s=%s" % (cname, value)) configure_command = ' '.join(args) self.output.info(configure_command) self.run(configure_command) # Fix library names because they can be not just zlib.lib def fix_library(option, package, old_libname): if option: libs = [] for lib in self.deps_cpp_info[package].libs: libname = lib if not libname.endswith('.lib'): libname += '.lib' libs.append(libname) tools.replace_in_file("Makefile.msvc", "LIBS = $(LIBS) %s" % old_libname, "LIBS = $(LIBS) %s" % ' '.join(libs)) fix_library(self.options.zlib, 'zlib', 'zlib.lib') fix_library(self.options.lzma, 'lzma', 'liblzma.lib') fix_library(self.options.iconv, 'libiconv', 'iconv.lib') fix_library(self.options.icu, 'icu', 'advapi32.lib sicuuc.lib sicuin.lib sicudt.lib') fix_library(self.options.icu, 'icu', 'icuuc.lib icuin.lib icudt.lib') self.run("nmake /f Makefile.msvc libxml libxmla libxmladll") if self.options.include_utils: self.run("nmake /f Makefile.msvc utils") def _package_msvc(self): with self._msvc_build_environment(): self.run("nmake /f Makefile.msvc install-libs") if self.options.include_utils: self.run("nmake /f Makefile.msvc install-dist") 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 tools.os_info.is_windows: self._autotools.fpic = self.options.fPIC full_install_subfolder = tools.unix_path( self.package_folder ) if tools.os_info.is_windows else self.package_folder # fix rpath if self.settings.os == "Macos": tools.replace_in_file( os.path.join(self._source_subfolder, "configure"), r"-install_name \$rpath/", "-install_name ") configure_args = ['--prefix=%s' % full_install_subfolder] if self._autotools.fpic: configure_args.extend(['--with-pic']) if self.options.shared: configure_args.extend(['--enable-shared', '--disable-static']) else: configure_args.extend(['--enable-static', '--disable-shared']) for name in self._option_names: value = getattr(self.options, name) value = ("--with-%s" % name) if value else ("--without-%s" % name) configure_args.append(value) # Disable --build when building for iPhoneSimulator. The configure script halts on # not knowing if it should cross-compile. build = None if self.settings.os == "iOS" and self.settings.arch == "x86_64": build = False self._autotools.configure(args=configure_args, build=build, configure_dir=self._source_subfolder) return self._autotools def _patch_sources(self): # Break dependency of install on build for makefile in ("Makefile.mingw", "Makefile.msvc"): tools.replace_in_file( os.path.join(self._source_subfolder, "win32", makefile), "install-libs : all", "install-libs :") def build(self): self._patch_sources() if self._is_msvc: self._build_msvc() else: autotools = self._configure_autotools() autotools.make(["libxml2.la"]) if self.options.include_utils: autotools.make(["xmllint", "xmlcatalog", "xml2-config"]) def package(self): # copy package license self.copy("COPYING", src=self._source_subfolder, dst="licenses", ignore_case=True, keep_path=False) if self._is_msvc: self._package_msvc() else: autotools = self._configure_autotools() autotools.make(["install-libLTLIBRARIES", "install-data"]) if self.options.include_utils: autotools.make( ["install", "xmllint", "xmlcatalog", "xml2-config"]) os.unlink(os.path.join(self.package_folder, 'lib', 'libxml2.la')) for prefix in ["run", "test"]: for test in glob.glob("%s/bin/%s*" % (self.package_folder, prefix)): os.remove(test) for header in ["win32config.h", "wsockcompat.h"]: self.copy(pattern=header, src=os.path.join(self._source_subfolder, "include"), dst=os.path.join("include", "libxml2"), keep_path=False) if self._is_msvc: # remove redundant libraries to avoid confusion if not self.options.shared: os.unlink( os.path.join(self.package_folder, "bin", "libxml2.dll")) os.unlink( os.path.join(self.package_folder, 'lib', 'libxml2_a_dll.lib')) os.unlink( os.path.join( self.package_folder, 'lib', 'libxml2_a.lib' if self.options.shared else 'libxml2.lib')) pdb_files = glob.glob(os.path.join(self.package_folder, 'bin', '*.pdb'), recursive=True) for pdb in pdb_files: os.unlink(pdb) tools.rmdir(os.path.join(self.package_folder, 'share')) tools.rmdir(os.path.join(self.package_folder, 'lib', 'cmake')) tools.rmdir(os.path.join(self.package_folder, 'lib', 'pkgconfig')) def package_info(self): if self._is_msvc: self.cpp_info.libs = [ 'libxml2' if self.options.shared else 'libxml2_a' ] else: self.cpp_info.libs = ['xml2'] self.cpp_info.includedirs.append(os.path.join("include", "libxml2")) if not self.options.shared: self.cpp_info.defines = ["LIBXML_STATIC"] if self.options.include_utils: bindir = os.path.join(self.package_folder, "bin") self.output.info( "Appending PATH environment variable: {}".format(bindir)) self.env_info.PATH.append(bindir) if self.settings.os in ["Linux", "Macos", "FreeBSD"]: self.cpp_info.system_libs.append('m') if self.settings.os == "Windows": self.cpp_info.system_libs.append('ws2_32') self.cpp_info.names["cmake_find_package"] = "LibXml2" self.cpp_info.names["cmake_find_package_multi"] = "LibXml2" self.cpp_info.names["pkg_config"] = "libxml-2.0"
def build_make(self): with tools.chdir(self.source_subfolder): autotools = AutoToolsBuildEnvironment(self) autotools.configure() autotools.make()
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 = ("autoconf", "configure", "build") license = ("GPL-2.0-or-later", "GPL-3.0-or-later") settings = "os", "arch", "compiler", "build_type" exports_sources = "patches/*" _autotools = None @property def _source_subfolder(self): return os.path.join(self.source_folder, "source_subfolder") @property def _settings_build(self): return getattr(self, "settings_build", self.settings) def requirements(self): self.requires("m4/1.4.19") def build_requirements(self): if hasattr(self, "settings_build"): self.build_requires("m4/1.4.19") if self._settings_build.os == "Windows" and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") def package_id(self): self.info.header_only() 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, "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.get("patches", {}).get(self.version, []): tools.patch(**patch) @contextlib.contextmanager def _build_context(self): with tools.environment_append(tools.RunEnvironment(self).vars): yield def build(self): self._patch_files() 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() tools.rmdir(os.path.join(self.package_folder, "bin", "share", "info")) tools.rmdir(os.path.join(self.package_folder, "bin", "share", "man")) def package_info(self): self.cpp_info.libdirs = [] self.cpp_info.includedirs = [] 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 = tools.unix_path( os.path.join(self.package_folder, "bin", "autoconf")) self.output.info("Setting AUTOCONF to {}".format(autoconf)) self.env_info.AUTOCONF = autoconf autoreconf = tools.unix_path( os.path.join(self.package_folder, "bin", "autoreconf")) self.output.info("Setting AUTORECONF to {}".format(autoreconf)) self.env_info.AUTORECONF = autoreconf autoheader = tools.unix_path( os.path.join(self.package_folder, "bin", "autoheader")) self.output.info("Setting AUTOHEADER to {}".format(autoheader)) self.env_info.AUTOHEADER = autoheader autom4te = tools.unix_path( os.path.join(self.package_folder, "bin", "autom4te")) 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 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], "postproc": [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_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], } default_options = { "shared": False, "fPIC": True, "postproc": 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_xcb": True, "with_appkit": True, "with_avfoundation": True, "with_coreimage": True, "with_audiotoolbox": True, "with_videotoolbox": True, "with_programs": True, } generators = "pkg_config" _autotools = None @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 if not self.settings.os in ["Linux", "FreeBSD"]: del self.options.with_vaapi del self.options.with_vdpau 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 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.11") 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.0") 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.16") 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.10.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.1") if self.options.with_ssl == "openssl": self.requires("openssl/1.1.1l") 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") 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") 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): _, _, 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.settings.compiler == "Visual Studio" 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.settings.compiler == "Visual Studio": 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 = [] opt_enable_disable = lambda what, v: "--{}-{}".format( "enable" if v else "disable", 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)), opt_enable_disable("postproc", self.options.postproc), # 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), opt_enable_disable( "gpl", self.options.with_libx264 or self.options.with_libx265 or self.options.postproc) ] 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.settings.compiler == "Visual Studio": args.append("--pkg-config={}".format(tools.get_env("PKG_CONFIG"))) args.append("--toolchain=msvc") if tools.Version(str(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): 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 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.settings.compiler == "Visual Studio": 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"): tools.rename( 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"): tools.rename(lib, lib[3:-2] + ".lib") def _read_component_version(self, component_name): result = dict() 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): self.cpp_info.components["avdevice"].libs = ["avdevice"] self.cpp_info.components["avdevice"].requires = [ "avfilter", "swscale", "avformat", "avcodec", "swresample", "avutil" ] self.cpp_info.components["avdevice"].names[ "pkg_config"] = "libavdevice" self._set_component_version("avdevice") self.cpp_info.components["avfilter"].libs = ["avfilter"] self.cpp_info.components["avfilter"].requires = [ "swscale", "avformat", "avcodec", "swresample", "avutil" ] self.cpp_info.components["avfilter"].names[ "pkg_config"] = "libavfilter" self._set_component_version("avfilter") self.cpp_info.components["avformat"].libs = ["avformat"] self.cpp_info.components["avformat"].requires = [ "avcodec", "swresample", "avutil" ] self.cpp_info.components["avformat"].names[ "pkg_config"] = "libavformat" self._set_component_version("avformat") self.cpp_info.components["avcodec"].libs = ["avcodec"] self.cpp_info.components["avcodec"].requires = ["swresample", "avutil"] self.cpp_info.components["avcodec"].names["pkg_config"] = "libavcodec" self._set_component_version("avcodec") self.cpp_info.components["swscale"].libs = ["swscale"] self.cpp_info.components["swscale"].requires = ["avutil"] self.cpp_info.components["swscale"].names["pkg_config"] = "libswscale" self._set_component_version("swscale") self.cpp_info.components["swresample"].libs = ["swresample"] self.cpp_info.components["swresample"].names[ "pkg_config"] = "libswresample" self.cpp_info.components["swresample"].requires = ["avutil"] self._set_component_version("swresample") if self.options.postproc: self.cpp_info.components["postproc"].libs = ["postproc"] self.cpp_info.components["postproc"].requires = ["avutil"] self.cpp_info.components["postproc"].names[ "pkg_config"] = "libpostproc" self._set_component_version("postproc") self.cpp_info.components["avfilter"].requires.append("postproc") self.cpp_info.components["avdevice"].requires.append("postproc") self.cpp_info.components["avutil"].libs = ["avutil"] self.cpp_info.components["avutil"].names["pkg_config"] = "libavutil" self._set_component_version("avutil") if self.settings.os in ("FreeBSD", "Linux"): self.cpp_info.components["avutil"].system_libs = [ "pthread", "m", "dl" ] self.cpp_info.components["swresample"].system_libs = ["m"] 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", ): # 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") self.cpp_info.components["avformat"].system_libs = ["m"] self.cpp_info.components["avfilter"].system_libs = ["m", "pthread"] self.cpp_info.components["avdevice"].system_libs = ["m"] elif self.settings.os == "Windows": self.cpp_info.components["avcodec"].system_libs = [ "Mfplat", "Mfuuid" ] self.cpp_info.components["avdevice"].system_libs = [ "ole32", "psapi", "strmiids", "uuid", "oleaut32", "shlwapi", "gdi32", "vfw32" ] self.cpp_info.components["avutil"].system_libs = [ "user32", "bcrypt" ] elif tools.is_apple_os(self.settings.os): self.cpp_info.components["avdevice"].frameworks = [ "CoreFoundation", "Foundation", "CoreGraphics" ] self.cpp_info.components["avfilter"].frameworks = ["CoreGraphics"] self.cpp_info.components["avcodec"].frameworks = [ "CoreVideo", "CoreMedia" ] if self.settings.os == "Macos": self.cpp_info.components["avdevice"].frameworks.append( "OpenGL") self.cpp_info.components["avfilter"].frameworks.append( "OpenGL") 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.with_zlib: self.cpp_info.components["avcodec"].requires.append("zlib::zlib") if self.options.with_bzip2: self.cpp_info.components["avformat"].requires.append( "bzip2::bzip2") 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_freetype: self.cpp_info.components["avfilter"].requires.append( "freetype::freetype") 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.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.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.options.get_safe("with_appkit"): self.cpp_info.components["avdevice"].frameworks.append("AppKit") self.cpp_info.components["avfilter"].frameworks.append("AppKit") if self.options.get_safe("with_avfoundation"): self.cpp_info.components["avdevice"].frameworks.append( "AVFoundation") if self.options.get_safe("with_coreimage"): self.cpp_info.components["avfilter"].frameworks.append("CoreImage") if self.options.get_safe("with_audiotoolbox"): self.cpp_info.components["avcodec"].frameworks.append( "AudioToolbox") self.cpp_info.components["avdevice"].frameworks.append("CoreAudio") if self.options.get_safe("with_videotoolbox"): self.cpp_info.components["avcodec"].frameworks.append( "VideoToolbox")
class NCursesConan(ConanFile): name = "ncurses" description = "The ncurses (new curses) library is a free software emulation of curses in System V Release 4.0 (SVr4), and more" topics = ("conan", "ncurses", "terminal", "screen", "tui") url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.gnu.org/software/ncurses" license = "X11" exports_sources = "patches/**" settings = "os", "compiler", "build_type", "arch" generators = "pkg_config" options = { "shared": [True, False], "fPIC": [True, False], "with_widec": [True, False], "with_extended_colors": [True, False], "with_cxx": [True, False], "with_progs": [True, False], "with_ticlib": ["auto", True, False], "with_reentrant": [True, False], "with_tinfo": ["auto", True, False], "with_pcre2": [True, False], } default_options = { "shared": False, "fPIC": True, "with_widec": True, "with_extended_colors": True, "with_cxx": True, "with_progs": True, "with_ticlib": "auto", "with_reentrant": False, "with_tinfo": "auto", "with_pcre2": False, } _autotools = None @property def _source_subfolder(self): return "source_subfolder" @property def _with_ticlib(self): if self.options.with_ticlib == "auto": return self.settings.os != "Windows" else: return self.options.with_ticlib @property def _with_tinfo(self): if self.options.with_tinfo == "auto": return self.settings.os != "Windows" else: return self.options.with_tinfo 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.compiler == "Visual Studio": if "MT" in str(self.settings.compiler.runtime): raise ConanInvalidConfiguration("Cannot build shared libraries with static (MT) runtime") if not self.options.with_cxx: del self.settings.compiler.libcxx del self.settings.compiler.cppstd if not self.options.with_widec: del self.options.with_extended_colors if self.settings.os == "Windows": if self._with_tinfo: raise ConanInvalidConfiguration("terminfo cannot be built on Windows because it requires a term driver") if self.options.shared and self._with_ticlib: raise ConanInvalidConfiguration("ticlib cannot be built separately as a shared library on Windows") def requirements(self): if self.options.with_pcre2: self.requires("pcre2/10.33") if self.settings.compiler == "Visual Studio": self.requires("getopt-for-visual-studio/20200201") self.requires("dirent/1.23.2") if self.options.get_safe("with_extended_colors", False): self.requires("naive-tsearch/0.1.1") def build_requirements(self): 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("ncurses-{}".format(self.version), self._source_subfolder) def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) build = None host = None conf_args = [ "--enable-widec" if self.options.with_widec else "--disable-widec", "--enable-ext-colors" if self.options.get_safe("with_extended_colors", False) else "--disable-ext-colors", "--enable-reentrant" if self.options.with_reentrant else "--disable-reentrant", "--with-pcre2" if self.options.with_pcre2 else "--without-pcre2", "--with-cxx-binding" if self.options.with_cxx else "--without-cxx-binding", "--with-progs" if self.options.with_progs else "--without-progs", "--with-termlib" if self._with_tinfo else "--without-termlib", "--with-ticlib" if self._with_ticlib else "--without-ticlib", "--without-libtool", "--without-ada", "--without-manpages", "--without-tests", "--disable-echo", "--without-debug", "--without-profile", "--with-sp-funcs", "--disable-rpath", "--datarootdir={}".format(tools.unix_path(os.path.join(self.package_folder, "bin", "share"))), "--disable-pc-files", ] if self.options.shared: conf_args.extend(["--with-shared", "--without-normal", "--with-cxx-shared",]) else: conf_args.extend(["--without-shared", "--with-normal", "--without-cxx-shared"]) if self.settings.os == "Windows": conf_args.extend([ "--disable-macros", "--disable-termcap", "--enable-database", "--enable-sp-funcs", "--enable-term-driver", "--enable-interop", ]) if self.settings.compiler == "Visual Studio": conf_args.extend([ "ac_cv_func_getopt=yes", "ac_cv_func_setvbuf_reversed=no", ]) build = host = "{}-w64-mingw32-msvc7".format(self.settings.arch) self._autotools.flags.append("-FS") self._autotools.cxx_flags.append("-EHsc") self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder, host=host, build=build) return self._autotools def _patch_sources(self): for patch in self.conan_data["patches"][self.version]: tools.patch(**patch) @contextmanager def _build_context(self): if self.settings.compiler == "Visual Studio": with tools.vcvars(self.settings): msvc_env = { "CC": "cl -nologo", "CXX": "cl -nologo", "LD": "link -nologo", "LDFLAGS": "", "NM": "dumpbin -symbols", "STRIP": ":", "AR": "lib -nologo", "RANLIB": ":", } with tools.environment_append(msvc_env): yield else: yield def build(self): self._patch_sources() # return with self._build_context(): autotools = self._configure_autotools() autotools.make() @property def _major_version(self): return tools.Version(self.version).major def package(self): # return self.copy("COPYING", src=self._source_subfolder, dst="licenses") with self._build_context(): autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) autotools.install() os.unlink(os.path.join(self.package_folder, "bin", "ncurses{}{}-config".format(self._suffix, self._major_version))) @property def _suffix(self): res = "" if self.options.with_reentrant: res += "t" if self.options.with_widec: res += "w" return res @property def _lib_suffix(self): res = self._suffix if self.options.shared: if self.settings.os == "Windows": if self.settings.compiler == "Visual Studio": res += ".dll.lib" else: res += ".dll.a" return res def package_id(self): self.info.options.with_ticlib = self._with_ticlib self.info.options.with_tinfo = self._with_tinfo def package_info(self): if self._with_tinfo: self.cpp_info.components["tinfo"].libs = ["tinfo" + self._lib_suffix] self.cpp_info.components["tinfo"].names["pkg_config"] = "tinfo" + self._lib_suffix self.cpp_info.components["tinfo"].includedirs.append(os.path.join("include", "ncurses" + self._suffix)) self.cpp_info.components["libcurses"].libs = ["ncurses" + self._lib_suffix] self.cpp_info.components["libcurses"].names["pkg_config"] = "ncurses" + self._lib_suffix self.cpp_info.components["libcurses"].includedirs.append(os.path.join("include", "ncurses" + self._suffix)) if not self.options.shared: self.cpp_info.components["libcurses"].defines = ["NCURSES_STATIC"] if self.settings.os == "Linux": self.cpp_info.components["libcurses"].system_libs = ["dl", "m"] if self._with_tinfo: self.cpp_info.components["libcurses"].requires.append("tinfo") if self.settings.compiler == "Visual Studio": self.cpp_info.components["libcurses"].requires.extend([ "getopt-for-visual-studio::getopt-for-visual-studio", "dirent::dirent", ]) if self.options.get_safe("with_extended_colors", False): self.cpp_info.components["libcurses"].requires.append("naive-tsearch::naive-tsearch") self.cpp_info.components["panel"].libs = ["panel" + self._lib_suffix] self.cpp_info.components["panel"].names["pkg_config"] = "panel" + self._lib_suffix self.cpp_info.components["panel"].requires = ["libcurses"] self.cpp_info.components["menu"].libs = ["menu" + self._lib_suffix] self.cpp_info.components["menu"].names["pkg_config"] = "menu" + self._lib_suffix self.cpp_info.components["menu"].requires = ["libcurses"] self.cpp_info.components["form"].libs = ["form" + self._lib_suffix] self.cpp_info.components["form"].names["pkg_config"] = "form" + self._lib_suffix self.cpp_info.components["form"].requires = ["libcurses"] if self.options.with_pcre2: self.cpp_info.components["form"].requires.append("pcre2::pcre2") if self.options.with_cxx: self.cpp_info.components["curses++"].libs = ["ncurses++" + self._lib_suffix] self.cpp_info.components["curses++"].names["pkg_config"] = "ncurses++" + self._lib_suffix self.cpp_info.components["curses++"].requires = ["libcurses"] if self._with_ticlib: self.cpp_info.components["ticlib"].libs = ["tic" + self._lib_suffix] self.cpp_info.components["ticlib"].names["pkg_config"] = "tic" + self._lib_suffix self.cpp_info.components["ticlib"].requires = ["libcurses"] if self.options.with_progs: 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) terminfo = os.path.join(self.package_folder, "bin", "share", "terminfo") self.output.info("Setting TERMINFO environment variable: {}".format(terminfo)) self.env_info.TERMINFO = terminfo self.user_info.lib_suffix = self._lib_suffix
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"] generators = "cmake", "pkg_config" settings = "os", "arch", "compiler", "build_type" options = {"shared": [True, False], "fPIC": [True, False], "with_openssl": [True, False], "with_winssl": [True, False], "with_ldap": [True, False], "darwin_ssl": [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_brotli": [True, False] } default_options = {'shared': False, 'fPIC': True, 'with_openssl': True, 'with_winssl': False, 'with_ldap': False, 'darwin_ssl': True, 'with_libssh2': False, 'with_libidn': False, 'with_librtmp': False, 'with_libmetalink': False, 'with_libpsl': False, 'with_largemaxwritesize': False, 'with_nghttp2': False, 'with_brotli': False } _source_subfolder = "source_subfolder" _build_subfolder = "build_subfolder" _autotools = False @property def _is_mingw(self): return self.settings.os == "Windows" and self.settings.compiler != "Visual Studio" 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 config_options(self): if not tools.is_apple_os(self.settings.os): del self.options.darwin_ssl if self.settings.os != "Windows": del self.options.with_winssl if self.settings.os == "Windows": del self.options.fPIC def configure(self): del self.settings.compiler.libcxx del self.settings.compiler.cppstd # be careful with those flags: # - with_openssl AND darwin_ssl uses darwin_ssl (to maintain recipe compatibilty) # - with_openssl AND NOT darwin_ssl uses openssl # - with_openssl AND with_winssl raises to error # - with_openssl AND NOT with_winssl uses openssl # Moreover darwin_ssl is set by default and with_winssl is not if self.settings.os == "Windows" and self.options.with_winssl and self.options.with_openssl: raise ConanInvalidConfiguration('Specify only with_winssl or with_openssl') if self.options.with_openssl: # enforce shared linking due to openssl dependency if not tools.is_apple_os(self.settings.os) or not self.options.darwin_ssl: self.options["openssl"].shared = self.options.shared if self.options.with_libssh2: if self.settings.compiler != "Visual Studio": self.options["libssh2"].shared = self.options.shared def system_requirements(self): # TODO: Declare tools needed to compile. The idea is Conan checking that they are # installed and providing a meaninful message before starting the compilation. It # would be much better than installed them (sudo required). pass def requirements(self): if self.options.with_openssl: if tools.is_apple_os(self.settings.os) and self.options.darwin_ssl: pass elif self.settings.os == "Windows" and self.options.with_winssl: pass else: self.requires("openssl/1.1.1f") if self.options.with_libssh2: if self.settings.compiler != "Visual Studio": self.requires("libssh2/1.9.0") if self.options.with_nghttp2: self.requires("libnghttp2/1.40.0") self.requires("zlib/1.2.11") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("curl-%s" % self.version, self._source_subfolder) tools.download("https://curl.haxx.se/ca/cacert.pem", "cacert.pem", verify=True) def build(self): self._patch_misc_files() if self.settings.compiler != "Visual Studio": self._build_with_autotools() else: self._build_with_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.darwin_ssl: 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 _get_configure_command_args(self): params = [] params.append("--without-libidn2" if not self.options.with_libidn else "--with-libidn2") params.append("--without-librtmp" if not self.options.with_librtmp else "--with-librtmp") params.append("--without-libmetalink" if not self.options.with_libmetalink else "--with-libmetalink") params.append("--without-libpsl" if not self.options.with_libpsl else "--with-libpsl") params.append("--without-brotli" if not self.options.with_brotli else "--with-brotli") if tools.is_apple_os(self.settings.os) and self.options.darwin_ssl: params.append("--with-darwinssl") params.append("--without-ssl") elif self.settings.os == "Windows" and self.options.with_winssl: params.append("--with-winssl") params.append("--without-ssl") elif self.options.with_openssl: openssl_path = self.deps_cpp_info["openssl"].rootpath.replace('\\', '/') params.append("--with-ssl=%s" % openssl_path) else: params.append("--without-ssl") if self.options.with_libssh2: params.append("--with-libssh2=%s" % self.deps_cpp_info["libssh2"].lib_paths[0].replace('\\', '/')) else: params.append("--without-libssh2") if self.options.with_nghttp2: params.append("--with-nghttp2=%s" % self.deps_cpp_info["libnghttp2"].rootpath.replace('\\', '/')) else: params.append("--without-nghttp2") params.append("--with-zlib=%s" % self.deps_cpp_info["zlib"].lib_paths[0].replace('\\', '/')) if not self.options.shared: params.append("--disable-shared") params.append("--enable-static") else: params.append("--enable-shared") params.append("--disable-static") if not self.options.with_ldap: params.append("--disable-ldap") # 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 _patch_mingw_files(self): if not self._is_mingw: return # patch autotools files # for mingw builds - do not compile curl tool, just library # linking errors are much harder to fix than to exclude curl tool tools.replace_in_file("Makefile.am", 'SUBDIRS = lib src', 'SUBDIRS = lib') tools.replace_in_file("Makefile.am", 'include src/Makefile.inc', '') # patch for zlib naming in mingw # when cross-building, the name is correct if not tools.cross_building(self.settings): tools.replace_in_file("configure.ac", '-lz ', '-lzlib ') # patch for openssl extras in mingw if self.options.with_openssl: tools.replace_in_file("configure", '-lcrypto ', '-lcrypto -lcrypt32 ') if self.options.shared: # patch for shared mingw build tools.replace_in_file(os.path.join('lib', 'Makefile.am'), 'noinst_LTLIBRARIES = libcurlu.la', '') tools.replace_in_file(os.path.join('lib', 'Makefile.am'), 'noinst_LTLIBRARIES =', '') tools.replace_in_file(os.path.join('lib', 'Makefile.am'), '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(os.path.join(self.source_folder, 'lib_Makefile_add.am')) tools.save(os.path.join('lib', 'Makefile.am'), added_content, append=True) def _build_with_autotools(self): with tools.chdir(self._source_subfolder): use_win_bash = self._is_mingw and not tools.cross_building(self.settings) # autoreconf self.run('./buildconf', win_bash=use_win_bash, 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") env_run = RunEnvironment(self) # run configure with *LD_LIBRARY_PATH env vars it allows to pick up shared openssl self.output.info("Run vars: " + repr(env_run.vars)) with tools.environment_append(env_run.vars): 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' del autotools_vars['LIBS'] self.output.info("Autotools env vars: " + repr(autotools_vars)) if tools.cross_building(self.settings): if self.settings.os == "iOS": iphoneos = tools.apple_sdk_name(self.settings) ios_dev_target = str(self.settings.os.version).split(".")[0] if self.settings.arch in ["x86", "x86_64"]: autotools_vars['CPPFLAGS'] = "-D__IPHONE_OS_VERSION_MIN_REQUIRED={}0000".format(ios_dev_target) elif self.settings.arch in ["armv7", "armv7s", "armv8"]: autotools_vars['CPPFLAGS'] = "" else: raise ConanInvalidConfiguration("Unsuported iOS arch {}".format(self.settings.arch)) cc = tools.XCRun(self.settings, iphoneos).cc sysroot = "-isysroot {}".format(tools.XCRun(self.settings, iphoneos).sdk_path) if self.settings.arch == "armv8": configure_arch = "arm64" configure_host = "arm" #unused, autodetected else: configure_arch = self.settings.arch configure_host = self.settings.arch #unused, autodetected arch_flag = "-arch {}".format(configure_arch) ios_min_version = tools.apple_deployment_target_flag(self.settings.os, self.settings.os.version) extra_flag = "-Werror=partial-availability" extra_def = " -DHAVE_SOCKET -DHAVE_FCNTL_O_NONBLOCK" # if we debug, maybe add a -gdwarf-2 , but why would we want that? autotools_vars['CC'] = cc autotools_vars['IPHONEOS_DEPLOYMENT_TARGET'] = ios_dev_target autotools_vars['CFLAGS'] = "{} {} {} {}".format( sysroot, arch_flag, ios_min_version, extra_flag ) if self.options.with_openssl: openssl_path = self.deps_cpp_info["openssl"].rootpath openssl_libdir = self.deps_cpp_info["openssl"].libdirs[0] autotools_vars['LDFLAGS'] = "{} {} -L{}/{}".format(arch_flag, sysroot, openssl_path, openssl_libdir) else: autotools_vars['LDFLAGS'] = "{} {}".format(arch_flag, sysroot) autotools_vars['CPPFLAGS'] += extra_def elif self.settings.os == "Android": # nothing do to at the moment, this seems to just work pass return autotools_vars def _configure_autotools(self): if not self._autotools: use_win_bash = self._is_mingw and not tools.cross_building(self.settings) self._autotools = AutoToolsBuildEnvironment(self, win_bash=use_win_bash) if self.settings.os != "Windows": self._autotools.fpic = self.options.fPIC autotools_vars = self._configure_autotools_vars() # tweaks for mingw if self._is_mingw: # patch autotools files self._patch_mingw_files() self._autotools.defines.append('_AMD64_') 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=autotools_vars, args=configure_args, build=False) else: self._autotools.configure(vars=autotools_vars, args=configure_args) return self._autotools, self._configure_autotools_vars() def _configure_cmake(self): cmake = CMake(self) cmake.definitions['BUILD_TESTING'] = False cmake.definitions['BUILD_CURL_EXE'] = False cmake.definitions['CURL_DISABLE_LDAP'] = not self.options.with_ldap cmake.definitions['BUILD_SHARED_LIBS'] = self.options.shared cmake.definitions['CURL_STATICLIB'] = not self.options.shared cmake.definitions['CMAKE_DEBUG_POSTFIX'] = '' cmake.definitions['CMAKE_USE_LIBSSH2'] = self.options.with_libssh2 # all these options are exclusive. set just one of them # mac builds do not use cmake so don't even bother about darwin_ssl cmake.definitions['CMAKE_USE_WINSSL'] = 'with_winssl' in self.options and self.options.with_winssl cmake.definitions['CMAKE_USE_OPENSSL'] = 'with_openssl' in self.options and self.options.with_openssl cmake.configure(build_folder=self._build_subfolder) return cmake def _build_with_cmake(self): # patch cmake files with tools.chdir(self._source_subfolder): tools.replace_in_file("CMakeLists.txt", "include(CurlSymbolHiding)", "") cmake = self._configure_cmake() cmake.build() def package(self): self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder) # Execute install if self.settings.compiler != "Visual Studio": env_run = RunEnvironment(self) with tools.environment_append(env_run.vars): with tools.chdir(self._source_subfolder): autotools, autotools_vars = self._configure_autotools() autotools.install(vars=autotools_vars) else: cmake = self._configure_cmake() cmake.install() if self._is_mingw: # 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="*.def", dst="lib", keep_path=False) self.copy(pattern="*.lib", dst="lib", keep_path=False) self.copy("cacert.pem", dst="res") # no need to distribute share folder (docs/man pages) tools.rmdir(os.path.join(self.package_folder, 'share')) # no need for pc files tools.rmdir(os.path.join(self.package_folder, 'lib', 'pkgconfig')) # no need for cmake files tools.rmdir(os.path.join(self.package_folder, 'lib', 'cmake')) # Remove libtool files (*.la) if os.path.isfile(os.path.join(self.package_folder, 'lib', 'libcurl.la')): os.remove(os.path.join(self.package_folder, 'lib', 'libcurl.la')) def package_info(self): self.cpp_info.names['cmake_find_package'] = 'CURL' self.cpp_info.names['cmake_find_package_multi'] = 'CURL' if self.settings.compiler != "Visual Studio": self.cpp_info.libs = ['curl'] if self.settings.os == "Linux": self.cpp_info.system_libs.extend(["rt", "pthread"]) if self.options.with_libssh2: self.cpp_info.libs.extend(["ssh2"]) if self.options.with_libidn: self.cpp_info.libs.extend(["idn"]) if self.options.with_librtmp: self.cpp_info.libs.extend(["rtmp"]) if self.options.with_brotli: self.cpp_info.libs.extend(["brotlidec"]) if self.settings.os == "Macos": if self.options.with_ldap: self.cpp_info.system_libs.extend(["ldap"]) if self.options.darwin_ssl: self.cpp_info.frameworks.extend(["Cocoa", "Security"]) else: self.cpp_info.libs = ['libcurl_imp'] if self.options.shared else ['libcurl'] if self.settings.os == "Windows": # used on Windows for VS build, native and cross mingw build self.cpp_info.system_libs.append('ws2_32') if self.options.with_ldap: self.cpp_info.system_libs.append("wldap32") if self.options.with_winssl: self.cpp_info.system_libs.append("Crypt32") if self._is_mingw: # provide pthread for dependent packages self.cpp_info.cflags.append("-pthread") self.cpp_info.exelinkflags.append("-pthread") self.cpp_info.sharedlinkflags.append("-pthread") if not self.options.shared: self.cpp_info.defines.append("CURL_STATICLIB=1")
def _get_auto_tools(self): autoTools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) return autoTools
class FontconfigConan(ConanFile): name = "fontconfig" version = "2.13.91" license = "MIT" url = "https://github.com/conan-community/conan-fontconfig" description = "Fontconfig is a library for configuring and customizing font access" homepage = "https://gitlab.freedesktop.org/fontconfig/fontconfig" author = "Conan Community" topics = ("conan", "fontconfig", "fonts", "freedesktop") settings = "os", "compiler", "build_type", "arch" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} generators = "pkg_config" exports = "LICENSE" _source_subfolder = "source_subfolder" _autotools = None def requirements(self): self.requires("freetype/2.10.0") self.requires("expat/2.2.7") if self.settings.os == "Linux": self.requires("libuuid/1.0.3") def configure(self): if self.settings.os == "Windows": raise ConanInvalidConfiguration("Windows builds are not supported.") del self.settings.compiler.libcxx del self.settings.compiler.cppstd def source(self): source_url = "https://www.freedesktop.org/software/fontconfig/release/fontconfig-{}.tar.gz" sha256 = "19e5b1bc9d013a52063a44e1307629711f0bfef35b9aca16f9c793971e2eb1e5" tools.get(source_url.format(self.version), sha256=sha256) extrated_dir = self.name + "-" + self.version os.rename(extrated_dir, self._source_subfolder) def build_requirements(self): self.build_requires("gperf_installer/3.1@conan/stable") if not tools.which("pkg-config"): self.build_requires("pkg-config_installer/0.29.2@bincrafters/stable") 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-docs"] self._autotools = AutoToolsBuildEnvironment(self) self._autotools.configure(configure_dir=self._source_subfolder, args=args) tools.replace_in_file("Makefile", "po-conf test", "po-conf") return self._autotools def _patch_files(self): # - fontconfig requires libtool version number, change it for the corresponding freetype one tools.replace_in_file(os.path.join(self._source_subfolder, 'configure'), '21.0.15', '2.8.1') os.rename('freetype.pc', 'freetype2.pc') os.rename('ZLIB.pc', 'zlib.pc') def build(self): # Patch files from dependencies self._patch_files() autotools = self._configure_autotools() autotools.make() def package(self): self.copy("COPYING", dst="licenses", src=self._source_subfolder) autotools = self._configure_autotools() autotools.install() la = os.path.join(self.package_folder, "lib", "libfontconfig.la") if os.path.isfile(la): os.unlink(la) def package_info(self): self.cpp_info.libs = tools.collect_libs(self) if self.settings.os == "Linux": self.cpp_info.libs.extend(["m", "pthread"]) self.env_info.PATH.append(os.path.join(self.package_folder, 'bin'))
def build(self): autotools = AutoToolsBuildEnvironment(self) autotools.configure(configure_dir='trng-4.21') autotools.make() autotools.install()
class XapianCoreConan(ConanFile): name = "xapian-core" description = "Xapian is a highly adaptable toolkit which allows developers to easily add advanced indexing and search facilities to their own applications." topics = ("conan", "xapian", "search", "engine", "indexing", "query") license = "GPL-2.0-or-later" homepage = "https://xapian.org/" url = "https://github.com/conan-io/conan-center-index" 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" @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 if self.options.shared and self.settings.os == "Windows": raise ConanInvalidConfiguration("shared builds are unavailable due to libtool's inability to create shared libraries") def requirements(self): if self.settings.os != "Windows": self.requires("libuuid/1.0.3") self.requires("zlib/1.2.11") def build_requirements(self): 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) @contextmanager def _build_context(self): if self.settings.compiler == "Visual Studio": with tools.vcvars(self.settings): msvc_cl_sh = os.path.join(self.build_folder, "msvc_cl.sh").replace("\\", "/") env = { "AR": "lib", "CC": msvc_cl_sh, "CXX": msvc_cl_sh, "LD": msvc_cl_sh, "NM": "dumpbin -symbols", "OBJDUMP": ":", "RANLIB": ":", "STRIP": ":", } with tools.environment_append(env): yield else: yield @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) self._autotools.libs = [] self._autotools.link_flags.extend(["-L{}".format(l.replace("\\", "/")) for l in self._autotools.library_paths]) self._autotools.library_paths = [] if self.settings.compiler == "Visual Studio": self._autotools.cxx_flags.extend(["-EHsc", "-FS"]) conf_args = [ "--datarootdir={}".format(self._datarootdir.replace("\\", "/")), "--disable-documentation", ] 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, 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() if self.settings.compiler == "Visual Studio": if self.options.shared: pass else: tools.rename(os.path.join(self.package_folder, "lib", "libxapian.lib"), os.path.join(self.package_folder, "lib", "xapian.lib")) os.unlink(os.path.join(os.path.join(self.package_folder, "bin", "xapian-config"))) os.unlink(os.path.join(os.path.join(self.package_folder, "lib", "libxapian.la"))) tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.rmdir(os.path.join(self._datarootdir, "doc")) tools.rmdir(os.path.join(self._datarootdir, "man")) self._create_cmake_module_variables( os.path.join(self.package_folder, self._module_file_rel_path) ) @staticmethod def _create_cmake_module_variables(module_file): content = textwrap.dedent("""\ set(XAPIAN_FOUND TRUE) set(XAPIAN_INCLUDE_DIR ${xapian_INCLUDE_DIR} ${xapian_INCLUDE_DIR_RELEASE} ${xapian_INCLUDE_DIR_RELWITHDEBINFO} ${xapian_INCLUDE_DIR_MINSIZEREL} ${xapian_INCLUDE_DIR_DEBUG}) set(XAPIAN_LIBRARIES ${xapian_LIBRARIES} ${xapian_LIBRARIES_RELEASE} ${xapian_LIBRARIES_RELWITHDEBINFO} ${xapian_LIBRARIES_MINSIZEREL} ${xapian_LIBRARIES_DEBUG}) """) tools.save(module_file, content) @property def _module_subfolder(self): return os.path.join("lib", "cmake") @property def _module_file_rel_path(self): return os.path.join(self._module_subfolder, "conan-official-{}-variables.cmake".format(self.name)) def package_info(self): self.cpp_info.libs = ["xapian"] if not self.options.shared: if self.settings.os in ("Linux", "FreeBSD"): self.cpp_info.system_libs = ["rt"] elif self.settings.os == "Windows": self.cpp_info.system_libs = ["rpcrt4", "ws2_32"] elif self.settings.os == "SunOS": self.cpp_info.system_libs = ["socket", "nsl"] self.cpp_info.names["cmake_find_package"] = "xapian" self.cpp_info.names["cmake_find_package_multi"] = "xapian" self.cpp_info.builddirs.append(self._module_subfolder) self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path] self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] self.cpp_info.names["pkg_config"] = "xapian-core" binpath = os.path.join(self.package_folder, "bin") self.output.info("Appending PATH environment variable: {}".format(binpath)) self.env_info.PATH.append(binpath) xapian_aclocal = tools.unix_path(os.path.join(self._datarootdir, "aclocal")) self.output.info("Appending AUTOMAKE_CONAN_INCLUDES environment variable: {}".format(xapian_aclocal)) self.env_info.AUTOMAKE_CONAN_INCLUDES.append(tools.unix_path(xapian_aclocal))
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", "build_type" 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 del self.info.settings.build_type 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 = [] self.cpp_info.includedirs = [] 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")
def build(self): # Source should be downloaded in the build step since it depends on specific options self._download_source() 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) ] 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!")
def build(self): self.run("./bootstrap") autotools = AutoToolsBuildEnvironment(self) autotools.configure() autotools.make() autotools.install()
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... } _source_subfolder = "source_subfolder" _autotools = None _pupnp_libs = ["upnp", "ixml"] def configure(self): if self.settings.os == "Windows": # Note, pupnp has build instructions for Windows 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("Windows builds are not supported.") del self.settings.compiler.libcxx del self.settings.compiler.cppstd if self.options.shared: del self.options.fPIC def source(self): tools.get(**self.conan_data["sources"][self.version]) extrated_dir = self.name + "-release-" + self.version os.rename(extrated_dir, self._source_subfolder) 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", "blocking-tcp", "debug" ), ) ) self.run("./bootstrap", run_environment=True, cwd=self._source_subfolder) self._autotools = AutoToolsBuildEnvironment(self) self._autotools.configure(configure_dir=self._source_subfolder, args=args) 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() # Adjust install folders so includes go into convenient place # and pkgconfig stays in build folder. autotools.install(args=["upnpincludedir=$(includedir)", "pkgconfigexecdir=no_install"]) for lib in self._pupnp_libs: os.unlink(os.path.join(self.package_folder, "lib", "lib%s.la" % lib)) def package_info(self): self.cpp_info.libs.extend(self._pupnp_libs) if self.settings.os == "Linux": self.cpp_info.system_libs.extend(["pthread"]) self.cpp_info.cflags.extend(["-pthread"]) self.cpp_info.cxxflags.extend(["-pthread"])
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 MpirConan(ConanFile): name = "mpir" description = "MPIR is a highly optimised library for bignum arithmetic" \ "forked from the GMP bignum library." topics = ("conan", "mpir", "multiprecision", "math", "mathematics") url = "https://github.com/conan-io/conan-center-index" homepage = "http://mpir.org/" license = "LGPL-3.0-or-later" settings = "os", "compiler", "arch", "build_type" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} _source_subfolder = "source_subfolder" _platforms = {'x86': 'Win32', 'x86_64': 'x64'} _autotools = None def build_requirements(self): self.build_requires("yasm/1.3.0") def config_options(self): if self.settings.os == "Windows": del self.options.fPIC @property def _dll_or_lib(self): return "dll" if self.options.shared else "lib" @property def _vcxproj_path(self): compiler_version = self.settings.compiler.version if tools.Version( self.settings.compiler.version) < "16" else "15" return os.path.join(self._source_subfolder, "build.vc{}".format(compiler_version), "{}_mpir_gc".format(self._dll_or_lib), "{}_mpir_gc.vcxproj".format(self._dll_or_lib)) def source(self): tools.get(keep_permissions=True, **self.conan_data["sources"][self.version]) extracted_dir = self.name + "-" + self.version os.rename(extracted_dir, self._source_subfolder) def _build_visual_studio(self): if "MD" in self.settings.compiler.runtime and not self.options.shared: # RuntimeLibrary only defined in lib props files props_path = os.path.join( self._source_subfolder, "build.vc", "mpir_{}_{}.props".format( str(self.settings.build_type).lower(), self._dll_or_lib)) if self.settings.build_type == "Debug": tools.replace_in_file( props_path, "<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>", "<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>") else: tools.replace_in_file( props_path, "<RuntimeLibrary>MultiThreaded</RuntimeLibrary>", "<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>") msbuild = MSBuild(self) msbuild.build(self._vcxproj_path, platforms=self._platforms, upgrade_project=False) def _configure_autotools(self): if not self._autotools: self._autotools = AutoToolsBuildEnvironment(self) args = [] if self.options.shared: args.extend(['--disable-static', '--enable-shared']) else: args.extend(['--disable-shared', '--enable-static']) args.extend([ '--disable-silent-rules', '--enable-gmpcompat', '--enable-cxx' ]) self._autotools.configure(args=args) return self._autotools def build(self): if self.settings.compiler == "Visual Studio": self._build_visual_studio() else: with tools.chdir(self._source_subfolder): autotools = self._configure_autotools() autotools.make() def package(self): self.copy("COPYING*", dst="licenses", src=self._source_subfolder) if self.settings.compiler == 'Visual Studio': lib_folder = os.path.join( self._source_subfolder, self._dll_or_lib, self._platforms.get(str(self.settings.arch)), str(self.settings.build_type)) self.copy("*.h", dst="include", src=lib_folder, keep_path=True) self.copy(pattern="*.dll*", dst="bin", src=lib_folder, keep_path=False) self.copy(pattern="*.lib", dst="lib", src=lib_folder, keep_path=False) else: with tools.chdir(self._source_subfolder): autotools = self._configure_autotools() autotools.install() 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_info(self): self.cpp_info.libs = ['mpir']
class LibnetConan(ConanFile): name = "libnet" description = "Libnet is an API to help with the construction and injection of network packets." topics = ("conan", "libnet", "network") url = "https://github.com/conan-io/conan-center-index" homepage = "http://libnet.sourceforge.net/" license = ["BSD-2-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): del self.settings.compiler.libcxx del self.settings.compiler.cppstd if self.options.shared: del self.options.fPIC if self.settings.compiler == "Visual Studio": raise ConanInvalidConfiguration( "libnet is not supported by Visual Studio") if self.settings.os == "Windows" and self.options.shared: raise ConanInvalidConfiguration( "libnet can't be built as shared on Windows") def source(self): tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder) def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment(self) args = [] if self.options.shared: args.extend(["--disable-static", "--enable-shared"]) else: args.extend(["--disable-shared", "--enable-static"]) args.append("--disable-doxygen-doc") self._autotools.configure(configure_dir=self._source_subfolder, args=args) return self._autotools def build(self): autotools = self._configure_autotools() autotools.make() def package(self): self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder) autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "share")) os.unlink(os.path.join(self.package_folder, "lib", "libnet.la")) os.unlink( os.path.join(self.package_folder, "lib", "pkgconfig", "libnet.pc")) def package_info(self): self.cpp_info.libs = ["net"] self.cpp_info.names["pkg_config"] = "libnet" if self.settings.os == "Linux": self.cpp_info.system_libs.append("m") elif self.settings.os == "Windows": self.cpp_info.system_libs.append("ws2_32")
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" @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.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 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 _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) 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)), ] 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 in ("FreeBSD", "Linux"): self.cpp_info.system_libs.append("m")
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.1i") elif self.options.with_ssl == "wolfssl": self.requires("wolfssl/4.5.0") if self.options.with_nghttp2: self.requires("libnghttp2/1.42.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.8") 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_mingw and 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/20200517") elif self._is_win_x_android: self.build_requires("ninja/1.10.1") elif not tools.os_info.is_windows: self.build_requires("libtool/2.4.6") self.build_requires("pkgconf/1.7.3") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("curl-%s" % self.version, self._source_subfolder) 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() self._patch_misc_files() 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) 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") if self._has_zstd_option: # Custom findZstd.cmake file relies on pkg-config file, make sure that it's consumed on all platforms tools.replace_in_file( os.path.join(self._source_subfolder, "CMake", "FindZstd.cmake"), "if(UNIX)", "if(TRUE)") 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-darwinssl={}".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"].lib_paths[0]))) 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"].lib_paths[0]))) 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 _patch_mingw_files(self): if not self._is_mingw: return # patch autotools files # for mingw builds - do not compile curl tool, just library # linking errors are much harder to fix than to exclude curl tool tools.replace_in_file("Makefile.am", "SUBDIRS = lib src", "SUBDIRS = lib") tools.replace_in_file("Makefile.am", "include src/Makefile.inc", "") # patch for zlib naming in mingw # when cross-building, the name is correct if not tools.cross_building(self.settings): tools.replace_in_file("configure.ac", "-lz ", "-lzlib ") # patch for openssl extras in mingw if self.options.with_ssl == "openssl": tools.replace_in_file("configure", "-lcrypto ", "-lcrypto -lcrypt32 ") if self.options.shared: # patch for shared mingw build tools.replace_in_file(os.path.join("lib", "Makefile.am"), "noinst_LTLIBRARIES = libcurlu.la", "") tools.replace_in_file(os.path.join("lib", "Makefile.am"), "noinst_LTLIBRARIES =", "") tools.replace_in_file(os.path.join("lib", "Makefile.am"), "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( os.path.join(self.source_folder, "lib_Makefile_add.am")) tools.save(os.path.join("lib", "Makefile.am"), added_content, append=True) def _build_with_autotools(self): with tools.chdir(self._source_subfolder): # autoreconf self.run("./buildconf", 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") env_run = RunEnvironment(self) # run configure with *LD_LIBRARY_PATH env vars it allows to pick up shared openssl self.output.info("Run vars: " + repr(env_run.vars)) with tools.environment_append(env_run.vars): 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" del autotools_vars["LIBS"] self.output.info("Autotools env vars: " + repr(autotools_vars)) if tools.cross_building(self.settings): if self.settings.os == "iOS": iphoneos = tools.apple_sdk_name(self.settings) ios_dev_target = str(self.settings.os.version).split(".")[0] env_cppflags = tools.get_env("CPPFLAGS", "") socket_flags = " -DHAVE_SOCKET -DHAVE_FCNTL_O_NONBLOCK" if self.settings.arch in ["x86", "x86_64"]: autotools_vars[ "CPPFLAGS"] = "-D__IPHONE_OS_VERSION_MIN_REQUIRED={}0000 {} {}".format( ios_dev_target, socket_flags, env_cppflags) elif self.settings.arch in ["armv7", "armv7s", "armv8"]: autotools_vars["CPPFLAGS"] = "{} {}".format( socket_flags, env_cppflags) else: raise ConanInvalidConfiguration( "Unsuported iOS arch {}".format(self.settings.arch)) cc = tools.XCRun(self.settings, iphoneos).cc sysroot = "-isysroot {}".format( tools.XCRun(self.settings, iphoneos).sdk_path) if self.settings.arch == "armv8": configure_arch = "arm64" configure_host = "arm" #unused, autodetected else: configure_arch = self.settings.arch configure_host = self.settings.arch #unused, autodetected arch_flag = "-arch {}".format(configure_arch) ios_min_version = tools.apple_deployment_target_flag( self.settings.os, self.settings.os.version) extra_flag = "-Werror=partial-availability" # if we debug, maybe add a -gdwarf-2 , but why would we want that? autotools_vars["CC"] = cc autotools_vars["IPHONEOS_DEPLOYMENT_TARGET"] = ios_dev_target env_cflags = tools.get_env("CFLAGS", "") autotools_vars["CFLAGS"] = "{} {} {} {}".format( sysroot, arch_flag, ios_min_version, env_cflags) if self.options.with_ssl == "openssl": openssl_path = self.deps_cpp_info["openssl"].rootpath openssl_libdir = self.deps_cpp_info["openssl"].libdirs[0] autotools_vars["LDFLAGS"] = "{} {} -L{}/{}".format( arch_flag, sysroot, openssl_path, openssl_libdir) elif self.options.with_ssl == "wolfssl": wolfssl_path = self.deps_cpp_info["wolfssl"].rootpath wolfssl_libdir = self.deps_cpp_info["wolfssl"].libdirs[0] autotools_vars["LDFLAGS"] = "{} {} -L{}/{}".format( arch_flag, sysroot, wolfssl_path, wolfssl_libdir) else: autotools_vars["LDFLAGS"] = "{} {}".format( arch_flag, sysroot) elif self.settings.os == "Android": # nothing do to at the moment, this seems to just work pass 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: # patch autotools files self._patch_mingw_files() self._autotools.defines.append("_AMD64_") 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): # patch cmake files with tools.chdir(self._source_subfolder): tools.replace_in_file("CMakeLists.txt", "include(CurlSymbolHiding)", "") 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: env_run = RunEnvironment(self) with tools.environment_append(env_run.vars): 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 self.settings.os == "Macos": 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( ["Cocoa", "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 _get_env_build(self): if not self._env_build: self._env_build = AutoToolsBuildEnvironment(self) return self._env_build
def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) self._autotools.libs = [] opt_enable_disable = lambda what, v: "--{}-{}".format( "enable" if v else "disable", 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)), opt_enable_disable("postproc", self.options.postproc), # 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), opt_enable_disable( "gpl", self.options.with_libx264 or self.options.with_libx265 or self.options.postproc) ] 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.settings.compiler == "Visual Studio": args.append("--pkg-config={}".format(tools.get_env("PKG_CONFIG"))) args.append("--toolchain=msvc") if tools.Version(str(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): 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 _configure_autotools(self): autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) autotools.configure(args=self._autotools_args, configure_dir=self._source_subfolder) return autotools
class SwigConan(ConanFile): name = "swig" description = "SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages." url = "https://github.com/conan-io/conan-center-index" homepage = "http://www.swig.org" license = "GPL-3.0-or-later" topics = ("conan", "swig", "python", "java", "wrapper") exports_sources = "patches/**", "cmake/*" 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 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") if self.settings.compiler == "Visual Studio": self.build_requires("winflexbison/2.5.22") else: self.build_requires("bison/3.7.1") self.build_requires("automake/1.16.2") def requirements(self): self.requires("pcre/8.41") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("swig-rel-{}".format(self.version), self._source_subfolder) @property def _user_info_build(self): # If using the experimental feature with different context for host and # build, the 'user_info' attributes of the 'build_requires' packages # will be located into the 'user_info_build' object. In other cases they # will be located into the 'deps_user_info' object. return getattr(self, "user_info_build", None) or self.deps_user_info @contextmanager def _build_context(self): env = {} if self.settings.compiler != "Visual Studio": env["YACC"] = self._user_info_build["bison"].YACC if self.settings.compiler == "Visual Studio": with tools.vcvars(self.settings): env.update({ "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)), "AR": "{} link".format(self._user_info_build["automake"].ar_lib), "LD": "link", }) with tools.environment_append(env): yield else: with tools.environment_append(env): yield def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) deps_libpaths = self._autotools.library_paths deps_libs = self._autotools.libs deps_defines = self._autotools.defines if self.settings.os == "Windows" and self.settings.compiler != "Visual Studio": self._autotools.link_flags.append("-static") libargs = list("-L\"{}\"".format(p) for p in deps_libpaths) + list("-l\"{}\"".format(l) for l in deps_libs) args = [ "PCRE_LIBS={}".format(" ".join(libargs)), "PCRE_CPPFLAGS={}".format(" ".join("-D{}".format(define) for define in deps_defines)), "--host={}".format(self.settings.arch), "--with-swiglibdir={}".format(self._swiglibdir), ] host, build = None, None if self.settings.compiler == "Visual Studio": self.output.warn( "Visual Studio compiler cannot create ccache-swig. Disabling ccache-swig." ) args.append("--disable-ccache") self._autotools.flags.append("-FS") # MSVC canonical names aren't understood host, build = False, False self._autotools.libs = [] self._autotools.library_paths = [] self._autotools.configure(args=args, configure_dir=self._source_subfolder, host=host, build=build) return self._autotools def _patch_sources(self): for patch in self.conan_data["patches"][self.version]: tools.patch(**patch) def build(self): self._patch_sources() with tools.chdir(os.path.join(self._source_subfolder)): self.run("./autogen.sh", win_bash=tools.os_info.is_windows) with self._build_context(): autotools = self._configure_autotools() autotools.make() def package(self): self.copy(pattern="LICENSE*", dst="licenses", src=self._source_subfolder) self.copy(pattern="COPYRIGHT", dst="licenses", src=self._source_subfolder) self.copy("*", src="cmake", dst=self._module_subfolder) with self._build_context(): autotools = self._configure_autotools() autotools.install() @property def _swiglibdir(self): return os.path.join(self.package_folder, "bin", "swiglib").replace("\\", "/") @property def _module_subfolder(self): return os.path.join("lib", "cmake") @property def _module_file(self): return "conan-official-{}-targets.cmake".format(self.name) def package_info(self): self.cpp_info.names["cmake_find_package"] = "SWIG" self.cpp_info.names["cmake_find_package_multi"] = "SWIG" self.cpp_info.builddirs = [self._module_subfolder] self.cpp_info.build_modules = [ os.path.join(self._module_subfolder, self._module_file) ] bindir = os.path.join(self.package_folder, "bin") self.output.info( "Appending PATH environment variable: {}".format(bindir)) self.env_info.PATH.append(bindir)
class CoinCbcConan(ConanFile): name = "coin-cbc" description = "COIN-OR Branch-and-Cut solver" topics = ("conan", "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], } default_options = { "shared": False, "fPIC": True, } exports_sources = "patches/**.patch" generators = "pkg_config" _autotools = 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.settings.os == "Windows" and self.options.shared: raise ConanInvalidConfiguration( "coin-cbc does not support shared builds on Windows") 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") def build_requirements(self): 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") 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("Cbc-releases-{}".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 = [] yes_no = lambda v: "yes" if v else "no" configure_args = [ "--enable-shared={}".format(yes_no(self.options.shared)), "--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)) 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) 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" 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 LibsassConan(ConanFile): name = "libsass" license = "MIT" homepage = "libsass.org" url = "https://github.com/conan-io/conan-center-index" description = "A C/C++ implementation of a Sass compiler" topics = ("Sass", "LibSass", "compiler") settings = "os", "compiler", "build_type", "arch" 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_mingw(self): return self.settings.os == "Windows" and self.settings.compiler == "gcc" 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.compiler == "Visual Studio": # TODO: add Visual Studio support raise ConanInvalidConfiguration( "Visual Studio not yet supported in libsass recipe") def build_requirements(self): if self.settings.os != "Windows": 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 _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment(self) args = [] args.append("--disable-tests") args.append("--enable-%s" % ("shared" if self.options.shared else "static")) args.append("--disable-%s" % ("static" if self.options.shared else "shared")) self._autotools.configure(args=args) return self._autotools def _build_autotools(self): with tools.chdir(self._source_subfolder): tools.save(path="VERSION", content="%s" % self.version) self.run("{} -fiv".format(tools.get_env("AUTORECONF"))) autotools = self._configure_autotools() autotools.make() @property def _make_program(self): return tools.get_env( "CONAN_MAKE_PROGRAM", tools.which("make") or tools.which("mingw32-make")) def _build_mingw(self): makefile = os.path.join(self._source_subfolder, "Makefile") tools.replace_in_file(makefile, "CFLAGS += -O2", "") tools.replace_in_file(makefile, "CXXFLAGS += -O2", "") tools.replace_in_file(makefile, "LDFLAGS += -O2", "") with tools.chdir(self._source_subfolder): env_vars = AutoToolsBuildEnvironment(self).vars env_vars.update({ "BUILD": "shared" if self.options.shared else "static", "PREFIX": tools.unix_path(os.path.join(self.package_folder)), # Don't force static link to mingw libs, leave this decision to consumer (through LDFLAGS in env) "STATIC_ALL": "0", "STATIC_LIBGCC": "0", "STATIC_LIBSTDCPP": "0", }) with tools.environment_append(env_vars): self.run("{} -f Makefile".format(self._make_program)) def build(self): if self._is_mingw: self._build_mingw() else: self._build_autotools() def _install_autotools(self): with tools.chdir(self._source_subfolder): autotools = self._configure_autotools() autotools.install() tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.remove_files_by_mask(self.package_folder, "*.la") def _install_mingw(self): self.copy("*.h", dst="include", src=os.path.join(self._source_subfolder, "include")) self.copy("*.dll", dst="bin", src=os.path.join(self._source_subfolder, "lib")) self.copy("*.a", dst="lib", src=os.path.join(self._source_subfolder, "lib")) def package(self): self.copy("LICENSE", src=self._source_subfolder, dst="licenses") if self._is_mingw: self._install_mingw() else: self._install_autotools() def package_info(self): self.cpp_info.names["pkg_config"] = "libsass" self.cpp_info.libs = ["sass"] if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs.extend(["dl", "m"]) if not self.options.shared and tools.stdcpp_library(self): self.cpp_info.system_libs.append(tools.stdcpp_library(self))
class JemallocConan(ConanFile): name = "jemalloc" description = "jemalloc is a general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support." url = "https://github.com/conan-io/conan-center-index" license = "BSD-2-Clause" homepage = "http://jemalloc.net/" topics = ("conan", "jemalloc", "malloc", "free") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "prefix": "ANY", "enable_cxx": [True, False], "enable_fill": [True, False], "enable_xmalloc": [True, False], "enable_readlinkat": [True, False], "enable_syscall": [True, False], "enable_lazy_lock": [True, False], "enable_debug_logging": [True, False], "enable_initial_exec_tls": [True, False], "enable_libdl": [True, False], "enable_prof": [True, False], } default_options = { "shared": False, "fPIC": True, "prefix": "", "enable_cxx": True, "enable_fill": True, "enable_xmalloc": False, "enable_readlinkat": False, "enable_syscall": True, "enable_lazy_lock": False, "enable_debug_logging": False, "enable_initial_exec_tls": True, "enable_libdl": True, "enable_prof": False, } exports_sources = ["patches/**"] _autotools = None _source_subfolder = "source_subfolder" def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.enable_cxx and \ self.settings.compiler.get_safe("libcxx") == "libc++" and \ self.settings.compiler == "clang" and \ tools.Version(self.settings.compiler.version) < "10": raise ConanInvalidConfiguration( "clang and libc++ version {} (< 10) is missing a mutex implementation" .format(self.settings.compiler.version)) if self.settings.compiler == "Visual Studio" and \ self.options.shared and \ "MT" in self.settings.compiler.runtime: raise ConanInvalidConfiguration( "Visual Studio build for shared library with MT runtime is not supported" ) if self.settings.compiler == "Visual Studio" and self.settings.compiler.version != "15": # https://github.com/jemalloc/jemalloc/issues/1703 raise ConanInvalidConfiguration( "Only Visual Studio 15 2017 is supported. Please fix this if other versions are supported" ) if self.options.shared: del self.options.fPIC if not self.options.enable_cxx: del self.settings.compiler.libcxx del self.settings.compiler.cppstd if self.settings.build_type not in ("Release", "Debug", None): raise ConanInvalidConfiguration( "Only Release and Debug build_types are supported") if self.settings.compiler == "Visual Studio" and self.settings.arch not in ( "x86_64", "x86"): raise ConanInvalidConfiguration("Unsupported arch") if self.settings.compiler == "clang" and tools.Version( self.settings.compiler.version) <= "3.9": raise ConanInvalidConfiguration("Unsupported compiler version") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("{}-{}".format(self.name, self.version), self._source_subfolder) def build_requirements(self): if tools.os_info.is_windows and not os.environ.get( "CONAN_BASH_PATH", None): self.build_requires("msys2/20200517") @property def _autotools_args(self): conf_args = [ "--with-jemalloc-prefix={}".format(self.options.prefix), "--enable-debug" if self.settings.build_type == "Debug" else "--disable-debug", "--enable-cxx" if self.options.enable_cxx else "--disable-cxx", "--enable-fill" if self.options.enable_fill else "--disable-fill", "--enable-xmalloc" if self.options.enable_cxx else "--disable-xmalloc", "--enable-readlinkat" if self.options.enable_readlinkat else "--disable-readlinkat", "--enable-syscall" if self.options.enable_syscall else "--disable-syscall", "--enable-lazy-lock" if self.options.enable_lazy_lock else "--disable-lazy-lock", "--enable-log" if self.options.enable_debug_logging else "--disable-log", "--enable-initial-exec-tls" if self.options.enable_initial_exec_tls else "--disable-initial-exec-tls", "--enable-libdl" if self.options.enable_libdl else "--disable-libdl", ] if self.options.enable_prof: conf_args.append("--enable-prof") if self.options.shared: conf_args.extend(["--enable-shared", "--disable-static"]) else: conf_args.extend(["--disable-shared", "--enable-static"]) return conf_args def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) self._autotools.configure(args=self._autotools_args, configure_dir=self._source_subfolder) return self._autotools @property def _msvc_build_type(self): build_type = str(self.settings.build_type) or "Release" if not self.options.shared: build_type += "-static" return build_type def _patch_sources(self): if self.settings.os == "Windows": makefile_in = os.path.join(self._source_subfolder, "Makefile.in") tools.replace_in_file( makefile_in, "DSO_LDFLAGS = @DSO_LDFLAGS@", "DSO_LDFLAGS = @DSO_LDFLAGS@ -Wl,--out-implib,lib/libjemalloc.a" ) tools.replace_in_file( makefile_in, "\t$(INSTALL) -d $(LIBDIR)\n" "\t$(INSTALL) -m 755 $(objroot)lib/$(LIBJEMALLOC).$(SOREV) $(LIBDIR)", "\t$(INSTALL) -d $(BINDIR)\n" "\t$(INSTALL) -d $(LIBDIR)\n" "\t$(INSTALL) -m 755 $(objroot)lib/$(LIBJEMALLOC).$(SOREV) $(BINDIR)\n" "\t$(INSTALL) -m 644 $(objroot)lib/libjemalloc.a $(LIBDIR)") for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) def build(self): self._patch_sources() if self.settings.compiler == "Visual Studio": with tools.vcvars( self.settings ) if self.settings.compiler == "Visual Studio" else tools.no_op(): with tools.environment_append( { "CC": "cl", "CXX": "cl" } ) if self.settings.compiler == "Visual Studio" else tools.no_op( ): with tools.chdir(self._source_subfolder): # Do not use AutoToolsBuildEnvironment because we want to run configure as ./configure self.run("./configure {}".format(" ".join( self._autotools_args)), win_bash=tools.os_info.is_windows) msbuild = MSBuild(self) # Do not use the 2015 solution: unresolved external symbols: test_hooks_libc_hook and test_hooks_arena_new_hook sln_file = os.path.join(self._source_subfolder, "msvc", "jemalloc_vc2017.sln") msbuild.build(sln_file, targets=["jemalloc"], build_type=self._msvc_build_type) else: autotools = self._configure_autotools() autotools.make() @property def _library_name(self): libname = "jemalloc" if self.settings.compiler == "Visual Studio": if self.options.shared: if self.settings.build_type == "Debug": libname += "d" else: toolset = tools.msvs_toolset(self.settings) toolset_number = "".join(c for c in toolset if c in string.digits) libname += "-vc{}-{}".format(toolset_number, self._msvc_build_type) else: if self.settings.os == "Windows": if not self.options.shared: libname += "_s" else: if not self.options.shared and self.options.fPIC: libname += "_pic" return libname def package(self): self.copy(pattern="COPYING", src=self._source_subfolder, dst="licenses") if self.settings.compiler == "Visual Studio": arch_subdir = { "x86_64": "x64", "x86": "x86", }[str(self.settings.arch)] self.copy("*.lib", src=os.path.join(self._source_subfolder, "msvc", arch_subdir, self._msvc_build_type), dst=os.path.join(self.package_folder, "lib")) self.copy("*.dll", src=os.path.join(self._source_subfolder, "msvc", arch_subdir, self._msvc_build_type), dst=os.path.join(self.package_folder, "bin")) self.copy("jemalloc.h", src=os.path.join(self._source_subfolder, "include", "jemalloc"), dst=os.path.join(self.package_folder, "include", "jemalloc"), keep_path=True) shutil.copytree( os.path.join(self._source_subfolder, "include", "msvc_compat"), os.path.join(self.package_folder, "include", "msvc_compat")) else: autotools = self._configure_autotools() # Use install_lib_XXX and install_include to avoid mixing binaries and dll's autotools.make(target="install_lib_shared" if self.options. shared else "install_lib_static") autotools.make(target="install_include") if self.settings.os == "Windows" and self.settings.compiler == "gcc": os.rename( os.path.join(self.package_folder, "lib", "{}.lib".format(self._library_name)), os.path.join(self.package_folder, "lib", "lib{}.a".format(self._library_name))) if not self.options.shared: os.unlink( os.path.join(self.package_folder, "lib", "jemalloc.lib")) def package_id(self): if not self.settings.build_type: self.info.settings.build_type = "Release" def package_info(self): self.cpp_info.libs = [self._library_name] self.cpp_info.includedirs = [ os.path.join(self.package_folder, "include"), os.path.join(self.package_folder, "include", "jemalloc") ] if self.settings.compiler == "Visual Studio": self.cpp_info.includedirs.append( os.path.join(self.package_folder, "include", "msvc_compat")) if not self.options.shared: self.cpp_info.defines = ["JEMALLOC_EXPORT="] if self.settings.os == "Linux": self.cpp_info.system_libs.extend(["dl", "pthread", "rt"])
class Re2CConan(ConanFile): name = "re2c" description = "re2c is a free and open-source lexer generator for C, C++ and Go." topics = ("re2c", "lexer", "language", "tokenizer", "flex") url = "https://github.com/conan-io/conan-center-index" homepage = "http://re2c.org/" license = "Unlicense" settings = "os", "arch", "build_type", "compiler" exports_sources = "patches/**" _autotools = None @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): del self.settings.compiler.cppstd del self.settings.compiler.libcxx def package_id(self): del self.info.settings.compiler def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def build_requirements(self): if self._settings_build.os == "Windows" and not tools.get_env( "CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") @contextmanager def _build_context(self): if self.settings.compiler == "Visual Studio": with tools.vcvars(self): env = { "CC": "{} -nologo".format( tools.unix_path( os.path.join(self.build_folder, "msvc_cl.sh"))), "CXX": "{} -nologo".format( tools.unix_path( os.path.join(self.build_folder, "msvc_cl.sh"))), "LD": "{} -nologo".format( tools.unix_path( os.path.join(self.build_folder, "msvc_cl.sh"))), "CXXLD": "{} -nologo".format( tools.unix_path( os.path.join(self.build_folder, "msvc_cl.sh"))), "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) if self.settings.compiler == "Visual Studio": self._autotools.flags.append("-FS") self._autotools.cxx_flags.append("-EHsc") 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(args=["V=1"]) def package(self): self.copy("LICENSE", src=self._source_subfolder, dst="licenses", keep_path=False) self.copy("NO_WARRANTY", src=self._source_subfolder, dst="licenses", keep_path=False) with self._build_context(): 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 MpirConan(ConanFile): name = "mpir" description = "MPIR is a highly optimised library for bignum arithmetic" \ "forked from the GMP bignum library." topics = ("mpir", "multiprecision", "math", "mathematics") url = "https://github.com/conan-io/conan-center-index" homepage = "http://mpir.org/" license = "LGPL-3.0-or-later" provides = [] settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "enable_cxx": [True, False], "enable_gmpcompat": [True, False], } default_options = { "shared": False, "fPIC": True, "enable_cxx": True, "enable_gmpcompat": 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 _is_msvc(self): return str(self.settings.compiler) in ["Visual Studio", "msvc"] 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._is_msvc and self.options.shared: del self.options.enable_cxx if not self.options.get_safe("enable_cxx", False): del self.settings.compiler.libcxx del self.settings.compiler.cppstd if self.options.enable_gmpcompat: self.provides.append("gmp") def validate(self): if hasattr(self, "settings_build") and tools.cross_building( self, skip_x64_x86=True): raise ConanInvalidConfiguration( "Cross-building doesn't work (yet)") def build_requirements(self): self.build_requires("yasm/1.3.0") if not self._is_msvc: self.build_requires("m4/1.4.19") 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(keep_permissions=True, **self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder) @property def _platforms(self): return {"x86": "Win32", "x86_64": "x64"} @property def _dll_or_lib(self): return "dll" if self.options.shared else "lib" @property def _vcxproj_paths(self): compiler_version = self.settings.compiler.version if tools.Version( self.settings.compiler.version) < "16" else "15" build_subdir = "build.vc{}".format(compiler_version) vcxproj_paths = [ os.path.join(self._source_subfolder, build_subdir, "{}_mpir_gc".format(self._dll_or_lib), "{}_mpir_gc.vcxproj".format(self._dll_or_lib)) ] if self.options.get_safe("enable_cxx"): vcxproj_paths.append( os.path.join(self._source_subfolder, build_subdir, "lib_mpir_cxx", "lib_mpir_cxx.vcxproj")) return vcxproj_paths def _build_visual_studio(self): if not self.options.shared: # RuntimeLibrary only defined in lib props files build_type = "debug" if self.settings.build_type == "Debug" else "release" props_path = os.path.join(self._source_subfolder, "build.vc", "mpir_{}_lib.props".format(build_type)) old_runtime = "MultiThreaded{}".format( "Debug" if build_type == "debug" else "", ) new_runtime = "MultiThreaded{}{}".format( "Debug" if "d" in msvc_runtime_flag(self) else "", "DLL" if "MD" in msvc_runtime_flag(self) else "", ) tools.replace_in_file(props_path, old_runtime, new_runtime) msbuild = MSBuild(self) for vcxproj_path in self._vcxproj_paths: msbuild.build(vcxproj_path, platforms=self._platforms, upgrade_project=False) @contextlib.contextmanager def _build_context(self): if self.settings.compiler == "apple-clang": env_build = { "CC": tools.XCRun(self.settings).cc, "CXX": tools.XCRun(self.settings).cxx } if hasattr(self, "settings_build"): # there is no CFLAGS_FOR_BUILD/CXXFLAGS_FOR_BUILD xcrun = tools.XCRun(self.settings_build) flags = " -Wno-implicit-function-declaration -isysroot {} -arch {}".format( xcrun.sdk_path, tools.to_apple_arch(self.settings_build.arch)) env_build["CC_FOR_BUILD"] = xcrun.cc + flags env_build["CXX_FOR_BUILD"] = xcrun.cxx + flags with tools.environment_append(env_build): yield else: yield def _configure_autotools(self): if not self._autotools: self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) 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("--disable-silent-rules") args.append("--enable-cxx" if self.options. get_safe("enable_cxx") else "--disable-cxx") args.append("--enable-gmpcompat" if self.options. enable_gmpcompat else "--disable-gmpcompat") # compiler checks are written for C89 but compilers that default to C99 treat implicit functions as error self._autotools.flags.append("-Wno-implicit-function-declaration") self._autotools.configure(args=args) return self._autotools def build(self): if self._is_msvc: self._build_visual_studio() else: with tools.chdir(self._source_subfolder), self._build_context(): # relocatable shared lib on macOS tools.replace_in_file("configure", "-install_name \\$rpath/", "-install_name @rpath/") autotools = self._configure_autotools() autotools.make() def package(self): self.copy("COPYING*", dst="licenses", src=self._source_subfolder) if self._is_msvc: lib_folder = os.path.join( self._source_subfolder, self._dll_or_lib, self._platforms.get(str(self.settings.arch)), str(self.settings.build_type)) self.copy("mpir.h", dst="include", src=lib_folder, keep_path=True) if self.options.enable_gmpcompat: self.copy("gmp.h", dst="include", src=lib_folder, keep_path=True) if self.options.get_safe("enable_cxx"): self.copy("mpirxx.h", dst="include", src=lib_folder, keep_path=True) if self.options.enable_gmpcompat: self.copy("gmpxx.h", dst="include", src=lib_folder, keep_path=True) self.copy(pattern="*.dll*", dst="bin", src=lib_folder, keep_path=False) self.copy(pattern="*.lib", dst="lib", src=lib_folder, keep_path=False) else: with tools.chdir(self._source_subfolder), self._build_context(): 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): if self.options.get_safe("enable_cxx"): self.cpp_info.libs.append("mpirxx") self.cpp_info.libs.append("mpir") if self.options.enable_gmpcompat and not self._is_msvc: if self.options.get_safe("enable_cxx"): self.cpp_info.libs.append("gmpxx") self.cpp_info.libs.append("gmp") if self.settings.os == "Windows" and self.options.shared: self.cpp_info.defines.append("MSC_USE_DLL")
class GmpConan(ConanFile): name = "gmp" description = "GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers." url = "https://github.com/conan-io/conan-center-index" topics = ("conan", "gmp", "math") license = ("LGPL-3.0", "GPL-2.0") homepage = "https://gmplib.org" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "disable_assembly": [True, False], "run_checks": [True, False], "enable_cxx": [True, False] } default_options = { "shared": False, "fPIC": True, "disable_assembly": True, "run_checks": False, "enable_cxx": True } _source_subfolder = "source_subfolder" _autotools = None def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.settings.compiler == "Visual Studio": raise ConanInvalidConfiguration( "The gmp package cannot be built on Visual Studio.") if self.options.shared: del self.options.fPIC if not self.options.enable_cxx: del self.settings.compiler.libcxx del self.settings.compiler.cppstd def package_id(self): del self.info.options.run_checks # run_checks doesn't affect package's ID def build_requirements(self): if tools.os_info.is_windows and self.settings.compiler != "Visual Studio" and \ "CONAN_BASH_PATH" not in os.environ and tools.os_info.detect_windows_subsystem() != "msys2": self.build_requires("msys2/20200517") def source(self): tools.get(**self.conan_data["sources"][self.version]) os.rename("gmp-" + self.version, self._source_subfolder) def _configure_autotools(self): if not self._autotools: self._autotools = AutoToolsBuildEnvironment( self, win_bash=tools.os_info.is_windows) if self.settings.os == "Macos": configure_file = "configure" tools.replace_in_file(configure_file, r"-install_name \$rpath/", "-install_name ") configure_stats = os.stat(configure_file) os.chmod(configure_file, configure_stats.st_mode | stat.S_IEXEC) configure_args = [] if self.options.disable_assembly: configure_args.append("--disable-assembly") if self.options.shared: configure_args.extend(["--enable-shared", "--disable-static"]) else: configure_args.extend(["--disable-shared", "--enable-static"]) if self.options.enable_cxx: configure_args.append("--enable-cxx") self._autotools.configure(args=configure_args) return self._autotools def build(self): with tools.chdir(self._source_subfolder): autotools = self._configure_autotools() autotools.make() # INFO: According to the gmp readme file, make check should not be omitted, but it causes timeouts on the CI server. if self.options.run_checks: autotools.make(args=["check"]) def package(self): self.copy("COPYINGv2", dst="licenses", src=self._source_subfolder) self.copy("COPYING.LESSERv3", 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, "lib", "pkgconfig")) tools.rmdir(os.path.join(self.package_folder, "share")) os.unlink(os.path.join(self.package_folder, "lib", "libgmp.la")) if self.options.enable_cxx: os.unlink(os.path.join(self.package_folder, "lib", "libgmpxx.la")) def package_info(self): self.cpp_info.components["libgmp"].libs = ["gmp"] self.cpp_info.components["libgmp"].names["cmake_find_package"] = "GMP" self.cpp_info.components["libgmp"].names[ "cmake_find_package_multi"] = "GMP" self.cpp_info.components["libgmp"].names["pkg_config"] = "gmp" if self.options.enable_cxx: self.cpp_info.components["gmpxx"].libs = ["gmpxx"] self.cpp_info.components["gmpxx"].requires = ["libgmp"] self.cpp_info.components["gmpxx"].names[ "cmake_find_package"] = "GMPXX" self.cpp_info.components["gmpxx"].names[ "cmake_find_package_multi"] = "GMPXX" self.cpp_info.components["gmpxx"].names["pkg_config"] = "gmpxx"
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], "enable_udev": [True, False], "fPIC": [True, False] } default_options = {"shared": False, "enable_udev": True, "fPIC": 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" def source(self): tools.get(**self.conan_data["sources"][self.version]) extracted_folder = self.name + "-" + self.version os.rename(extracted_folder, self._source_subfolder) def configure(self): if self.options.shared: del self.options.fPIC del self.settings.compiler.libcxx del self.settings.compiler.cppstd def config_options(self): if self.settings.os != "Linux": del self.options.enable_udev if self.settings.os == "Windows": del self.options.fPIC def build_requirements(self): if tools.os_info.is_windows and self.settings.compiler != "Visual Studio" and \ not tools.get_env("CONAN_BASH_PATH") and tools.os_info.detect_windows_subsystem() != "msys2": self.build_requires("msys2/20200517") def system_requirements(self): if self.settings.os == "Linux": if self.options.enable_udev: package_tool = tools.SystemPackageTool(conanfile=self) libudev_name = "" os_info = tools.OSInfo() if os_info.with_apt: libudev_name = "libudev-dev" elif os_info.with_yum: libudev_name = "libudev-devel" elif os_info.with_zypper: libudev_name = "libudev-devel" elif os_info.with_pacman: libudev_name = "libsystemd systemd" else: self.output.warn( "Could not install libudev: Undefined package name for current platform." ) return package_tool.install(packages=libudev_name, update=True) def _build_visual_studio(self): with tools.chdir(self._source_subfolder): solution_file = "libusb_2017.sln" if self.settings.compiler.version == "14": solution_file = "libusb_2015.sln" if self.settings.compiler.version == "12": solution_file = "libusb_2013.sln" elif self.settings.compiler.version == "11": solution_file = "libusb_2012.sln" solution_file = os.path.join("msvc", solution_file) platforms = {"x86": "Win32"} msbuild = MSBuild(self) msbuild.build(solution_file, platforms=platforms, upgrade_project=False) 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 == "Linux": 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: 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")) la_file = os.path.join(self.package_folder, "lib", "libusb-1.0.la") if os.path.isfile(la_file): os.remove(la_file) 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 == "Linux": self.cpp_info.system_libs.append("pthread") if self.options.enable_udev: self.cpp_info.system_libs.append("udev") elif self.settings.os == "Macos": self.cpp_info.system_libs = ["objc"] self.cpp_info.frameworks = ["IOKit", "CoreFoundation"] elif self.settings.os == "Windows": self.cpp_info.system_libs = ["advapi32"]
def build(self): env_build = AutoToolsBuildEnvironment(self) env_build.configure(configure_dir="cmake-3.10.2",args=[ '--prefix=`pwd`/build' ]) env_build.make()
def build(self): env_build = AutoToolsBuildEnvironment(self) env_build.make()