diff options
| author | vm22 <[email protected]> | 2026-01-25 13:02:41 +0800 |
|---|---|---|
| committer | R b b666 <[email protected]> | 2026-01-27 13:04:11 +0800 |
| commit | 97e1f014a174069adc741c4e565d4d3ec343bf51 (patch) | |
| tree | 264e16d7107e5ce07587ca14e580e06becc1bfd3 | |
| parent | 5d1f199e9e44b14e93b6de7e68f73567ee3f371a (diff) | |
cmake: make CPPDEFINES handling robust for SCons-generated values
[tools][cmake] fix type handling when generating CMake targets
[Root Cause]
Unexpected macro definition types during `scons --target=cmake`
could trigger a TypeError and abort CMakeLists.txt generation.
[Solution]
Add support for handling different macro definition types.
[Affect Area]
cmake.py
[Test Suggestion]
Run `scons --target=cmake` and verify CMakeLists.txt is generated
successfully with different macro definition formats.
| -rw-r--r-- | tools/targets/cmake.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tools/targets/cmake.py b/tools/targets/cmake.py index e6c733217d..e1840e68bd 100644 --- a/tools/targets/cmake.py +++ b/tools/targets/cmake.py @@ -18,6 +18,7 @@ * 2024-11-18 kaidegit fix processing groups with similar name * 2025-02-22 kaidegit fix missing some flags added in Sconscript * 2025-02-24 kaidegit remove some code that is unnecessary but takes time, get them from env + * 2026-01-22 xym-ee Fix handling of tuple-based CPPDEFINES from SCons in CMake project generation. """ import os @@ -187,7 +188,24 @@ def GenerateCFiles(env, project, project_name): cm_file.write("ADD_DEFINITIONS(\n") for i in env['CPPDEFINES']: - cm_file.write("\t-D" + i + "\n") + # Handle CPPDEFINES from SCons (str / tuple) + if isinstance(i, tuple): + # e.g. ('STM32F407xx',) + if len(i) == 1: + cm_file.write("\t-D" + str(i[0]) + "\n") + # e.g. ('FOO', None) + elif len(i) == 2: + if i[1] is None: + cm_file.write("\t-D" + str(i[0]) + "\n") + # e.g. ('FOO', 1) + else: + cm_file.write("\t-D{}={}\n".format(i[0], i[1])) + else: + # unexpected form, fallback to name only + cm_file.write("\t-D" + str(i[0]) + "\n") + else: + # generic macro (commonly a string), ensure robust string conversion + cm_file.write("\t-D" + str(i) + "\n") cm_file.write(")\n\n") libgroups = [] |
