|
| 1 | +import os |
| 2 | +import re |
| 3 | + |
| 4 | +from conan import ConanFile |
| 5 | +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout |
| 6 | +from conan.tools.files import copy, load, rmdir |
| 7 | + |
| 8 | +required_conan_version = ">=2.0.0" |
| 9 | + |
| 10 | + |
| 11 | +class FtxuiConan(ConanFile): |
| 12 | + name = "ftxui" |
| 13 | + description = "C++ Functional Terminal User Interface." |
| 14 | + license = "MIT" |
| 15 | + url = "https://github.com/ArthurSonzogni/FTXUI" |
| 16 | + homepage = "https://github.com/ArthurSonzogni/FTXUI" |
| 17 | + topics = ("terminal", "tui", "cli", "console", "functional") |
| 18 | + package_type = "library" |
| 19 | + settings = "os", "arch", "compiler", "build_type" |
| 20 | + options = { |
| 21 | + "shared": [True, False], |
| 22 | + "fPIC": [True, False], |
| 23 | + } |
| 24 | + default_options = { |
| 25 | + "shared": False, |
| 26 | + "fPIC": True, |
| 27 | + } |
| 28 | + |
| 29 | + exports_sources = ( |
| 30 | + "CMakeLists.txt", |
| 31 | + "cmake/*", |
| 32 | + "include/*", |
| 33 | + "src/*", |
| 34 | + "ftxui.pc.in", |
| 35 | + "LICENSE", |
| 36 | + # CMakeLists.txt unconditionally add_subdirectory()s these two |
| 37 | + # directories; each one's own CMakeLists.txt returns immediately |
| 38 | + # when its FTXUI_BUILD_* option is off, so nothing else from |
| 39 | + # examples/ or doc/ needs to be exported. |
| 40 | + "examples/CMakeLists.txt", |
| 41 | + "doc/CMakeLists.txt", |
| 42 | + ) |
| 43 | + |
| 44 | + def set_version(self): |
| 45 | + cmake_lists = load(self, os.path.join(self.recipe_folder, "CMakeLists.txt")) |
| 46 | + match = re.search(r"project\(\s*ftxui.*?VERSION\s+(\S+)", cmake_lists, re.DOTALL) |
| 47 | + self.version = match.group(1) |
| 48 | + |
| 49 | + def config_options(self): |
| 50 | + if self.settings.os == "Windows": |
| 51 | + self.options.rm_safe("fPIC") |
| 52 | + |
| 53 | + def configure(self): |
| 54 | + if self.options.shared: |
| 55 | + self.options.rm_safe("fPIC") |
| 56 | + |
| 57 | + def layout(self): |
| 58 | + cmake_layout(self, src_folder=".") |
| 59 | + |
| 60 | + def generate(self): |
| 61 | + tc = CMakeToolchain(self) |
| 62 | + tc.variables["BUILD_SHARED_LIBS"] = bool(self.options.shared) |
| 63 | + tc.variables["FTXUI_BUILD_DOCS"] = False |
| 64 | + tc.variables["FTXUI_BUILD_EXAMPLES"] = False |
| 65 | + tc.variables["FTXUI_BUILD_MODULES"] = False |
| 66 | + tc.variables["FTXUI_BUILD_TESTS"] = False |
| 67 | + tc.variables["FTXUI_BUILD_TESTS_FUZZER"] = False |
| 68 | + tc.variables["FTXUI_ENABLE_INSTALL"] = True |
| 69 | + tc.variables["FTXUI_QUIET"] = True |
| 70 | + tc.generate() |
| 71 | + |
| 72 | + def build(self): |
| 73 | + cmake = CMake(self) |
| 74 | + cmake.configure() |
| 75 | + cmake.build() |
| 76 | + |
| 77 | + def package(self): |
| 78 | + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) |
| 79 | + cmake = CMake(self) |
| 80 | + cmake.install() |
| 81 | + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) |
| 82 | + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) |
| 83 | + |
| 84 | + def package_info(self): |
| 85 | + self.cpp_info.set_property("cmake_file_name", "ftxui") |
| 86 | + |
| 87 | + self.cpp_info.components["screen"].set_property("cmake_target_name", "ftxui::screen") |
| 88 | + self.cpp_info.components["screen"].libs = ["ftxui-screen"] |
| 89 | + |
| 90 | + self.cpp_info.components["dom"].set_property("cmake_target_name", "ftxui::dom") |
| 91 | + self.cpp_info.components["dom"].libs = ["ftxui-dom"] |
| 92 | + self.cpp_info.components["dom"].requires = ["screen"] |
| 93 | + |
| 94 | + self.cpp_info.components["component"].set_property("cmake_target_name", "ftxui::component") |
| 95 | + self.cpp_info.components["component"].libs = ["ftxui-component"] |
| 96 | + self.cpp_info.components["component"].requires = ["dom"] |
0 commit comments