MCPcopy Create free account
hub / github.com/celer-pkg/celer / Generate

Method Generate

configs/rootfs.go:93–129  ·  view source on GitHub ↗
(toolchain *strings.Builder)

Source from the content-addressed store, hash-verified

91}
92
93func (r RootFS) Generate(toolchain *strings.Builder) error {
94 var buffer bytes.Buffer
95
96 // SYSROOT section.
97 fmt.Fprintf(&buffer, "\n# =============== Cross-compile SYSROOT =============== #\n")
98 fmt.Fprintf(&buffer, "set(CMAKE_SYSROOT %q)\n", "${WORKSPACE_ROOT}/downloads/tools/"+filepath.ToSlash(r.Path))
99
100 // Append --sysroot to compiler flags.
101 fmt.Fprintf(&buffer, `string(APPEND CMAKE_C_FLAGS_INIT " --sysroot=${CMAKE_SYSROOT}")`+"\n")
102 fmt.Fprintf(&buffer, `string(APPEND CMAKE_CXX_FLAGS_INIT " --sysroot=${CMAKE_SYSROOT}")`+"\n")
103
104 // Include directories section,
105 if len(r.IncludeDirs) > 0 {
106 for _, incDir := range r.IncludeDirs {
107 incPath := filepath.ToSlash(filepath.Join("${CMAKE_SYSROOT}", incDir))
108 fmt.Fprintf(&buffer, `string(APPEND CMAKE_C_FLAGS_INIT " -isystem %s")`+"\n", incPath)
109 fmt.Fprintf(&buffer, `string(APPEND CMAKE_CXX_FLAGS_INIT " -isystem %s")`+"\n", incPath)
110 }
111 }
112
113 // Linker rpath-link section.
114 if len(r.LibDirs) > 0 {
115 fmt.Fprintf(&buffer, "\n# Linker needs -L and rpath-link to resolve NEEDED dependencies from sysroot.\n")
116 for _, libDir := range r.LibDirs {
117 libPath := filepath.Join("${CMAKE_SYSROOT}", libDir)
118 libPath = filepath.ToSlash(libPath)
119 fmt.Fprintf(&buffer, `foreach(flag_var CMAKE_SHARED_LINKER_FLAGS_INIT CMAKE_MODULE_LINKER_FLAGS_INIT CMAKE_EXE_LINKER_FLAGS_INIT)`+"\n")
120 fmt.Fprintf(&buffer, ` string(APPEND ${flag_var} " -L%s")`+"\n", libPath)
121 fmt.Fprintf(&buffer, ` string(APPEND ${flag_var} " -Wl,-rpath-link,%s")`+"\n", libPath)
122 fmt.Fprintf(&buffer, `endforeach()`+"\n")
123 }
124 }
125
126 // Write all at once.
127 toolchain.WriteString(buffer.String())
128 return nil
129}

Callers

nothing calls this directly

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected