Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion tools/targets/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" + i[0] + "\n")
# e.g. ('FOO', None)
elif len(i) == 2:
if i[1] is None:
cm_file.write("\t-D" + 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:
# string macro, e.g. "FOO"
cm_file.write("\t-D" + i + "\n")
cm_file.write(")\n\n")

libgroups = []
Expand Down