@@ -39,8 +39,6 @@ def GDB_NAME():
3939    return  f"{ COMPILER_TRIPLE }  -gdb" 
4040
4141
42- CMAKE_TOOLCHAIN_NAME  =  "pico_arm_gcc.cmake" 
43- 
4442VSCODE_LAUNCH_FILENAME  =  "launch.json" 
4543VSCODE_C_PROPERTIES_FILENAME  =  "c_cpp_properties.json" 
4644VSCODE_CMAKE_KITS_FILENAME  =  "cmake-kits.json" 
@@ -475,29 +473,12 @@ def semver_compare_ge(first, second):
475473    return  first_tuple  >=  second_tuple 
476474
477475
478- def  CheckPrerequisites ():
476+ def  CheckSystemType ():
479477    global  isMac , isWindows , isx86 
480478    isMac  =  platform .system () ==  "Darwin" 
481479    isWindows  =  platform .system () ==  "Windows" 
482480    isx86  =  platform .machine ().lower () in  ["x86_64" , "amd64" ]
483481
484-     # Do we have a compiler? 
485-     return  shutil .which (COMPILER_NAME (), 1 , os .environ ["Path"  if  isWindows  else  "PATH" ])
486- 
487- 
488- def  CheckSDKPath (gui ):
489-     sdkPath  =  os .getenv ("PICO_SDK_PATH" )
490- 
491-     if  sdkPath  ==  None :
492-         m  =  "Unable to locate the Raspberry Pi Pico SDK, PICO_SDK_PATH is not set" 
493-         print (m )
494-     elif  not  os .path .isdir (sdkPath ):
495-         m  =  "Unable to locate the Raspberry Pi Pico SDK, PICO_SDK_PATH does not point to a directory" 
496-         print (m )
497-         sdkPath  =  None 
498- 
499-     return  sdkPath 
500- 
501482
502483def  GetFilePath (filename ):
503484    if  os .path .islink (__file__ ):
@@ -513,18 +494,6 @@ def ParseCommandLine():
513494    )
514495    parser  =  argparse .ArgumentParser (description = "Pico Project generator" )
515496    parser .add_argument ("name" , nargs = "?" , help = "Name of the project" )
516-     parser .add_argument (
517-         "-t" ,
518-         "--tsv" ,
519-         help = "Select an alternative pico_configs.tsv file" ,
520-         default = GetFilePath ("pico_configs.tsv" ),
521-     )
522-     parser .add_argument (
523-         "-o" ,
524-         "--output" ,
525-         help = "Set an alternative CMakeList.txt filename" ,
526-         default = "CMakeLists.txt" ,
527-     )
528497    parser .add_argument (
529498        "-x" ,
530499        "--examples" ,
@@ -537,15 +506,6 @@ def ParseCommandLine():
537506        action = "store_true" ,
538507        help = "Add example code for UART support with the Pico SDK" ,
539508    )
540-     parser .add_argument (
541-         "-l" , "--list" , action = "store_true" , help = "List available features" 
542-     )
543-     parser .add_argument (
544-         "-c" ,
545-         "--configs" ,
546-         action = "store_true" ,
547-         help = "List available project configuration items" ,
548-     )
549509    parser .add_argument (
550510        "-f" , "--feature" , action = "append" , help = "Add feature to generated project" 
551511    )
@@ -567,15 +527,6 @@ def ParseCommandLine():
567527        action = "store_true" ,
568528        help = "Convert an examples folder to standalone project" ,
569529    )
570-     parser .add_argument (
571-         "-b" , "--build" , action = "store_true" , help = "Build after project created" 
572-     )
573-     parser .add_argument (
574-         "-g" ,
575-         "--gui" ,
576-         action = "store_true" ,
577-         help = "Run a GUI version of the project generator" ,
578-     )
579530    parser .add_argument (
580531        "-p" ,
581532        "--project" ,
@@ -645,10 +596,6 @@ def ParseCommandLine():
645596        default = "pico" ,
646597        help = "Select board type (see --boardlist for available boards)" ,
647598    )
648-     parser .add_argument (
649-         "-bl" , "--boardlist" , action = "store_true" , help = "List available board types" 
650-     )
651-     parser .add_argument ("-cp" , "--cpath" , help = "Override default VSCode compiler path" )
652599    parser .add_argument (
653600        "-root" ,
654601        "--projectRoot" ,
@@ -687,6 +634,11 @@ def ParseCommandLine():
687634        action = "store_true" ,
688635        help = "Enable CMake Tools extension integration" ,
689636    )
637+     parser .add_argument (
638+         "-uhome" ,
639+         "--userHome" ,
640+         help = "Full path to user's home directory" ,
641+     )
690642
691643    return  parser .parse_args ()
692644
@@ -957,7 +909,7 @@ def GenerateCMake(folder, params):
957909    # Standard include directories 
958910    file .write ("# Add the standard include files to the build\n " )
959911    file .write (f"target_include_directories({ projectName }   PRIVATE\n " )
960-     file .write ("  ${CMAKE_CURRENT_LIST_DIR}\n " )
912+     file .write ("        "    +   " ${CMAKE_CURRENT_LIST_DIR}\n " )
961913    file .write (")\n \n " )
962914
963915    # Selected libraries/features 
@@ -980,7 +932,6 @@ def GenerateCMake(folder, params):
980932def  generateProjectFiles (
981933    projectPath ,
982934    projectName ,
983-     sdkPath ,
984935    projects ,
985936    debugger ,
986937    sdkVersion ,
@@ -1338,40 +1289,7 @@ def generateProjectFiles(
13381289    os .chdir (oldCWD )
13391290
13401291
1341- def  LoadConfigurations ():
1342-     try :
1343-         with  open (args .tsv ) as  tsvfile :
1344-             reader  =  csv .DictReader (tsvfile , dialect = "excel-tab" )
1345-             for  row  in  reader :
1346-                 configuration_dictionary .append (row )
1347-     except :
1348-         print ("No Pico configurations file found. Continuing without" )
1349- 
1350- 
1351- def  LoadBoardTypes (sdkPath ):
1352-     # Scan the boards folder for all header files, extract filenames, and make a list of the results 
1353-     # default folder is <PICO_SDK_PATH>/src/boards/include/boards/* 
1354-     # If the PICO_BOARD_HEADER_DIRS environment variable is set, use that as well 
1355- 
1356-     loc  =  sdkPath  /  "src/boards/include/boards" 
1357-     boards  =  []
1358-     for  x  in  Path (loc ).iterdir ():
1359-         if  x .suffix  ==  ".h" :
1360-             boards .append (x .stem )
1361- 
1362-     loc  =  os .getenv ("PICO_BOARD_HEADER_DIRS" )
1363- 
1364-     if  loc  !=  None :
1365-         for  x  in  Path (loc ).iterdir ():
1366-             if  x .suffix  ==  ".h" :
1367-                 boards .append (x .stem )
1368- 
1369-     return  boards 
1370- 
1371- 
1372- def  DoEverything (parent , params ):
1373-     global  CMAKE_TOOLCHAIN_NAME 
1374- 
1292+ def  DoEverything (params ):
13751293    if  not  os .path .exists (params ["projectRoot" ]):
13761294        print ("Invalid project path" )
13771295        sys .exit (- 1 )
@@ -1404,7 +1322,11 @@ def DoEverything(parent, params):
14041322    # Copy the SDK finder cmake file to our project folder 
14051323    # Can be found here <PICO_SDK_PATH>/external/pico_sdk_import.cmake 
14061324    shutil .copyfile (
1407-         params ["sdkPath" ] /  "external"  /  "pico_sdk_import.cmake" ,
1325+         os .path .join (
1326+             params ["userHome" ] +  relativeSDKPath (params ["sdkVersion" ]),
1327+             "external" ,
1328+             "pico_sdk_import.cmake" ,
1329+         ),
14081330        projectPath  /  "pico_sdk_import.cmake" ,
14091331    )
14101332
@@ -1467,46 +1389,10 @@ def DoEverything(parent, params):
14671389    if  os .path .exists (CMAKECACHE_FILENAME ):
14681390        os .remove (CMAKECACHE_FILENAME )
14691391
1470-     cpus  =  os .cpu_count ()
1471-     if  cpus  ==  None :
1472-         cpus  =  1 
1473- 
1474-     if  isWindows :
1475-         if  shutil .which ("ninja" ) or  (
1476-             params ["ninjaPath" ] !=  None  and  params ["ninjaPath" ] !=  "" 
1477-         ):
1478-             # When installing SDK version 1.5.0 on windows with installer pico-setup-windows-x64-standalone.exe, ninja is used 
1479-             cmakeCmd  =  params ["cmakePath" ] +  " -G Ninja .." 
1480-             makeCmd  =  params ["ninjaPath" ] +  " " 
1481-         else :
1482-             # Everything else assume nmake 
1483-             cmakeCmd  =  params ["cmakePath" ] +  ' -G "NMake Makefiles" ..' 
1484-             makeCmd  =  "nmake " 
1485-     else :
1486-         # Ninja now works OK under Linux, so if installed use it by default. It's faster. 
1487-         if  shutil .which ("ninja" ) or  (
1488-             params ["ninjaPath" ] !=  None  and  params ["ninjaPath" ] !=  "" 
1489-         ):
1490-             cmakeCmd  =  params ["cmakePath" ] +  " -G Ninja .." 
1491-             makeCmd  =  params ["ninjaPath" ] +  " " 
1492-         else :
1493-             cmakeCmd  =  params ["cmakePath" ] +  " .." 
1494-             makeCmd  =  "make -j"  +  str (cpus )
1495- 
1496-     os .system (cmakeCmd )
1497- 
1498-     # Extract CMake Toolchain File 
1499-     if  os .path .exists (CMAKECACHE_FILENAME ):
1500-         cacheFile  =  open (CMAKECACHE_FILENAME , "r" )
1501-         for  line  in  cacheFile :
1502-             if  re .search ("CMAKE_TOOLCHAIN_FILE:FILEPATH=" , line ):
1503-                 CMAKE_TOOLCHAIN_NAME  =  line .split ("=" )[- 1 ].split ("/" )[- 1 ].strip ()
1504- 
15051392    if  params ["projects" ]:
15061393        generateProjectFiles (
15071394            projectPath ,
15081395            params ["projectName" ],
1509-             params ["sdkPath" ],
15101396            params ["projects" ],
15111397            params ["debugger" ],
15121398            params ["sdkVersion" ],
@@ -1518,12 +1404,6 @@ def DoEverything(parent, params):
15181404            params ["useCmakeTools" ],
15191405        )
15201406
1521-     if  params ["wantBuild" ]:
1522-         os .system (makeCmd )
1523-         print (
1524-             "\n If the application has built correctly, you can now transfer it to the Raspberry Pi Pico board" 
1525-         )
1526- 
15271407    os .chdir (oldCWD )
15281408
15291409
@@ -1547,111 +1427,58 @@ def DoEverything(parent, params):
15471427        else :
15481428            COMPILER_TRIPLE  =  RISCV_TRIPLE 
15491429
1550-     # Check we have everything we need to compile etc 
1551-     c  =  CheckPrerequisites ()
1552- 
1553-     ## TODO Do both warnings in the same error message so user does have to keep coming back to find still more to do 
1554- 
1555-     if  c  ==  None :
1556-         m  =  f"Unable to find the `{ COMPILER_NAME ()}  ` compiler\n " 
1557-         m  +=  "You will need to install an appropriate compiler to build a Raspberry Pi Pico project\n " 
1558-         m  +=  "See the Raspberry Pi Pico documentation for how to do this on your particular platform\n " 
1559- 
1560-         print (m )
1561-         sys .exit (- 1 )
1430+     # Populate isMac, isWindows, isx86 variables 
1431+     CheckSystemType ()
15621432
1563-     if  (
1564-         args .name  ==  None 
1565-         and  not  args .gui 
1566-         and  not  args .list 
1567-         and  not  args .configs 
1568-         and  not  args .boardlist 
1569-     ):
1433+     if  args .name  ==  None :
15701434        print ("No project name specfied\n " )
15711435        sys .exit (- 1 )
15721436
15731437    # Check if we were provided a compiler path, and override the default if so 
1574-     if  args .cpath :
1575-         compilerPath  =  Path (args .cpath )
1576-     elif  args .toolchainVersion :
1438+     if  args .toolchainVersion :
15771439        compilerPath  =  Path (
15781440            codeToolchainPath (args .toolchainVersion ) +  "/bin/"  +  COMPILER_NAME ()
15791441        )
15801442    else :
1581-         compilerPath  =  Path (c )
1582- 
1583-     # load/parse any configuration dictionary we may have 
1584-     LoadConfigurations ()
1585- 
1586-     p  =  CheckSDKPath (args .gui )
1587- 
1588-     if  p  ==  None :
1443+         print ("No toolchain version specfied\n " )
15891444        sys .exit (- 1 )
15901445
1591-     sdkPath  =  Path (p )
1592- 
1593-     boardtype_list  =  LoadBoardTypes (sdkPath )
1594-     boardtype_list .sort ()
1595- 
15961446    projectRoot  =  Path (os .getcwd ()) if  not  args .projectRoot  else  Path (args .projectRoot )
15971447
1598-     if  args .list  or  args .configs  or  args .boardlist :
1599-         if  args .list :
1600-             print ("Available project features:\n " )
1601-             for  feat  in  features_list :
1602-                 print (feat .ljust (6 ), "\t " , features_list [feat ][GUI_TEXT ])
1603-             print ("\n " )
1604- 
1605-         if  args .configs :
1606-             print ("Available project configuration items:\n " )
1607-             for  conf  in  configuration_dictionary :
1608-                 print (conf ["name" ].ljust (40 ), "\t " , conf ["description" ])
1609-             print ("\n " )
1610- 
1611-         if  args .boardlist :
1612-             print ("Available board types:\n " )
1613-             for  board  in  boardtype_list :
1614-                 print (board )
1615-             print ("\n " )
1616- 
1617-         sys .exit (0 )
1618-     else :
1619-         params  =  {
1620-             "sdkPath" : sdkPath ,
1621-             "projectRoot" : projectRoot ,
1622-             "projectName" : args .name ,
1623-             "wantGUI" : False ,
1624-             "wantOverwrite" : args .overwrite ,
1625-             "wantConvert" : args .convert  or  args .example ,
1626-             "wantExample" : args .example ,
1627-             "wantThreadsafeBackground" : False ,
1628-             "wantPoll" : False ,
1629-             "boardtype" : args .boardtype ,
1630-             "wantBuild" : args .build ,
1631-             "features" : args .feature ,
1632-             "projects" : args .project ,
1633-             "configs" : (),
1634-             "wantRunFromRAM" : args .runFromRAM ,
1635-             "wantEntryProjName" : args .entryProjName ,
1636-             "wantExamples" : args .examples ,
1637-             "wantUARTExample" : args .uartExample ,
1638-             "wantUART" : args .uart ,
1639-             "wantUSB" : args .usb ,
1640-             "wantCPP" : args .cpp ,
1641-             "debugger" : args .debugger ,
1642-             "exceptions" : args .cppexceptions ,
1643-             "rtti" : args .cpprtti ,
1644-             "ssid" : "" ,
1645-             "password" : "" ,
1646-             "sdkVersion" : args .sdkVersion ,
1647-             "toolchainVersion" : args .toolchainVersion ,
1648-             "picotoolVersion" : args .picotoolVersion ,
1649-             "ninjaPath" : args .ninjaPath ,
1650-             "cmakePath" : args .cmakePath ,
1651-             "openOCDVersion" : args .openOCDVersion ,
1652-             "exampleLibs" : args .exampleLibs  if  args .exampleLibs  is  not   None  else  [],
1653-             "useCmakeTools" : args .useCmakeTools ,
1654-         }
1655- 
1656-         DoEverything (None , params )
1657-         sys .exit (0 )
1448+     params  =  {
1449+         "projectRoot" : projectRoot ,
1450+         "userHome" : args .userHome ,
1451+         "projectName" : args .name ,
1452+         "wantOverwrite" : args .overwrite ,
1453+         "wantConvert" : args .convert  or  args .example ,
1454+         "wantExample" : args .example ,
1455+         "wantThreadsafeBackground" : False ,
1456+         "wantPoll" : False ,
1457+         "boardtype" : args .boardtype ,
1458+         "features" : args .feature ,
1459+         "projects" : args .project ,
1460+         "configs" : (),
1461+         "wantRunFromRAM" : args .runFromRAM ,
1462+         "wantEntryProjName" : args .entryProjName ,
1463+         "wantExamples" : args .examples ,
1464+         "wantUARTExample" : args .uartExample ,
1465+         "wantUART" : args .uart ,
1466+         "wantUSB" : args .usb ,
1467+         "wantCPP" : args .cpp ,
1468+         "debugger" : args .debugger ,
1469+         "exceptions" : args .cppexceptions ,
1470+         "rtti" : args .cpprtti ,
1471+         "ssid" : "" ,
1472+         "password" : "" ,
1473+         "sdkVersion" : args .sdkVersion ,
1474+         "toolchainVersion" : args .toolchainVersion ,
1475+         "picotoolVersion" : args .picotoolVersion ,
1476+         "ninjaPath" : args .ninjaPath ,
1477+         "cmakePath" : args .cmakePath ,
1478+         "openOCDVersion" : args .openOCDVersion ,
1479+         "exampleLibs" : args .exampleLibs  if  args .exampleLibs  is  not   None  else  [],
1480+         "useCmakeTools" : args .useCmakeTools ,
1481+     }
1482+ 
1483+     DoEverything (params )
1484+     sys .exit (0 )
0 commit comments