The latest getopt portable implementation written by mingw-w64 project is on:
https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/getopt.c https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-headers/crt/getopt.h
Just compile the getopt.c
with your code's target object together. I've tried it on Visual Studio 2022 CMake Project and it works fine.