MCPcopy Create free account
hub / github.com/Autodesk/AutomaticComponentToolkit / BuildBindingCExplicit

Function BuildBindingCExplicit

Source/buildbindingccpp.go:47–115  ·  view source on GitHub ↗

BuildBindingCExplicit builds dyanmic C-bindings of a library's API in form of explicitly loaded function handles.

(component ComponentDefinition, outputFolder string, outputFolderExample string, indentString string)

Source from the content-addressed store, hash-verified

45
46// BuildBindingCExplicit builds dyanmic C-bindings of a library's API in form of explicitly loaded function handles.
47func BuildBindingCExplicit(component ComponentDefinition, outputFolder string, outputFolderExample string, indentString string) error {
48 forceRecreation := false
49
50 namespace := component.NameSpace
51 libraryname := component.LibraryName
52 baseName := component.BaseName
53
54 DynamicCHeader := path.Join(outputFolder, baseName+"_dynamic.h")
55 log.Printf("Creating \"%s\"", DynamicCHeader)
56 dynhfile, err := CreateLanguageFile(DynamicCHeader, indentString)
57 if err != nil {
58 return err
59 }
60 dynhfile.WriteCLicenseHeader(component,
61 fmt.Sprintf("This is an autogenerated plain C Header file in order to allow an easy\n use of %s", libraryname),
62 true)
63 err = buildDynamicCCPPHeader(component, dynhfile, namespace, baseName, false, false)
64 if err != nil {
65 return err
66 }
67
68 DynamicCImpl := path.Join(outputFolder, baseName+"_dynamic.cc")
69 log.Printf("Creating \"%s\"", DynamicCImpl)
70 dyncppfile, err := CreateLanguageFile(DynamicCImpl, indentString)
71 if err != nil {
72 return err
73 }
74 dyncppfile.WriteCLicenseHeader(component,
75 fmt.Sprintf("This is an autogenerated plain C Header file in order to allow an easy\n use of %s", libraryname),
76 true)
77
78 err = buildDynamicCImplementation(component, dyncppfile, namespace, baseName, true)
79 if err != nil {
80 return err
81 }
82
83 if len(outputFolderExample) > 0 {
84 CExample := path.Join(outputFolderExample, namespace+"_example"+".c")
85 if forceRecreation || !FileExists(CExample) {
86 log.Printf("Creating \"%s\"", CExample)
87 cexamplefile, err := CreateLanguageFile(CExample, indentString)
88 if err != nil {
89 return err
90 }
91 cexamplefile.WriteCLicenseHeader(component,
92 fmt.Sprintf("This is an autogenerated C application that demonstrates the\n usage of the C bindings of %s", libraryname),
93 true)
94 buildDynamicCExample(component, cexamplefile, outputFolder, "")
95 } else {
96 log.Printf("Omitting recreation of C-example file \"%s\"", CExample)
97 }
98
99 CPPCMake := path.Join(outputFolderExample, "CMakeLists.txt")
100 if forceRecreation || !FileExists(CPPCMake) {
101 log.Printf("Creating \"%s\"", CPPCMake)
102 cppcmake, err := CreateLanguageFile(CPPCMake, " ")
103 if err != nil {
104 return err

Callers 1

createComponentFunction · 0.85

Calls 9

CreateLanguageFileFunction · 0.85
buildDynamicCCPPHeaderFunction · 0.85
FileExistsFunction · 0.85
buildDynamicCExampleFunction · 0.85
PrintfMethod · 0.80
WriteCLicenseHeaderMethod · 0.80

Tested by

no test coverage detected