from conan import ConanFile from conan.tools.cmake import CMake, CMakeToolchain from conan.tools.files import get, replace_in_file, load import os import re class Lz4Conan(ConanFile): name = "lz4" version = "1.10.0" settings = "os", "compiler", "arch", "build_type" def source(self): # Скачиваем исходники url = f"https://github.com/lz4/lz4/archive/refs/tags/v{self.version}.tar.gz" get(self, url, strip_root=True) # Находим CMakeLists.txt в правильном месте cmakelists_path = os.path.join(self.source_folder, "build", "cmake", "CMakeLists.txt") if not os.path.exists(cmakelists_path): # Для более новых версий lz4 путь может быть другим cmakelists_path = os.path.join(self.source_folder, "CMakeLists.txt") # Применяем исправление для VS2022 if os.path.exists(cmakelists_path): content = load(self, cmakelists_path) # Добавляем исправление, если его еще нет if "CMP0091" not in content: # Ищем место для вставки после cmake_minimum_required new_content = re.sub( r'(cmake_minimum_required\(VERSION [\d.]+\))', r'\1\n\n# Fix for VS2022\ncmake_policy(SET CMP0091 NEW)', content ) with open(cmakelists_path, "w", encoding="utf-8") as f: f.write(new_content) self.output.info("Applied VS2022 fix to CMakeLists.txt") def generate(self): tc = CMakeToolchain(self) # Явно указываем генератор для VS2022 if self.settings.compiler == "msvc" and self.settings.compiler.version == "193": tc.generator = "Visual Studio 17 2022" # Дополнительные настройки для MSVC tc.preprocessor_definitions["_CRT_SECURE_NO_WARNINGS"] = "1" tc.variables["CMAKE_MSVC_RUNTIME_LIBRARY"] = "MultiThreaded$<$:Debug>" tc.generate() def build(self): cmake = CMake(self) # Автоматически определяем папку со скриптами CMake if os.path.exists(os.path.join(self.source_folder, "build", "cmake")): cmake.configure(build_script_folder=os.path.join("build", "cmake")) else: cmake.configure() cmake.build() def package(self): cmake = CMake(self) cmake.install() def package_info(self): self.cpp_info.libs = ["lz4"]