|
| 1 | +import re |
| 2 | + |
| 3 | +from conan import ConanFile |
| 4 | +from conan.tools.build import check_min_cppstd, can_run |
| 5 | +from conan.tools.cmake import cmake_layout, CMakeToolchain, CMakeDeps, CMake |
| 6 | +from conan.tools.files import apply_conandata_patches, copy |
| 7 | +from conan.tools.scm import Git |
| 8 | +import os |
| 9 | +import shutil |
| 10 | + |
| 11 | +required_conan_version = ">=2.0.9" |
| 12 | + |
| 13 | +class MoltenVKConan(ConanFile): |
| 14 | + name = "molten-vk" |
| 15 | + description = "molten vk (vulkan driver on macos)" |
| 16 | + license = "https://github.com/KhronosGroup/MoltenVK?tab=Apache-2.0-1-ov-file" |
| 17 | + url = "https://github.com/conan-io/conan-center-index" |
| 18 | + homepage = "https://github.com/KhronosGroup/MoltenVK" |
| 19 | + topics = ("vulkan", "driver", "macos") |
| 20 | + package_type = "shared-library" |
| 21 | + settings = "os", "arch", "compiler", "build_type" |
| 22 | + options = {} |
| 23 | + default_options = {} |
| 24 | + |
| 25 | + def layout(self): |
| 26 | + cmake_layout(self, src_folder="src") |
| 27 | + |
| 28 | + def validate(self): |
| 29 | + check_min_cppstd(self, 17) |
| 30 | + |
| 31 | + def build_requirements(self): |
| 32 | + self.tool_requires("ninja/[>=1.12]") |
| 33 | + self.tool_requires("cmake/[>=3.16]") |
| 34 | + |
| 35 | + def source(self): |
| 36 | + git = Git(self) |
| 37 | + git.clone("https://github.com/KhronosGroup/MoltenVK", target=".") |
| 38 | + git.checkout(self.conan_data["sources"][self.version]["commit"]) |
| 39 | + apply_conandata_patches(self) |
| 40 | + |
| 41 | + def generate(self): |
| 42 | + cmake_toolchain = CMakeToolchain(self, generator="Ninja") |
| 43 | + cmake_toolchain.generate() |
| 44 | + |
| 45 | + deps = CMakeDeps(self) |
| 46 | + deps.generate() |
| 47 | + |
| 48 | + def build(self): |
| 49 | + cmake = CMake(self) |
| 50 | + install_folder = os.path.join(self.build_folder, "installed") |
| 51 | + cmake.configure(cli_args=[f"-DCMAKE_INSTALL_PREFIX={install_folder}"]) |
| 52 | + cmake.build() |
| 53 | + cmake.install(cli_args=["--prefix", install_folder]) |
| 54 | + |
| 55 | + lib_root = os.path.join(install_folder, "lib") |
| 56 | + for entry in os.listdir(lib_root): |
| 57 | + entry_path = os.path.join(lib_root, entry) |
| 58 | + if os.path.isdir(entry_path): |
| 59 | + shutil.rmtree(entry_path) |
| 60 | + elif os.path.islink(entry_path): |
| 61 | + os.remove(entry_path) |
| 62 | + elif entry.startswith("libMoltenVK"): |
| 63 | + os.rename(entry_path, os.path.join(lib_root, "libMoltenVK.dylib")) |
| 64 | + |
| 65 | + icd_descriptor_json = os.path.join(install_folder, "etc", "vulkan", "icd.d", "MoltenVK_icd.json") |
| 66 | + new_icd_descriptor_json = os.path.join(install_folder, "lib", "MoltenVK_icd.json") |
| 67 | + with open(icd_descriptor_json, "r") as file: |
| 68 | + content = file.read() |
| 69 | + new_content = re.sub(r"\"library_path\": \".+\"", "\"library_path\": \"libMoltenVK.dylib\"", content) |
| 70 | + with open(new_icd_descriptor_json, "w") as file: |
| 71 | + file.write(new_content) |
| 72 | + |
| 73 | + def package(self): |
| 74 | + install_folder = os.path.join(self.build_folder, "installed") |
| 75 | + copy(self, "*", install_folder, self.package_folder) |
| 76 | + os.mkdir(os.path.join(self.package_folder, "include")) |
| 77 | + |
| 78 | + def package_info(self): |
| 79 | + self.cpp_info.set_property("cmake_file_name", "MoltenVK") |
| 80 | + self.cpp_info.bindirs = ["bin"] |
| 81 | + self.cpp_info.includedirs = ["include"] |
| 82 | + self.cpp_info.libs = [] |
| 83 | + self.cpp_info.libdirs = [] |
| 84 | + |
| 85 | + def test(self): |
| 86 | + if can_run(self): |
| 87 | + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") |
| 88 | + self.run(bin_path, env="conanrun") |
0 commit comments