-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
186 lines (153 loc) · 6.22 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
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 ExamplePluginsConan(ConanFile):
"""Class to package ExamplePlugins 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 = "ExamplePlugins"
description = (
"A collection of examples including analys, data, loader and view plugins."
)
topics = ("hdps", "plugin", "examples", "various")
url = "https://github.com/ManiVaultStudio/ExamplePlugins"
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/ExamplePlugins",
"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()
qt_root = qt_cfg.parents[3].as_posix()
# for Qt >= 6.4.2
#tc.variables["Qt6_DIR"] = qt_dir
# for Qt < 6.4.2
tc.variables["Qt6_ROOT"] = qt_root
# 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"
# Use vcpkg-installed dependencies if there are any
if os.environ.get("VCPKG_ROOT", None):
vcpkg_dir = pathlib.Path(os.environ["VCPKG_ROOT"])
vcpkg_exe = vcpkg_dir / "vcpkg.exe" if self.settings.os == "Windows" else vcpkg_dir / "vcpkg"
vcpkg_tc = vcpkg_dir / "scripts" / "buildsystems" / "vcpkg.cmake"
vcpkg_triplet = "x64-windows"
if self.settings.os == "Macos":
vcpkg_triplet = "x64-osx"
if self.settings.os == "Linux":
vcpkg_triplet = "x64-linux"
print("vcpkg_dir: ", vcpkg_dir)
print("vcpkg_exe: ", vcpkg_exe)
print("vcpkg_tc: ", vcpkg_tc)
print("vcpkg_triplet: ", vcpkg_triplet)
tc.variables["VCPKG_LIBRARY_LINKAGE"] = "dynamic"
tc.variables["VCPKG_TARGET_TRIPLET"] = vcpkg_triplet
tc.variables["VCPKG_HOST_TRIPLET"] = vcpkg_triplet
tc.variables["VCPKG_ROOT"] = vcpkg_dir.as_posix()
tc.variables["CMAKE_PROJECT_INCLUDE"] = vcpkg_tc.as_posix()
tc.generate()
def _configure_cmake(self):
cmake = CMake(self)
cmake.configure(build_script_folder="hdps/ExamplePlugins")
cmake.verbose = True
return cmake
def build(self):
print("Build OS is: ", self.settings.os)
cmake = self._configure_cmake()
cmake.build(build_type="Debug")
cmake.build(build_type="Release")
def package(self):
package_dir = pathlib.Path(self.build_folder, "package")
debug_dir = package_dir / "Debug"
release_dir = package_dir / "Release"
print("Packaging install dir: ", package_dir)
subprocess.run(
[
"cmake",
"--install",
self.build_folder,
"--config",
"Debug",
"--prefix",
debug_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.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"]