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