-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
205 lines (176 loc) · 7.63 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
from conans import ConanFile
from conan.tools.cmake import CMakeDeps, CMake, CMakeToolchain
from conans.tools import save, load
from conans.tools import os_info, SystemPackageTool
#from conan.tools.system.package_manager import Brew
import os
import shutil
import pathlib
import subprocess
from rules_support import PluginBranchInfo
import re
def compatibility(os, compiler, compiler_version):
# On macos fallback to zlib apple-clang 13
if os == "Macos" and compiler == "apple-clang" and bool(re.match("14.*", compiler_version)):
print("Compatibility match")
return ["zlib/1.3:compiler.version=13"]
return None
class SpidrPluginConan(ConanFile):
"""Class to package SpidrLib-Analyses using conan
Packages both RELEASE and DEBUG.
Uses rules_support (github.com/hdps/rulessupport) to derive
versioninfo based on the branch naming convention
as described in https://github.com/hdps/core/wiki/Branch-naming-rules
"""
name = "SpidrPlugin"
description = (
"Spatial Information in Dimensionality Reduction (Spidr) plugin for dimensionality reduction of data. "
)
topics = ("hdps", "plugin", "data", "dimensionality reduction", "SPIDR", "spatial data")
url = "https://github.com/hdps/SpidrPlugin"
author = "B. van Lew b.van_lew@lumc.nl" # 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/SpidrPlugin",
"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):
# if self.settings.compiler == "Visual Studio":
# del self.settings.compiler.runtime
pass
def system_requirements(self):
print("In system requirements")
installer = SystemPackageTool()
if self.settings.os == "Macos":
installer.install("libomp")
proc = subprocess.run("brew --prefix libomp", shell=True, capture_output=True)
subprocess.run(f"ln {proc.stdout.decode('UTF-8').strip()}/lib/libomp.dylib /usr/local/lib/libomp.dylib", shell=True)
if os_info.linux_distro in ["ubuntu", "debian"]:
print("glfw system dependencies")
packages = []
packages.append('libxi-dev')
packages.append('libxcursor-dev')
packages.append('libxrandr-dev')
packages.append('libxinerama-dev')
installer.install_packages(packages)
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"
# Use the Qt provided .cmake files
qtpath = pathlib.Path(self.deps_cpp_info["qt"].rootpath)
qt_root = str(list(qtpath.glob("**/Qt6Config.cmake"))[0].parents[3].as_posix())
tc = CMakeToolchain(self, generator=generator)
if self.settings.os == "Windows" and self.options.shared:
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
if self.settings.os == "Linux" or self.settings.os == "Macos":
tc.variables["CMAKE_CXX_STANDARD_REQUIRED"] = "ON"
tc.variables["Qt6_ROOT"] = qt_root
if os_info.is_macos:
proc = subprocess.run(
"brew --prefix libomp", shell=True, capture_output=True
)
prefix_path = f"{proc.stdout.decode('UTF-8').strip()}"
tc.variables["OpenMP_ROOT"] = prefix_path
tc.variables["USE_MACOSSDK_OPENGL"] = "ON"
# Set the installation directory for ManiVault based on the MV_INSTALL_DIR environment variable
# or if none is specified, set it to the build/install dir.
if not os.environ.get("MV_INSTALL_DIR", None):
os.environ["MV_INSTALL_DIR"] = os.path.join(self.build_folder, "install")
print("MV_INSTALL_DIR: ", os.environ["MV_INSTALL_DIR"])
self.install_dir = pathlib.Path(os.environ["MV_INSTALL_DIR"]).as_posix()
# Give the installation directory to CMake
tc.variables["MV_INSTALL_DIR"] = self.install_dir
# Find ManiVault with find_package
self.manivault_dir = self.install_dir + '/cmake/mv/'
tc.variables["ManiVault_DIR"] = self.manivault_dir
tc.generate()
def _configure_cmake(self):
cmake = CMake(self)
cmake.configure(build_script_folder="hdps/SpidrPlugin")
cmake.verbose = True
return cmake
def build(self):
print("Build OS is : ", self.settings.os)
# The SpidrPlugin build expects the HDPS package to be in this install dir
hdps_pkg_root = self.deps_cpp_info["hdps-core"].rootpath
print("Install dir type: ", self.install_dir)
shutil.copytree(hdps_pkg_root, self.install_dir)
cmake = self._configure_cmake()
cmake.build(build_type="Debug")
cmake.install(build_type="Debug")
# cmake_release = self._configure_cmake()
cmake.build(build_type="Release")
cmake.install(build_type="Release")
def package(self):
package_dir = os.path.join(self.build_folder, "package")
print("Packaging install dir: ", package_dir)
subprocess.run(
[
"cmake",
"--install",
self.build_folder,
"--config",
"Debug",
"--prefix",
os.path.join(package_dir, "Debug"),
]
)
subprocess.run(
[
"cmake",
"--install",
self.build_folder,
"--config",
"Release",
"--prefix",
os.path.join(package_dir, "Release"),
]
)
self.copy(pattern="*", src=package_dir)
# Add the debug support files to the package
# (*.pdb) if building the Visual Studio version
if self.settings.compiler == "Visual Studio":
self.copy("*.pdb", dst="lib/Debug", keep_path=False)
def package_info(self):
self.cpp_info.debug.libdirs = ["Debug/lib"]
self.cpp_info.debug.bindirs = ["Debug/Plugins", "Debug"]
self.cpp_info.debug.includedirs = ["Debug/include", "Debug"]
self.cpp_info.release.libdirs = ["Release/lib"]
self.cpp_info.release.bindirs = ["Release/Plugins", "Release"]
self.cpp_info.release.includedirs = ["Release/include", "Release"]