Skip to content

Commit c6b9111

Browse files
committed
Add CPP build options
Exceptions and RTTI.
1 parent 1d1734d commit c6b9111

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

pico_project.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@
205205
isWindows = False
206206

207207
class Parameters():
208-
def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, features, projects, configs, runFromRAM, examples, uart, usb, cpp, debugger):
208+
def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, features, projects,
209+
configs, runFromRAM, examples, uart, usb, cpp, debugger, exceptions, rtti):
209210
self.sdkPath = sdkPath
210211
self.projectRoot = projectRoot
211212
self.projectName = projectName
@@ -221,6 +222,8 @@ def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, fea
221222
self.wantUSB = usb
222223
self.wantCPP = cpp
223224
self.debugger = debugger
225+
self.exceptions = exceptions
226+
self.rtti = rtti
224227

225228
def GetBackground():
226229
return 'white'
@@ -649,7 +652,7 @@ def init_window(self, args):
649652

650653
# Code options section
651654
coptionsSubframe = ttk.LabelFrame(mainFrame, relief=tk.RIDGE, borderwidth=2, text="Code Options")
652-
coptionsSubframe.grid(row=optionsRow, column=0, columnspan=5, rowspan=2, padx=5, pady=5, ipadx=5, ipady=3, sticky=tk.E+tk.W)
655+
coptionsSubframe.grid(row=optionsRow, column=0, columnspan=5, rowspan=3, padx=5, pady=5, ipadx=5, ipady=3, sticky=tk.E+tk.W)
653656

654657
self.wantExamples = tk.IntVar()
655658
self.wantExamples.set(args.examples)
@@ -665,7 +668,15 @@ def init_window(self, args):
665668

666669
ttk.Button(coptionsSubframe, text="Advanced...", command=self.config).grid(row=0, column=4, sticky=tk.E)
667670

668-
optionsRow += 2
671+
self.wantCPPExceptions = tk.IntVar()
672+
self.wantCPPExceptions.set(args.cppexceptions)
673+
ttk.Checkbutton(coptionsSubframe, text="Enable C++ exceptions", variable=self.wantCPPExceptions).grid(row=1, column=0, padx=4, sticky=tk.W)
674+
675+
self.wantCPPRTTI = tk.IntVar()
676+
self.wantCPPRTTI.set(args.cpprtti)
677+
ttk.Checkbutton(coptionsSubframe, text="Enable C++ RTTI", variable=self.wantCPPRTTI).grid(row=1, column=1, padx=4, sticky=tk.W)
678+
679+
optionsRow += 3
669680

670681
# Build Options section
671682

@@ -735,7 +746,7 @@ def OK(self):
735746
gui=True, overwrite=self.wantOverwrite.get(), build=self.wantBuild.get(),
736747
features=features, projects=projects, configs=self.configs, runFromRAM=self.wantRunFromRAM.get(),
737748
examples=self.wantExamples.get(), uart=self.wantUART.get(), usb=self.wantUSB.get(), cpp=self.wantCPP.get(),
738-
debugger=self.debugger.current())
749+
debugger=self.debugger.current(), exceptions=self.wantCPPExceptions, rtti=self.wantCPPRTTI)
739750

740751
DoEverything(self, p)
741752

@@ -799,6 +810,8 @@ def ParseCommandLine():
799810
parser.add_argument("-nouart", "--nouart", action='store_true', default=0, help="Disable console output to UART")
800811
parser.add_argument("-usb", "--usb", action='store_true', help="Console output to USB (disables other USB functionality")
801812
parser.add_argument("-cpp", "--cpp", action='store_true', default=0, help="Generate C++ code")
813+
parser.add_argument("-cpprtti", "--cpprtti", action='store_true', default=0, help="Enable C++ RTTI (Uses more memory)")
814+
parser.add_argument("-cppex", "--cppexceptions", action='store_true', default=0, help="Enable C++ exceptions (Uses more memory)")
802815
parser.add_argument("-d", "--debugger", type=int, help="Select debugger (0 = SWD, 1 = PicoProbe)", default=0)
803816

804817
return parser.parse_args()
@@ -881,7 +894,7 @@ def GenerateCMake(folder, params):
881894
)
882895

883896
cmake_header3 = (
884-
"# Initialise the Pico SDK\n"
897+
"\n# Initialise the Pico SDK\n"
885898
"pico_sdk_init()\n\n"
886899
"# Add executable. Default name is the project name, version 0.1\n\n"
887900
)
@@ -901,7 +914,14 @@ def GenerateCMake(folder, params):
901914

902915
file.write('set(PICO_SDK_PATH ' + p + ')\n\n')
903916
file.write(cmake_header2)
904-
file.write('project(' + params.projectName + ' C CXX ASM)\n\n')
917+
file.write('project(' + params.projectName + ' C CXX ASM)\n')
918+
919+
if params.exceptions:
920+
file.write("\nset(PICO_CXX_ENABLE_EXCEPTIONS 1)\n")
921+
922+
if params.rtti:
923+
file.write("\nset(PICO_CXX_ENABLE_RTTI 1)\n")
924+
905925
file.write(cmake_header3)
906926

907927
# add the preprocessor defines for overall configuration
@@ -982,11 +1002,7 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger):
9821002
' "type": "cortex-debug",\n'
9831003
' "servertype": "openocd",\n'
9841004
' "gdbPath": "gdb-multiarch",\n'
985-
<<<<<<< HEAD
9861005
' "device": "RP2040",\n'
987-
=======
988-
' "device": "Pico2040",\n'
989-
>>>>>>> Add a debugger selection options, some GUI rearrangement. Update readme
9901006
' "configFiles": [\n' + \
9911007
' "interface/' + deb + '",\n' + \
9921008
' "target/rp2040.cfg"\n' + \
@@ -1227,7 +1243,7 @@ def DoEverything(parent, params):
12271243
p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name,
12281244
gui=False, overwrite=args.overwrite, build=args.build, features=args.feature,
12291245
projects=args.project, configs=(), runFromRAM=args.runFromRAM,
1230-
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger)
1246+
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger, exceptions=args.cppexceptions, rtti=args.cpprtti)
12311247

12321248
DoEverything(None, p)
12331249

0 commit comments

Comments
 (0)