@@ -39,6 +39,12 @@ def GDB_NAME():
3939 return f"{ COMPILER_TRIPLE } -gdb"
4040
4141
42+ # if you change the do not edit headline you need to change the check for it in cmakeUtil.mts
43+ CMAKE_DO_NOT_EDIT_HEADER_PREFIX = "== DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work =="
44+ CMAKE_DO_NOT_EDIT_HEADER_PREFIX_OLD = (
45+ "== DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work =="
46+ )
47+
4248VSCODE_LAUNCH_FILENAME = "launch.json"
4349VSCODE_C_PROPERTIES_FILENAME = "c_cpp_properties.json"
4450VSCODE_CMAKE_KITS_FILENAME = "cmake-kits.json"
@@ -736,9 +742,8 @@ def GenerateCMake(folder, params):
736742 "# (note this can come from environment, CMake cache etc)\n \n "
737743 )
738744
739- # if you change the do not edit headline you need to change the check for it in extension.mts
740745 cmake_header_us = (
741- "# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == \n "
746+ f "# { CMAKE_DO_NOT_EDIT_HEADER_PREFIX } \n "
742747 "if(WIN32)\n "
743748 " set(USERHOME $ENV{USERPROFILE})\n "
744749 "else()\n "
@@ -774,11 +779,24 @@ def GenerateCMake(folder, params):
774779 lines = file .readlines ()
775780 file .seek (0 )
776781 if not params ["wantExample" ]:
777- # Prexisting CMake configuration - just adding cmake_header_us
778- file .write (cmake_header_us )
779- # If no PICO_BOARD, then add a line for that, defaulting to pico
780- if not any (["set(PICO_BOARD" in line for line in lines ]):
781- file .write (f'set(PICO_BOARD pico CACHE STRING "Board type")\n \n ' )
782+ if CMAKE_DO_NOT_EDIT_HEADER_PREFIX in content :
783+ print (
784+ "Not adding duplicate header to existing Pico VS Code project"
785+ )
786+ elif CMAKE_DO_NOT_EDIT_HEADER_PREFIX_OLD in content :
787+ print ("Replacing old header with new" )
788+ content = content .replace (
789+ CMAKE_DO_NOT_EDIT_HEADER_PREFIX_OLD ,
790+ CMAKE_DO_NOT_EDIT_HEADER_PREFIX ,
791+ )
792+ else :
793+ # Prexisting CMake configuration - just adding cmake_header_us
794+ file .write (cmake_header_us )
795+ # If no PICO_BOARD, then add a line for that, defaulting to pico
796+ if not any (["set(PICO_BOARD" in line for line in lines ]):
797+ file .write (
798+ f'set(PICO_BOARD pico CACHE STRING "Board type")\n \n '
799+ )
782800 file .write (content )
783801 else :
784802 if any (
0 commit comments