|
| 1 | +from conans import ConanFile |
| 2 | +from conan.tools.cmake import CMakeDeps, CMake, CMakeToolchain |
| 3 | +from conans.tools import save, load |
| 4 | +import os |
| 5 | +import pathlib |
| 6 | +import subprocess |
| 7 | +from rules_support import PluginBranchInfo |
| 8 | + |
| 9 | +class MEViewConan(ConanFile): |
| 10 | + """Class to package using conan |
| 11 | +
|
| 12 | + Packages both RELEASE and RELWITHDEBINFO. |
| 13 | + Uses rules_support (github.com/ManiVaultStudio/rulessupport) to derive |
| 14 | + versioninfo based on the branch naming convention |
| 15 | + as described in https://github.com/ManiVaultStudio/core/wiki/Branch-naming-rules |
| 16 | + """ |
| 17 | + |
| 18 | + name = "MEView" |
| 19 | + description = """Viewer of cell morphology data and associated ephys traces.""" |
| 20 | + topics = ("manivault", "plugin", "view", "morphology", "ephys") |
| 21 | + url = "https://github.com/ManiVaultStudio/MEView" |
| 22 | + author = "[email protected]" # conan recipe author |
| 23 | + license = "LGPL 3.0" |
| 24 | + |
| 25 | + short_paths = True |
| 26 | + generators = "CMakeDeps" |
| 27 | + |
| 28 | + # Options may need to change depending on the packaged library |
| 29 | + settings = {"os": None, "build_type": None, "compiler": None, "arch": None} |
| 30 | + options = {"shared": [True, False], "fPIC": [True, False]} |
| 31 | + default_options = {"shared": True, "fPIC": True} |
| 32 | + |
| 33 | + # Data plugin dependencies |
| 34 | + requires = ("CellMorphologyData/bican_bg@lkeb/stable", "EphysData/bican_bg@lkeb/stable") |
| 35 | + |
| 36 | + # Qt requirement is inherited from hdps-core |
| 37 | + |
| 38 | + scm = { |
| 39 | + "type": "git", |
| 40 | + "subfolder": "hdps/MEView", |
| 41 | + "url": "auto", |
| 42 | + "revision": "auto", |
| 43 | + } |
| 44 | + |
| 45 | + def __get_git_path(self): |
| 46 | + path = load( |
| 47 | + pathlib.Path(pathlib.Path(__file__).parent.resolve(), "__gitpath.txt") |
| 48 | + ) |
| 49 | + print(f"git info from {path}") |
| 50 | + return path |
| 51 | + |
| 52 | + def export(self): |
| 53 | + print("In export") |
| 54 | + # save the original source path to the directory used to build the package |
| 55 | + save( |
| 56 | + pathlib.Path(self.export_folder, "__gitpath.txt"), |
| 57 | + str(pathlib.Path(__file__).parent.resolve()), |
| 58 | + ) |
| 59 | + |
| 60 | + def set_version(self): |
| 61 | + # Assign a version from the branch name |
| 62 | + branch_info = PluginBranchInfo(self.recipe_folder) |
| 63 | + self.version = branch_info.version |
| 64 | + # print(f"Got version: {self.version}") |
| 65 | + |
| 66 | + def requirements(self): |
| 67 | + branch_info = PluginBranchInfo(self.__get_git_path()) |
| 68 | + print(f"Core requirement {branch_info.core_requirement}") |
| 69 | + self.requires(branch_info.core_requirement) |
| 70 | + |
| 71 | + def configure(self): |
| 72 | + pass |
| 73 | + |
| 74 | + def system_requirements(self): |
| 75 | + # May be needed for macOS or Linux |
| 76 | + pass |
| 77 | + |
| 78 | + def config_options(self): |
| 79 | + if self.settings.os == "Windows": |
| 80 | + del self.options.fPIC |
| 81 | + |
| 82 | + def generate(self): |
| 83 | + generator = None |
| 84 | + if self.settings.os == "Macos": |
| 85 | + generator = "Xcode" |
| 86 | + if self.settings.os == "Linux": |
| 87 | + generator = "Ninja Multi-Config" |
| 88 | + |
| 89 | + tc = CMakeToolchain(self, generator=generator) |
| 90 | + |
| 91 | + tc.variables["CMAKE_CXX_STANDARD_REQUIRED"] = "ON" |
| 92 | + |
| 93 | + # Use the Qt provided .cmake files |
| 94 | + qt_path = pathlib.Path(self.deps_cpp_info["qt"].rootpath) |
| 95 | + qt_cfg = list(qt_path.glob("**/Qt6Config.cmake"))[0] |
| 96 | + qt_dir = qt_cfg.parents[0].as_posix() |
| 97 | + |
| 98 | + tc.variables["Qt6_DIR"] = qt_dir |
| 99 | + |
| 100 | + # Use the ManiVault .cmake file to find ManiVault with find_package |
| 101 | + mv_core_root = self.deps_cpp_info["hdps-core"].rootpath |
| 102 | + manivault_dir = pathlib.Path(mv_core_root, "cmake", "mv").as_posix() |
| 103 | + print("ManiVault_DIR: ", manivault_dir) |
| 104 | + tc.variables["ManiVault_DIR"] = manivault_dir |
| 105 | + |
| 106 | + # Give the installation directory to CMake |
| 107 | + MV_CMD_PATH = pathlib.Path(self.deps_cpp_info["CellMorphologyData"].rootpath).as_posix() |
| 108 | + tc.variables["MV_CMD_INSTALL_DIR"] = MV_CMD_PATH |
| 109 | + |
| 110 | + MV_EPD_PATH = pathlib.Path(self.deps_cpp_info["EphysData"].rootpath).as_posix() |
| 111 | + tc.variables["MV_EPD_INSTALL_DIR"] = MV_EPD_PATH |
| 112 | + |
| 113 | + # Set some build options |
| 114 | + tc.variables["MV_UNITY_BUILD"] = "ON" |
| 115 | + |
| 116 | + tc.generate() |
| 117 | + |
| 118 | + def _configure_cmake(self): |
| 119 | + cmake = CMake(self) |
| 120 | + cmake.configure(build_script_folder="hdps/MEView") |
| 121 | + cmake.verbose = True |
| 122 | + return cmake |
| 123 | + |
| 124 | + def build(self): |
| 125 | + print("Build OS is: ", self.settings.os) |
| 126 | + |
| 127 | + cmake = self._configure_cmake() |
| 128 | + cmake.build(build_type="RelWithDebInfo") |
| 129 | + cmake.build(build_type="Release") |
| 130 | + |
| 131 | + def package(self): |
| 132 | + package_dir = pathlib.Path(self.build_folder, "package") |
| 133 | + relWithDebInfo_dir = package_dir / "RelWithDebInfo" |
| 134 | + release_dir = package_dir / "Release" |
| 135 | + print("Packaging install dir: ", package_dir) |
| 136 | + subprocess.run( |
| 137 | + [ |
| 138 | + "cmake", |
| 139 | + "--install", |
| 140 | + self.build_folder, |
| 141 | + "--config", |
| 142 | + "RelWithDebInfo", |
| 143 | + "--prefix", |
| 144 | + relWithDebInfo_dir, |
| 145 | + ] |
| 146 | + ) |
| 147 | + subprocess.run( |
| 148 | + [ |
| 149 | + "cmake", |
| 150 | + "--install", |
| 151 | + self.build_folder, |
| 152 | + "--config", |
| 153 | + "Release", |
| 154 | + "--prefix", |
| 155 | + release_dir, |
| 156 | + ] |
| 157 | + ) |
| 158 | + self.copy(pattern="*", src=package_dir) |
| 159 | + |
| 160 | + def package_info(self): |
| 161 | + self.cpp_info.relwithdebinfo.libdirs = ["RelWithDebInfo/lib"] |
| 162 | + self.cpp_info.relwithdebinfo.bindirs = ["RelWithDebInfo/Plugins", "RelWithDebInfo"] |
| 163 | + self.cpp_info.relwithdebinfo.includedirs = ["RelWithDebInfo/include", "RelWithDebInfo"] |
| 164 | + self.cpp_info.release.libdirs = ["Release/lib"] |
| 165 | + self.cpp_info.release.bindirs = ["Release/Plugins", "Release"] |
| 166 | + self.cpp_info.release.includedirs = ["Release/include", "Release"] |
0 commit comments