-
Notifications
You must be signed in to change notification settings - Fork 1
/
conanfile.py
246 lines (217 loc) · 9.87 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# -*- coding: utf-8 -*-
from conan import ConanFile
from conan.tools.cmake import CMakeDeps, CMake, CMakeToolchain
from conans.tools import save, load
from conans import tools
import os
import sys
import pathlib
import shutil
from rules_support import CoreBranchInfo
import subprocess
import traceback
import re
class HdpsCoreConan(ConanFile):
"""Class to package hdps-core using conan
Packages both RELEASE and DEBUG.
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 = "hdps-core"
description = (
"Core libraries and plugins for ManiVault"
)
# topics can get used for searches, GitHub topics, Bintray tags etc.
# Add here keywords about the library
topics = ("conan", "analysis", "n-dimensional", "plugin")
url = "https://github.com/ManiVaultStudio/core"
branch = "develop" # should come from profile
author = "B. van Lew <b.van_lew@lumc.nl>"
license = (
"LGPL-3.0-or-later" # Indicates license: use SPDX Identifiers https://spdx.org/licenses/
)
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],
"macos_bundle": [True, False],
}
default_options = {"shared": True, "fPIC": True, "macos_bundle": False}
# Custom attributes for Bincrafters recipe conventions
install_dir = None
this_dir = os.path.dirname(os.path.realpath(__file__))
requires = ("qt/6.3.2@lkeb/stable")
scm = {"type": "git", "subfolder": "hdps/core", "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 = CoreBranchInfo(self.recipe_folder)
self.version = branch_info.version
# Remove runtime and use always default (MD/MDd)
def configure(self):
pass
# Needed for toolchain
# if self.settings.compiler == "Visual Studio":
# del self.settings.compiler.runtime
def system_requirements(self):
if tools.os_info.is_linux:
if tools.os_info.with_apt:
installer = tools.SystemPackageTool()
installer.install("mesa-common-dev")
installer.install("libgl1-mesa-dev")
installer.install("libxcomposite-dev")
installer.install("libxcursor-dev")
installer.install("libxi-dev")
installer.install("libnss3-dev")
installer.install("libnspr4-dev")
installer.install("libfreetype6-dev")
installer.install("libfontconfig1-dev")
installer.install("libxtst-dev")
installer.install("libasound2-dev")
installer.install("libdbus-1-dev")
min_cmake_version = os.environ.get("CONAN_MINIMUM_CMAKE_VERSION")
if min_cmake_version is not None:
subprocess.run(f"pip3 install cmake>={min_cmake_version}".split())
print("Path is: ", os.environ["PATH"])
result = subprocess.run(
"which cmake".split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
os.environ["CONAN_CMAKE_PROGRAM"] = result.stdout.decode(
"utf-8"
).rstrip()
print(f'Cmake at {os.environ["CONAN_CMAKE_PROGRAM"]}')
# if tools.os_info.is_macos:
# installer = tools.SystemPackageTool()
# installer.install("libomp", update=False)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def generate(self):
# This prevents overlap between the hdps/core (source folder)
# and the HDPS (build) folder. This happens in the Macos build
# Build folder can't be set here since conan 1.50
# possibly via CMakeDeps and CMakeToolchain
# self.build_folder = self.build_folder + '/hdps-common'
deps = CMakeDeps(self)
deps.generate()
generator = None
# TODO Generators can be moved to profiles
if self.settings.os == "Macos":
generator = "Xcode"
if self.settings.os == "Linux":
generator = "Ninja Multi-Config"
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"
# 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.variables["CMAKE_PREFIX_PATH"] = f"{qt_root}"
#tc.variables["Qt6_ROOT"] = qt_root
# 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
# Set some build options
tc.variables["MV_PRECOMPILE_HEADERS"] = "ON"
tc.variables["MV_UNITY_BUILD"] = "ON"
# OS specific settings
if self.settings.os == "Linux":
tc.variables["CMAKE_CONFIGURATION_TYPES"] = "Debug;Release"
try:
tc.generate()
except KeyError as e:
print("Exception!", sys.exc_info()[0])
print(e)
traceback.print_exc()
raise e
def _configure_cmake(self):
cmake = CMake(self)
cmake.verbose = True
cmake.configure(build_script_folder="hdps/core")
return cmake
def build(self):
print("Build OS is : ", self.settings.os)
print(f"In build, build folder {self.build_folder}")
# save the last build folder to allow double packaging with export-pkg
save(
pathlib.Path(self.__get_git_path(), "__last_build_folder.txt"),
self.build_folder,
)
cmake = self._configure_cmake()
print("**** Build DEBUG *****")
cmake.build(build_type="Debug")
print("**** Install DEBUG *****")
cmake.install(build_type="Debug")
# cmake_release = self._configure_cmake()
print("**** Build RELEASE *****")
cmake.build(build_type="Release")
print("**** Install RELEASE *****")
cmake.install(build_type="Release")
def package(self):
# if just running package
if self.install_dir is None:
if not os.environ.get("MV_INSTALL_DIR", None):
os.environ["MV_INSTALL_DIR"] = os.path.join(
self.build_folder, "install"
)
self.install_dir = os.environ["MV_INSTALL_DIR"]
print("Packaging install dir: ", self.install_dir)
if self.settings.os == "Macos":
#git = tools.Git()
#branch_name = str(git.get_branch())
#release_tag = re.search(r"^release-|release\/(.*)$", branch_name)
#if (self.settings.os == "Macos") and (release_tag is not None):
self.options.macos_bundle = True
print("Options macos: ", self.options.macos_bundle)
if self.options.macos_bundle:
print("Macos including bundle")
else:
print("No macos_bundle in package")
if False == self.options.macos_bundle and self.settings.os == "Macos":
# remove the bundle before packaging -
# it contains the complete QtWebEngine > 1GB
shutil.rmtree(str(pathlib.Path(self.install_dir, "Debug/ManiVault Studio.app")))
shutil.rmtree(str(pathlib.Path(self.install_dir, "Release/ManiVault Studio.app")))
elif self.settings.os == "Macos":
# also remove debug even in bundle build to keep package size down
shutil.rmtree(str(pathlib.Path(self.install_dir, "Debug/ManiVault Studio.app")))
# Add the pdb files next to the libs for debug linking
if tools.os_info.is_windows:
pdb_dest = pathlib.Path(self.install_dir, "Debug/lib")
# pdb_dest.mkdir()
pdb_files = pathlib.Path(self.build_folder).glob("hdps/Debug/*.pdb")
for pfile in pdb_files:
shutil.copy(pfile, pdb_dest)
self.copy(pattern="*", src=self.install_dir, symlinks=True)
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"]