-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconan.go
101 lines (78 loc) · 2.76 KB
/
conan.go
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
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"runtime"
"strings"
"github.com/codecat/go-libs/log"
)
type Conanfile map[string][]string
func loadConanFile(path string) (Conanfile, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
regexHeader := regexp.MustCompile(`^\[(.*)\]$`)
currentHeader := ""
ret := make(Conanfile)
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
if line == "" {
continue
}
res := regexHeader.FindStringSubmatch(line)
if len(res) == 0 {
if currentHeader == "" {
return nil, fmt.Errorf("invalid conanfile on line: \"%s\"", line)
}
ret[currentHeader] = append(ret[currentHeader], strings.Trim(line, " \t"))
} else {
currentHeader = res[1]
}
}
return ret, nil
}
func addConanPackages(ctx *Context, conan Conanfile) {
//TODO: Implement all Conan features
// conan["frameworkdirs"] // contains .framework files, only needed on MacOS
// conan["frameworks"] // frameworks to link to
// conan["bindirs"] // contains .dll files, only needed when linking with shared libraries
log.Info("Adding Conan packages")
isWindows := runtime.GOOS == "windows"
// contains .h files
ctx.CompilerOptions.IncludeDirectories = append(ctx.CompilerOptions.IncludeDirectories, conan["includedirs"]...)
// contains .lib files
ctx.CompilerOptions.LinkDirectories = append(ctx.CompilerOptions.LinkDirectories, conan["libdirs"]...)
// libraries to link to
for _, lib := range conan["libs"] {
if isWindows && !strings.HasSuffix(lib, ".lib") {
lib += ".lib"
}
ctx.CompilerOptions.LinkLibraries = append(ctx.CompilerOptions.LinkLibraries, lib)
}
// additional system libraries to link to
for _, lib := range conan["system_libs"] {
if isWindows && !strings.HasSuffix(lib, ".lib") {
lib += ".lib"
}
ctx.CompilerOptions.LinkLibraries = append(ctx.CompilerOptions.LinkLibraries, lib)
}
// precompiler defines to add
ctx.CompilerOptions.Defines = append(ctx.CompilerOptions.Defines, conan["defines"]...)
// C++ compiler flags to add
ctx.CompilerOptions.CompilerFlagsCPP = append(ctx.CompilerOptions.CompilerFlagsCPP, conan["cppflags"]...)
// C/C++ compiler flags to add
ctx.CompilerOptions.CompilerFlagsCXX = append(ctx.CompilerOptions.CompilerFlagsCXX, conan["cxxflags"]...)
// C compiler flags to add
ctx.CompilerOptions.CompilerFlagsC = append(ctx.CompilerOptions.CompilerFlagsC, conan["cflags"]...)
if ctx.Type == LinkDll {
// linker flags to add when building a shared library
ctx.CompilerOptions.LinkerFlags = append(ctx.CompilerOptions.LinkerFlags, conan["sharedlinkflags"]...)
} else if ctx.Type == LinkExe {
// linker flags to add when building an executable
ctx.CompilerOptions.LinkerFlags = append(ctx.CompilerOptions.LinkerFlags, conan["exelinkflags"]...)
}
}