-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconanfile.py
128 lines (109 loc) · 4.57 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
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
required_conan_version = ">=1.33.0"
class CspiceConan(ConanFile):
name = "cspice"
description = "NASA C SPICE library"
license = "TSPA"
topics = ("spice", "naif", "kernels", "space", "nasa", "jpl", "spacecraft", "planet", "robotics")
homepage = "https://naif.jpl.nasa.gov/naif/toolkit.html"
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"utilities": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"utilities": True,
}
generators = "cmake"
_cmake = None
@property
def _source_subfolder(self):
return "source_subfolder"
def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
def validate(self):
sources_url_per_triplet = self.conan_data["sources"][self.version]["url"]
the_os = self._get_os_or_subsystem()
if the_os not in sources_url_per_triplet:
raise ConanInvalidConfiguration(
"cspice N{0} does not support {1}".format(self.version, the_os)
)
compiler = str(self.settings.compiler)
if compiler not in sources_url_per_triplet[the_os]:
raise ConanInvalidConfiguration(
"cspice N{0} does not support {1} on {2}".format(self.version, compiler, the_os)
)
arch = str(self.settings.arch)
if arch not in sources_url_per_triplet[the_os][compiler]:
raise ConanInvalidConfiguration(
"cspice N{0} does not support {1} on {2} {3}".format(self.version, compiler, the_os, arch)
)
def _get_os_or_subsystem(self):
if self.settings.os == "Windows" and self.settings.os.subsystem != "None":
os_or_subsystem = str(self.settings.os.subsystem)
else:
os_or_subsystem = str(self.settings.os)
return os_or_subsystem
def source(self):
pass
def build(self):
self._get_sources()
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()
def _get_sources(self):
the_os = self._get_os_or_subsystem()
compiler = str(self.settings.compiler)
arch = str(self.settings.arch)
url = self.conan_data["sources"][self.version]["url"][the_os][compiler][arch]
sha256 = self.conan_data["sources"][self.version]["sha256"][the_os][compiler][arch]
if url.endswith(".tar.Z"): # Python doesn't have any module to uncompress .Z files
filename = os.path.basename(url)
tools.download(url, filename, sha256=sha256)
command = "zcat {} | tar -xf -".format(filename)
self.run(command=command)
os.remove(filename)
else:
tools.get(url, sha256=sha256)
tools.rename(self.name, self._source_subfolder)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_UTILITIES"] = self.options.utilities
self._cmake.configure()
return self._cmake
def package(self):
tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), self._extract_license())
cmake = self._configure_cmake()
cmake.install()
def _extract_license(self):
spiceusr_header = tools.load(os.path.join(self._source_subfolder, "include", "SpiceUsr.h"))
begin = spiceusr_header.find("-Disclaimer")
end = spiceusr_header.find("-Required_Reading", begin)
return spiceusr_header[begin:end]
def package_info(self):
self.cpp_info.libs = ["cspice"]
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("m")
if self.options.utilities:
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)