|
| 1 | +from conan import ConanFile |
| 2 | + |
| 3 | +from conan.errors import ConanInvalidConfiguration |
| 4 | +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout |
| 5 | +from conan.tools.build import check_min_cppstd |
| 6 | +from conan.tools.files import copy, get |
| 7 | +from conan.tools.microsoft import check_min_vs, is_msvc |
| 8 | + |
| 9 | +import os |
| 10 | + |
| 11 | +required_conan_version = ">=1.47.0" |
| 12 | + |
| 13 | +class CppfrontConan(ConanFile): |
| 14 | + name = "cppfront" |
| 15 | + description = "Cppfront is a experimental compiler from a potential C++ 'syntax 2' (Cpp2) to today's 'syntax 1' (Cpp1)" |
| 16 | + topics = ("cpp2") |
| 17 | + url = "https://github.com/conan-io/conan-center-index" |
| 18 | + homepage = "https://github.com/hsutter/cppfront" |
| 19 | + license = "CC-BY-NC-ND-4.0" |
| 20 | + settings = "os", "arch", "compiler", "build_type" |
| 21 | + |
| 22 | + @property |
| 23 | + def _minimum_cpp_standard(self): |
| 24 | + return 20 |
| 25 | + |
| 26 | + @property |
| 27 | + def _compilers_minimum_version(self): |
| 28 | + return {"gcc": "11", |
| 29 | + "Visual Studio": "16.9", |
| 30 | + "clang": "12", |
| 31 | + "apple-clang": "13", |
| 32 | + } |
| 33 | + |
| 34 | + def layout(self): |
| 35 | + cmake_layout(self, src_folder="src") |
| 36 | + |
| 37 | + def export_sources(self): |
| 38 | + copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, "src")) |
| 39 | + |
| 40 | + def source(self): |
| 41 | + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) |
| 42 | + |
| 43 | + def validate(self): |
| 44 | + if self.info.settings.compiler.cppstd: |
| 45 | + check_min_cppstd(self, self._minimum_cpp_standard) |
| 46 | + |
| 47 | + def _lazy_lt_semver(v1, v2): |
| 48 | + lv1 = [int(v) for v in v1.split(".")] |
| 49 | + lv2 = [int(v) for v in v2.split(".")] |
| 50 | + min_length = min(len(lv1), len(lv2)) |
| 51 | + return lv1[:min_length] < lv2[:min_length] |
| 52 | + |
| 53 | + check_min_vs(self, "192.9") |
| 54 | + if not is_msvc(self): |
| 55 | + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) |
| 56 | + if not minimum_version: |
| 57 | + self.output.warn(f"{self.name} {self.version} requires C++20. Your compiler is unknown. Assuming it supports C++20.") |
| 58 | + elif _lazy_lt_semver(str(self.settings.compiler.version), minimum_version): |
| 59 | + raise ConanInvalidConfiguration(f"{self.name} {self.version} requires C++20, which your compiler does not support.") |
| 60 | + if self.info.settings.compiler == "clang" and str(self.info.settings.compiler.version) in ("13", "14"): |
| 61 | + raise ConanInvalidConfiguration(f"{self.ref} currently does not work with Clang {self.info.settings.compiler.version} on CCI, it enters in an infinite build loop (smells like a compiler bug). Contributions are welcomed!") |
| 62 | + |
| 63 | + def generate(self): |
| 64 | + tc = CMakeToolchain(self) |
| 65 | + tc.generate() |
| 66 | + |
| 67 | + def build(self): |
| 68 | + cmake = CMake(self) |
| 69 | + cmake.configure() |
| 70 | + cmake.build() |
| 71 | + |
| 72 | + def package(self): |
| 73 | + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) |
| 74 | + copy(self, "cppfront*", src=self.source_folder, dst=os.path.join(self.package_folder, "bin")) |
| 75 | + copy(self, pattern="*.h", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include")) |
| 76 | + |
| 77 | + cmake = CMake(self) |
| 78 | + cmake.install() |
| 79 | + |
| 80 | + @staticmethod |
| 81 | + def _chmod_plus_x(filename): |
| 82 | + if os.name == "posix": |
| 83 | + os.chmod(filename, os.stat(filename).st_mode | 0o111) |
| 84 | + |
| 85 | + def package_info(self): |
| 86 | + bin_path = os.path.join(self.package_folder, "bin") |
| 87 | + self.output.info(f"Appending PATH environment variable: {bin_path}") |
| 88 | + self.env_info.PATH.append(bin_path) |
| 89 | + |
| 90 | + bin_ext = ".exe" if self.settings.os == "Windows" else "" |
| 91 | + cppfront_bin = os.path.join(self.package_folder, "bin", "cppfront{}".format(bin_ext)).replace("\\", "/") |
| 92 | + |
| 93 | + # CppFront environment variable is used by a lot of scripts as a way to override a hard-coded embedded m4 path |
| 94 | + self.output.info("Setting CppFront environment variable: {}".format(cppfront_bin)) |
| 95 | + self.env_info.cppfront = cppfront_bin |
| 96 | + |
| 97 | + self.cpp_info.frameworkdirs = [] |
| 98 | + self.cpp_info.includedirs = [] |
| 99 | + self.cpp_info.libdirs = [] |
| 100 | + self.cpp_info.resdirs = [] |
| 101 | + |
0 commit comments