MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / GenerateCFiles

Function GenerateCFiles

tools/targets/cmake.py:32–338  ·  view source on GitHub ↗

Generate CMakeLists.txt files

(env, project, project_name)

Source from the content-addressed store, hash-verified

30
31
32def GenerateCFiles(env, project, project_name):
33 """
34 Generate CMakeLists.txt files
35 """
36
37 PROJECT_NAME = project_name if project_name != "project" else "rtthread"
38
39 tool_path_conv = defaultdict(lambda : {"name":"", "path": ""})
40 tool_path_conv_helper = lambda tool: {"name": tool, "path": os.path.join(rtconfig.EXEC_PATH, tool).replace('\\', "/")}
41
42 tool_path_conv["CMAKE_C_COMPILER"] = tool_path_conv_helper(rtconfig.CC)
43 if 'CXX' in dir(rtconfig):
44 tool_path_conv["CMAKE_CXX_COMPILER"] = tool_path_conv_helper(rtconfig.CXX)
45 tool_path_conv["CMAKE_ASM_COMPILER"] = tool_path_conv_helper(rtconfig.AS)
46 tool_path_conv["CMAKE_AR"] = tool_path_conv_helper(rtconfig.AR)
47 tool_path_conv["CMAKE_LINKER"] = tool_path_conv_helper(rtconfig.LINK)
48 if rtconfig.PLATFORM in ['gcc']:
49 tool_path_conv["CMAKE_SIZE"] = tool_path_conv_helper(rtconfig.SIZE)
50 tool_path_conv["CMAKE_OBJDUMP"] = tool_path_conv_helper(rtconfig.OBJDUMP)
51 tool_path_conv["CMAKE_OBJCOPY"] = tool_path_conv_helper(rtconfig.OBJCPY)
52 elif rtconfig.PLATFORM in ['armcc', 'armclang']:
53 tool_path_conv["CMAKE_FROMELF"] = tool_path_conv_helper(rtconfig.FROMELF)
54
55 CC = tool_path_conv["CMAKE_C_COMPILER"]["path"]
56 CXX = tool_path_conv["CMAKE_CXX_COMPILER"]["path"]
57 AS = tool_path_conv["CMAKE_ASM_COMPILER"]["path"]
58 AR = tool_path_conv["CMAKE_AR"]["path"]
59 LINK = tool_path_conv["CMAKE_LINKER"]["path"]
60 SIZE = tool_path_conv["CMAKE_SIZE"]["path"]
61 OBJDUMP = tool_path_conv["CMAKE_OBJDUMP"]["path"]
62 OBJCOPY = tool_path_conv["CMAKE_OBJCOPY"]["path"]
63 FROMELF = tool_path_conv["CMAKE_FROMELF"]["path"]
64
65 CFLAGS = env['CFLAGS'].replace('\\', "/").replace('\"', "\\\"")
66 if 'CXXFLAGS' in dir(rtconfig):
67 cflag_str=''.join(env['CXXFLAGS'])
68 CXXFLAGS = cflag_str.replace('\\', "/").replace('\"', "\\\"")
69 else:
70 CXXFLAGS = CFLAGS
71 AFLAGS = env['ASFLAGS'].replace('\\', "/").replace('\"', "\\\"")
72 LFLAGS = env['LINKFLAGS'].replace('\\', "/").replace('\"', "\\\"")
73
74 POST_ACTION = rtconfig.POST_ACTION
75 # replace the tool name with the cmake variable
76 for cmake_var, each_tool in tool_path_conv.items():
77 tool_name = each_tool['name']
78 if tool_name == "": continue
79 if "win32" in sys.platform:
80 while f"{tool_name}.exe" in POST_ACTION: # find the tool with `.exe` suffix first
81 POST_ACTION = POST_ACTION.replace(tool_name, "string_to_replace")
82 while tool_name in POST_ACTION:
83 POST_ACTION = POST_ACTION.replace(tool_name, "string_to_replace")
84 while "string_to_replace" in POST_ACTION:
85 POST_ACTION = POST_ACTION.replace("string_to_replace", f"${{{cmake_var}}}")
86 # replace the `$TARGET` with `${CMAKE_PROJECT_NAME}.elf`
87 while "$TARGET" in POST_ACTION:
88 POST_ACTION = POST_ACTION.replace("$TARGET", "${CMAKE_PROJECT_NAME}.elf")
89 # add COMMAAND before each command

Callers 1

CMakeProjectFunction · 0.70

Calls 4

_make_path_relativeFunction · 0.90
openFunction · 0.50
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected