diff --git a/scripts/pico_project.py b/scripts/pico_project.py index 57bde10..3af4d22 100644 --- a/scripts/pico_project.py +++ b/scripts/pico_project.py @@ -448,6 +448,7 @@ def ParseCommandLine(): parser.add_argument("-g", "--gui", action='store_true', help="Run a GUI version of the project generator") parser.add_argument("-p", "--project", action='append', help="Generate projects files for IDE. Options are: vscode") parser.add_argument("-r", "--runFromRAM", action='store_true', help="Run the program from RAM rather than flash") + parser.add_argument("-e", "--entryProjName", action='store_true', help="Use project name as entry point file name") parser.add_argument("-uart", "--uart", action='store_true', default=1, help="Console output to UART (default)") parser.add_argument("-nouart", "--nouart", action='store_true', default=0, help="Disable console output to UART") parser.add_argument("-usb", "--usb", action='store_true', help="Console output to USB (disables other USB functionality") @@ -471,12 +472,13 @@ def ParseCommandLine(): return parser.parse_args() -def GenerateMain(folder, projectName, features, cpp): +def GenerateMain(folder, projectName, features, cpp, wantEntryProjName): + executableName = projectName if wantEntryProjName else "main" if cpp: - filename = Path(folder) / (projectName + '.cpp') + filename = Path(folder) / (executableName + '.cpp') else: - filename = Path(folder) / (projectName + '.c') + filename = Path(folder) / (executableName + '.c') file = open(filename, 'w') @@ -669,15 +671,14 @@ def GenerateCMake(folder, params): file.write(f'add_compile_definitions({c} = {v})\n') file.write('\n') - # No GUI/command line to set a different executable name at this stage - executableName = projectName + entry_point_file_name = projectName if params['wantEntryProjName'] else "main" if params['wantCPP']: - file.write(f'add_executable({projectName} {projectName}.cpp )\n\n') + file.write(f'add_executable({projectName} {entry_point_file_name}.cpp )\n\n') else: - file.write(f'add_executable({projectName} {projectName}.c )\n\n') + file.write(f'add_executable({projectName} {entry_point_file_name}.c )\n\n') - file.write(f'pico_set_program_name({projectName} "{executableName}")\n') + file.write(f'pico_set_program_name({projectName} "{projectName}")\n') file.write(f'pico_set_program_version({projectName} "0.1")\n\n') if params['wantRunFromRAM']: @@ -1142,7 +1143,7 @@ def DoEverything(parent, params): features_and_examples = list(stdlib_examples_list.keys()) + features_and_examples if not (params['wantConvert']): - GenerateMain(projectPath, params['projectName'], features_and_examples, params['wantCPP']) + GenerateMain(projectPath, params['projectName'], features_and_examples, params['wantCPP'], params['wantEntryProjName']) # If we have any ancilliary files, copy them to our project folder # Currently only the picow with lwIP support needs an extra file, so just check that list @@ -1323,6 +1324,7 @@ def DoEverything(parent, params): 'projects' : args.project, 'configs' : (), 'wantRunFromRAM': args.runFromRAM, + 'wantEntryProjName': args.entryProjName, 'wantExamples' : args.examples, 'wantUART' : args.uart, 'wantUSB' : args.usb, diff --git a/src/webview/newProjectPanel.mts b/src/webview/newProjectPanel.mts index fc7621c..bd738bf 100644 --- a/src/webview/newProjectPanel.mts +++ b/src/webview/newProjectPanel.mts @@ -113,6 +113,7 @@ interface SubmitMessageValue extends ImportProjectMessageValue { // code generation options addExamples: boolean; runFromRAM: boolean; + entryPointProjectName: boolean; cpp: boolean; cppRtti: boolean; cppExceptions: boolean; @@ -156,6 +157,7 @@ enum PicoWirelessOption { enum CodeOption { addExamples = "Add examples from Pico library", runFromRAM = "Run the program from RAM rather than flash", + entryPointProjectName = "Use project name as entry point file name", cpp = "Generate C++ code", cppRtti = "Enable C++ RTTI (Uses more memory)", cppExceptions = "Enable C++ exceptions (Uses more memory)", @@ -235,6 +237,8 @@ function enumToParam( return "-x"; case CodeOption.runFromRAM: return "-r"; + case CodeOption.entryPointProjectName: + return "-e"; case CodeOption.cpp: return "-cpp"; case CodeOption.cppRtti: @@ -1090,6 +1094,9 @@ export class NewProjectPanel { codeOptions: [ theData.addExamples ? CodeOption.addExamples : null, theData.runFromRAM ? CodeOption.runFromRAM : null, + theData.entryPointProjectName + ? CodeOption.entryPointProjectName + : null, theData.cpp ? CodeOption.cpp : null, theData.cppRtti ? CodeOption.cppRtti : null, theData.cppExceptions ? CodeOption.cppExceptions : null, @@ -1931,6 +1938,12 @@ export class NewProjectPanel { +
  • +
    + + +
    +