forked from bincrafters/conan-xmake_generator
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conanfile.py
92 lines (73 loc) · 4.1 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans.model.conan_generator import Generator
from conans import ConanFile
class XmakeGenerator(ConanFile):
name = "xmake_generator"
version = "0.1.0"
url = "https://github.com/solvingj/conan-xmake_generator"
description = "Conan build generator for xmake build system"
topics = ("conan", "generator", "xmake", "tboox")
homepage = "https://github.com/tboox/xmake"
author = "Bincrafters <[email protected]>"
license = "MIT"
exports = ["LICENSE.md"]
class xmake(Generator):
@property
def filename(self):
return "conanbuildinfo.xmake.lua"
@property
def content(self):
deps = XmakeDepsFormatter(self.deps_build_info)
# get plat
plat = str(self.settings.get_safe("os"))
# get mode
mode = str(self.settings.get_safe("build_type"))
# get arch
arch = str(self.settings.get_safe("arch"))
# make template
template = (' {plat}_{arch}_{mode} = \n'
' {{\n'
' includedirs = {{{deps.include_paths}}},\n'
' linkdirs = {{{deps.lib_paths}}},\n'
' links = {{{deps.libs}}},\n'
' frameworkdirs = {{{deps.framework_paths}}},\n'
' frameworks = {{{deps.frameworks}}},\n'
' syslinks = {{{deps.system_libs}}},\n'
' defines = {{{deps.defines}}},\n'
' cxxflags = {{{deps.cppflags}}},\n'
' cflags = {{{deps.cflags}}},\n'
' shflags = {{{deps.sharedlinkflags}}},\n'
' ldflags = {{{deps.exelinkflags}}},\n'
' __bindirs = {{{deps.bin_paths}}},\n'
' __resdirs = {{{deps.res_paths}}},\n'
' __srcdirs = {{{deps.src_paths}}}\n'
' }}')
# make sections
sections = []
sections.append(template.format(plat = plat, arch = arch, mode = mode, deps = deps))
# make content
return "{\n" + ",\n".join(sections) + "\n}"
class XmakeDepsFormatter(object):
def __prepare_process_escape_character(self, raw_string):
if raw_string.find('\"') != -1:
raw_string = raw_string.replace("\"","\\\"")
return raw_string
def __filter_char(self, raw_string):
return self.__prepare_process_escape_character(raw_string)
def __init__(self, deps_cpp_info):
self.include_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in deps_cpp_info.include_paths)
self.lib_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in deps_cpp_info.lib_paths)
self.bin_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in deps_cpp_info.bin_paths)
self.res_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in deps_cpp_info.res_paths)
self.src_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in deps_cpp_info.src_paths)
self.framework_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in deps_cpp_info.framework_paths)
self.libs = ", ".join('"%s"' % p for p in deps_cpp_info.libs)
self.frameworks = ", ".join('"%s"' % p for p in deps_cpp_info.frameworks)
self.system_libs = ", ".join('"%s"' % p for p in deps_cpp_info.system_libs)
self.defines = ", ".join('"%s"' % self.__filter_char(p) for p in deps_cpp_info.defines)
self.cppflags = ", ".join('"%s"' % p for p in deps_cpp_info.cppflags)
self.cflags = ", ".join('"%s"' % p for p in deps_cpp_info.cflags)
self.sharedlinkflags = ", ".join('"%s"' % p for p in deps_cpp_info.sharedlinkflags)
self.exelinkflags = ", ".join('"%s"' % p for p in deps_cpp_info.exelinkflags)
self.rootpath = "%s" % self.__filter_char(deps_cpp_info.rootpath.replace("\\", "/"))