I kinda do the opposite, that is, have a bash script check if there is a build directory, and if so, delete it, create it, then run CMake. I named the script cm.sh and the rp2350 one cm2350.sh. They are all in a directory named $HOME/scripts which is in my $PATH so I can run it from anywhere, but the idea is to run it from my source directory so build is a sub-directory.Another way is to add a bash function to .bash_profile. I am currently using the C SDK on MSYS2 and I like to remove build directories as soon as I'm done with something. Also, for many generic test programs I don't want to hard-code a board spec. So I wrote something to simplify things:I can cd to a directory and just run 'pico1' and don't need to use many brain cells to do that. And write a 'pico2' function when I get a RP2350 board. I have also simplified loading firmware to just 'flash'.Code:
# run this in the directory where CMakeLists.txt residespico1 (){ if [ -f CMakeLists.txt ]; then if [ -d build ]; then echo "pico1: build directory already present" else mkdir build cd build cmake .. -DPICO_BOARD=pico -DPICO_PLATFORM=rp2040 -G "MSYS Makefiles" fi else echo "pico1: no CMakeLists.txt file found" fi}
Code:
#!/bin/bash# Enable execution tracingset -xif ls | grep -q build; then rm -Rf "$PWD/build"fimkdir $PWD/buildcmake -DPICO_PLATFORM=rp2040 -DPICO_BOARD=pico -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Release -S $PWD -B $PWD/build#cmake -G Ninja -DPICO_PLATFORM=rp2040 -DPICO_BOARD=pico -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Release -S $PWD -B $PWD/buildStatistics: Posted by breaker — Tue Apr 15, 2025 3:10 am