-
Notifications
You must be signed in to change notification settings - Fork 4
/
gyp-generator.py
60 lines (56 loc) · 2.03 KB
/
gyp-generator.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
from jinja2 import Template
from conans.model import Generator
from conans import ConanFile
import textwrap
class node_gyp(Generator):
@property
def filename(self):
return "conanbuildinfo.gyp"
def get_build_requires_names(self):
return [name for (name, _) in self.conanfile.build_requires]
@property
def content(self):
target_template = textwrap.dedent("""\
{
"target_name": "{{dep}}",
"type": "<(library)",
"direct_dependent_settings": {
"include_dirs": [
{% for include_path in include_paths -%}
"{{ include_path }}",
{%- endfor %}
],
{% if lib_paths -%}
"libraries": [
{% for lib in libs -%}
"-l{{ lib }}",
{%- endfor %}
{% for lib_path in lib_paths -%}
"-L{{ lib_path }}",
{%- endfor %}
"-Wl,-rpath,<(module_root_dir)/build/Release/"
]
{%- endif %}
}
}
""")
gyp_template = textwrap.dedent("""\
{
"targets": [
{{- targets -}}
]
}
""")
sections = []
for dep in self.conanfile.deps_cpp_info.deps:
if dep not in self.get_build_requires_names():
info = {
"dep": dep,
"libs": self.conanfile.deps_cpp_info[dep].libs,
"lib_paths": self.conanfile.deps_cpp_info[dep].lib_paths,
"include_paths": self.conanfile.deps_cpp_info[dep].include_paths,
}
t = Template(target_template)
sections.append(t.render(**info))
t = Template(gyp_template)
return t.render(targets=",\n".join(sections))