How to build OpenCV Without Visual Studio

I’m using VSCode, CMake v 3.27, GCC13.2 (x86_64-w64-mingw32), OpenCV 4.9 Windows downloaded and installed from here. My toolchain works for a handful of other c++ projects I work on.

From what I can tell, I need to use find_package (though I’d far prefer to add_subdirectory and build it directly from source as a subproject like I would most other libs. Is there a reason I can’t do that?)

cmake_minimum_required(VERSION 3.27)
set(OpenCV_DIR "~/openvc/opencv-4.9.0/build/")
find_package(OpenCV REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

My CMake mostly works, in that it’s no longer complaining on an inability to find OpenCV since I added OpenCV_Dir. Now CMake configures properly, but on build fails as:

No rule to make target ‘~/openvc/opencv-4.9.0/build/lib/libopencv_gapi490.dll.a’, needed by ‘testcv.exe’

Or in VS build tools,

INK : fatal error LNK1104: cannot open file ‘~\openvc\opencv-4.9.0\build\lib\libopencv_gapi490.dll.a’

My Main file is trivial, really just contains an

#include <opencv2/opencv.hpp>

I’m not clear what I’m missing, and admittedly I found the OpenCV build documentation very unhelpful. I’ve tried a few different iterations of my CMakeLists and I’m not sure what else to try. Any help would be great appreciated!