|
| 1 | +import os |
| 2 | +from conans import ConanFile, CMake, tools |
| 3 | +from conans.errors import ConanInvalidConfiguration |
| 4 | + |
| 5 | +required_conan_version = ">=1.28.0" |
| 6 | + |
| 7 | + |
| 8 | +class SentryCrashpadConan(ConanFile): |
| 9 | + name = "sentry-crashpad" |
| 10 | + description = "Crashpad is a crash-reporting system." |
| 11 | + url = "https://github.com/conan-io/conan-center-index" |
| 12 | + homepage = "https://github.com/getsentry/sentry-native" |
| 13 | + license = "Apache-2.0" |
| 14 | + topics = ("conan", "crashpad", "error-reporting", "crash-reporting") |
| 15 | + provides = "crashpad", "mini_chromium" |
| 16 | + settings = "os", "arch", "compiler", "build_type" |
| 17 | + options = { |
| 18 | + "fPIC": [True, False], |
| 19 | + "with_tls": ["openssl", False], |
| 20 | + } |
| 21 | + default_options = { |
| 22 | + "fPIC": True, |
| 23 | + "with_tls": "openssl", |
| 24 | + } |
| 25 | + exports_sources = "CMakeLists.txt", "patches/*" |
| 26 | + generators = "cmake" |
| 27 | + |
| 28 | + _cmake = None |
| 29 | + |
| 30 | + @property |
| 31 | + def _source_subfolder(self): |
| 32 | + return "source_subfolder" |
| 33 | + |
| 34 | + def config_options(self): |
| 35 | + if self.settings.os == "Windows": |
| 36 | + del self.options.fPIC |
| 37 | + if self.settings.os not in ("Linux", "Android") or tools.Version(self.version) < "0.4": |
| 38 | + del self.options.with_tls |
| 39 | + |
| 40 | + def requirements(self): |
| 41 | + self.requires("zlib/1.2.11") |
| 42 | + if self.options.get_safe("with_tls"): |
| 43 | + self.requires("openssl/1.1.1k") |
| 44 | + |
| 45 | + def validate(self): |
| 46 | + if self.settings.compiler.cppstd: |
| 47 | + tools.check_min_cppstd(self, 11) |
| 48 | + |
| 49 | + if tools.is_apple_os(self.settings.os): |
| 50 | + # FIXME: add Apple support |
| 51 | + raise ConanInvalidConfiguration("This recipe does not support Apple.") |
| 52 | + |
| 53 | + if self.settings.os == "Linux": |
| 54 | + if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < 5: |
| 55 | + # FIXME: need to test for availability of SYS_memfd_create syscall (Linux kernel >= 3.17) |
| 56 | + raise ConanInvalidConfiguration("sentry-crashpad needs SYS_memfd_create syscall support.") |
| 57 | + |
| 58 | + if self.settings.compiler == "Visual Studio" and tools.Version(self.settings.compiler.version) < 15: |
| 59 | + raise ConanInvalidConfiguration("Require at least Visual Studio 2017 (15)") |
| 60 | + |
| 61 | + def source(self): |
| 62 | + tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder) |
| 63 | + |
| 64 | + def _configure_cmake(self): |
| 65 | + if self._cmake: |
| 66 | + return self._cmake |
| 67 | + self._cmake = CMake(self) |
| 68 | + self._cmake.definitions["CRASHPAD_ENABLE_INSTALL"] = True |
| 69 | + self._cmake.definitions["CRASHPAD_ENABLE_INSTALL_DEV"] = True |
| 70 | + self._cmake.definitions["CRASHPAD_ZLIB_SYSTEM"] = True |
| 71 | + self._cmake.configure() |
| 72 | + return self._cmake |
| 73 | + |
| 74 | + def build(self): |
| 75 | + for patch in self.conan_data.get("patches", {}).get(self.version, []): |
| 76 | + tools.patch(**patch) |
| 77 | + if tools.Version(self.version) > "0.4": |
| 78 | + openssl_repl = "find_package(OpenSSL REQUIRED)" if self.options.get_safe("with_tls") else "" |
| 79 | + tools.replace_in_file(os.path.join(self._source_subfolder, "external", "crashpad", "CMakeLists.txt"), |
| 80 | + "find_package(OpenSSL)", openssl_repl) |
| 81 | + cmake = self._configure_cmake() |
| 82 | + cmake.build() |
| 83 | + |
| 84 | + def package(self): |
| 85 | + self.copy("LICENSE", dst="licenses", src=os.path.join(self._source_subfolder, "external", "crashpad")) |
| 86 | + cmake = self._configure_cmake() |
| 87 | + cmake.install() |
| 88 | + |
| 89 | + tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) |
| 90 | + tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb") |
| 91 | + |
| 92 | + def package_info(self): |
| 93 | + self.cpp_info.names["cmake_find_package"] = "crashpad" |
| 94 | + self.cpp_info.names["cmake_find_package_multi"] = "crashpad" |
| 95 | + self.cpp_info.filenames["cmake_find_package"] = "crashpad" |
| 96 | + self.cpp_info.filenames["cmake_find_package_multi"] = "crashpad" |
| 97 | + |
| 98 | + self.cpp_info.components["mini_chromium"].includedirs.append(os.path.join("include", "crashpad", "mini_chromium")) |
| 99 | + self.cpp_info.components["mini_chromium"].libs = ["mini_chromium"] |
| 100 | + if self.settings.os in ("Linux", "FreeBSD"): |
| 101 | + self.cpp_info.components["mini_chromium"].system_libs.append("pthread") |
| 102 | + |
| 103 | + self.cpp_info.components["compat"].includedirs.append(os.path.join("include", "crashpad")) |
| 104 | + self.cpp_info.components["compat"].libs = ["crashpad_compat"] |
| 105 | + if self.settings.os in ("Linux", "FreeBSD"): |
| 106 | + self.cpp_info.components["compat"].system_libs.append("dl") |
| 107 | + |
| 108 | + self.cpp_info.components["util"].libs = ["crashpad_util"] |
| 109 | + self.cpp_info.components["util"].requires = ["compat", "mini_chromium", "zlib::zlib"] |
| 110 | + if self.settings.os in ("Linux", "FreeBSD"): |
| 111 | + self.cpp_info.components["util"].system_libs.extend(["pthread", "rt"]) |
| 112 | + if self.options.get_safe("with_tls") == "openssl": |
| 113 | + self.cpp_info.components["util"].requires.append("openssl::openssl") |
| 114 | + |
| 115 | + self.cpp_info.components["client"].libs = ["crashpad_client"] |
| 116 | + self.cpp_info.components["client"].requires = ["util", "mini_chromium"] |
| 117 | + |
| 118 | + self.cpp_info.components["snapshot"].libs = ["crashpad_snapshot"] |
| 119 | + self.cpp_info.components["snapshot"].requires = ["client", "compat", "util", "mini_chromium"] |
| 120 | + |
| 121 | + self.cpp_info.components["minidump"].libs = ["crashpad_minidump"] |
| 122 | + self.cpp_info.components["minidump"].requires = ["compat", "snapshot", "util", "mini_chromium"] |
| 123 | + |
| 124 | + if tools.Version(self.version) > "0.3": |
| 125 | + self.cpp_info.components["handler"].libs = ["crashpad_handler_lib"] |
| 126 | + self.cpp_info.components["handler"].requires = ["compat", "minidump", "snapshot", "util", "mini_chromium"] |
| 127 | + |
| 128 | + self.cpp_info.components["tools"].libs = ["crashpad_tools"] |
| 129 | + |
| 130 | + bin_path = os.path.join(self.package_folder, "bin") |
| 131 | + self.output.info("Appending PATH environment variable: {}".format(bin_path)) |
| 132 | + self.env_info.PATH.append(bin_path) |
0 commit comments