-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathtoolchain.py
75 lines (61 loc) · 1.9 KB
/
toolchain.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
import os
import textwrap
from jinja2 import Template
from conan.tools.files import save
class PremakeToolchain:
"""
PremakeToolchain generator
"""
filename = "conantoolchain.premake5.lua"
_premake_file_template = textwrap.dedent(
"""\
#!lua
include("conandeps.premake5.lua")
workspace "{{workspace}}"
premake.api.addAliases("architecture", {
["armv8"] = "arm64"
})
{% if cppstd %}
cppdialect "{{cppstd}}"
{% endif %}
{% if cstd %}
cdialect "{{cstd}}"
{% endif %}
location "{{ build_folder }}"
targetdir "{{ build_folder }}"
conan_setup()
{% if variables %}
defines { {{variables}} }
{% endif %}
"""
)
def __init__(self, conanfile, workspace="*"):
# '*' is the global workspace
self._conanfile = conanfile
self.workspace = workspace
# TODO: not possible to overwrite upstream defines yet
self.defines = {}
def generate(self):
cppstd = self._conanfile.settings.get_safe("compiler.cppstd")
cstd = self._conanfile.settings.get_safe("compiler.cstd")
if cppstd.startswith("gnu"):
cppstd = f"gnu++{cppstd[3:]}"
formated_variables = ""
for key, value in self.defines.items():
if isinstance(value, bool):
value = 1 if value else 0
formated_variables += f'"{key}={value}", '
content = Template(
self._premake_file_template, trim_blocks=True, lstrip_blocks=True
).render(
workspace=self.workspace,
build_folder=self._conanfile.build_folder,
cppstd=cppstd,
cstd=cstd,
variables=formated_variables,
)
save(
self,
os.path.join(self._conanfile.generators_folder, self.filename),
content,
)