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

Function buildCDynamicExampleCMake

Source/buildbindingccpp.go:1756–1801  ·  view source on GitHub ↗
(componentdefinition ComponentDefinition, w LanguageWriter, outputFolder string, outputFolderExample string, ExplicitLinking bool)

Source from the content-addressed store, hash-verified

1754}
1755
1756func buildCDynamicExampleCMake(componentdefinition ComponentDefinition, w LanguageWriter, outputFolder string, outputFolderExample string, ExplicitLinking bool) error {
1757 NameSpace := componentdefinition.NameSpace
1758 BaseName := componentdefinition.BaseName
1759
1760 w.Writeln("cmake_minimum_required(VERSION 3.5)")
1761
1762 w.Writeln("")
1763 projectName := fmt.Sprintf("%sExample_C", NameSpace)
1764 if ExplicitLinking {
1765 projectName += "Dynamic"
1766 } else {
1767 projectName += "Implicit"
1768 }
1769
1770 bindingFolder, err := filepath.Rel(outputFolderExample, outputFolder)
1771 if (err != nil) {
1772 return err
1773 }
1774 bindingFolder = strings.Replace(bindingFolder, "\\", "/", -1)
1775 cmakeBindingFolder := "CMAKE_CURRENT_BINDING_DIR"
1776 w.Writeln("set(%s ${CMAKE_CURRENT_SOURCE_DIR}/%s)", cmakeBindingFolder, bindingFolder)
1777
1778 w.Writeln("")
1779 w.Writeln("project(%s C)", projectName)
1780 w.Writeln("")
1781 bindingSource := ""
1782 if (ExplicitLinking) {
1783 bindingSource = "\"${"+cmakeBindingFolder+"}/"+strings.ToLower(NameSpace)+"_dynamic.cc\""
1784 w.Writeln("SET_SOURCE_FILES_PROPERTIES(%s PROPERTIES LANGUAGE C)", bindingSource)
1785 bindingSource += "\n"
1786 }
1787
1788 w.Writeln("add_executable(%s\n \"${CMAKE_CURRENT_SOURCE_DIR}/%s_example.c\"\n %s\n)", projectName, NameSpace, bindingSource)
1789 w.Writeln("set_property(TARGET %s PROPERTY C_STANDARD 99)", projectName)
1790 if (ExplicitLinking) {
1791 w.Writeln("if (UNIX)")
1792 w.Writeln(" target_link_libraries(%s ${CMAKE_DL_LIBS})", projectName)
1793 w.Writeln("endif (UNIX)")
1794 } else {
1795 linkFolder := strings.Replace(outputFolder, string(filepath.Separator), "/", -2) + "/../../Implementations/*/*/*"
1796 w.Writeln("find_library(%sLOCATION %s \"%s\")", strings.ToUpper(BaseName), BaseName, linkFolder)
1797 w.Writeln("target_link_libraries(%s ${%sLOCATION})", projectName, strings.ToUpper(BaseName))
1798 }
1799 w.Writeln("target_include_directories(%s PRIVATE \"${%s}\")", projectName, cmakeBindingFolder)
1800 return nil
1801}

Callers 1

BuildBindingCExplicitFunction · 0.85

Calls 1

WritelnMethod · 0.80

Tested by

no test coverage detected