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

Method generate

tools/ng/generator.py:241–322  ·  view source on GitHub ↗

Generate CMakeLists.txt.

(self, context, project_info: Dict[str, Any])

Source from the content-addressed store, hash-verified

239 return "cmake"
240
241 def generate(self, context, project_info: Dict[str, Any]) -> bool:
242 """Generate CMakeLists.txt."""
243 self._ensure_output_dir()
244
245 # Get toolchain info
246 toolchain = context.toolchain_manager.get_current()
247
248 lines = [
249 "cmake_minimum_required(VERSION 3.10)",
250 "",
251 "# RT-Thread CMake Project",
252 f"project({self.config.project_name} C CXX ASM)",
253 "",
254 "# C Standard",
255 "set(CMAKE_C_STANDARD 99)",
256 "set(CMAKE_CXX_STANDARD 11)",
257 ""
258 ]
259
260 # Toolchain configuration
261 if toolchain and toolchain.get_name() == "gcc":
262 lines.extend([
263 "# Toolchain",
264 f"set(CMAKE_C_COMPILER {toolchain.info.prefix}gcc)",
265 f"set(CMAKE_CXX_COMPILER {toolchain.info.prefix}g++)",
266 f"set(CMAKE_ASM_COMPILER {toolchain.info.prefix}gcc)",
267 ""
268 ])
269
270 # Include directories
271 lines.extend([
272 "# Include directories",
273 "include_directories("
274 ])
275 for inc in project_info.get('all_includes', []):
276 lines.append(f" {inc}")
277 lines.extend([")", ""])
278
279 # Definitions
280 lines.extend([
281 "# Definitions",
282 "add_definitions("
283 ])
284 for k, v in project_info.get('all_defines', {}).items():
285 if v == '1':
286 lines.append(f" -D{k}")
287 else:
288 lines.append(f" -D{k}={v}")
289 lines.extend([")", ""])
290
291 # Source files
292 lines.extend([
293 "# Source files",
294 "set(SOURCES"
295 ])
296 for src in project_info.get('all_sources', []):
297 lines.append(f" {src}")
298 lines.extend([")", ""])

Callers 3

GenerateProjectFunction · 0.45
do_convertFunction · 0.45
do_convertFunction · 0.45

Calls 7

_ensure_output_dirMethod · 0.80
openFunction · 0.50
get_currentMethod · 0.45
get_nameMethod · 0.45
getMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected