CMake Qt project suddenly failing: “Cannot find source file” with duplicated file path after Git reset / vcpkg changes

Context: I have a CMake project that was working for building a Qt6 app using MSVC 2022, CMake, and vcpkg (manifest mode). I made some changes to try and get the project running fully via vcpkg, didn’t succeed, so I checked out my previously working branch (and even downloaded a fresh copy from GitHub as a zip). Now, out of nowhere, CMake refuses to generate build files.

Error:

CMake Error at C:/Users/Fabian/dev/vcpkg/scripts/buildsystems/vcpkg.cmake:600 (_add_executable):
  Cannot find source file:

    C:/Users/Fabian/dev/repos/Users/Fabian/dev/repos/InvokeInvoiceSystem/apps/src/main.cpp
1> [CMake] CMake Error at C:/Users/Fabian/dev/vcpkg/scripts/buildsystems/vcpkg.cmake:600 (_add_executable):
1> [CMake]   Cannot find source file:
1> [CMake] 
1> [CMake]     ../../../../../../Users/Fabian/dev/repos/InvokeInvoiceSystem/apps/src/main.cpp

Notice the file path is duplicated (my repo is at C:/Users/Fabian/dev/repos/InvokeInvoiceSystem). There is no such path as /Users/Fabian/dev/repos/Users/Fabian/dev/repos/…

Things I’ve tried:

Cleaned build directory (out/build/*), deleted CMake cache.

Fresh clone from GitHub (confirmed main.cpp exists at src/app/main.cpp).

Switching between branches, hard reset, etc.

Manually checked all CMakeLists.txt for obvious path errors.

Project structure (partial):

├── src/
│   ├── InvoiceSystem/
│   │   └── ... [core logic]
│   └── app/
│       └── main.cpp
├── CMakeLists.txt
├── src/app/CMakeLists.txt
Root CMakeLists.txt (snippet):
cmake_minimum_required(VERSION 3.24)
project(InvokeInvoiceSystem LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_PREFIX_PATH
    "C:/Users/Fabian/dev/vcpkg/installed/x64-windows/share"
    "C:/Qt/6.9.1/msvc2022_64/lib/cmake"
    CACHE STRING "Paths to vcpkg installed/share and Qt6 install prefix"
)

# ...find_package/fmt/bsoncxx/etc...

add_subdirectory(src/app)
src/app/CMakeLists.txt (snippet):

    file(GLOB_RECURSE APP_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
        # ...other globs for .ui, .qrc, headers
    )
    
    if(WIN32)
        qt_add_executable(InvokeInvoiceSystem WIN32
            ./main.cpp
            # ...other sources, all as relative paths
        )
    endif()

What I’m seeing:

CMake seems to concatenate paths in a weird way when trying to resolve main.cpp. I changed the folder structure trying to make it more like the qt CMake example but and this is when the error started. But it didn’t even work when trying a previously working push.

Worked fine before trying out vcpkg.

Questions:

What could cause CMake to generate these broken/duplicated file paths out of nowhere?

Is there something wrong with the way I’m specifying sources in qt_add_executable?

Is this a known problem when switching between vcpkg/non-vcpkg builds, or with CMake path caching?

Any advice would be appreciated! I’ve tried deleting build/cache, confirming paths, and even a clean clone but nothing fixes the path duplication issue.

Assuming this is your project, I tried to reproduce the problem, but I could not - the project configures fine. So I’d blame something in your environment. If anything, I was using MSVC PowerShell prompt.

The only changes I’ve made are in the CMakePresets.json (removed redundant compiler values, unhardcoded the path to vcpkg toolchain and removed CMAKE_PREFIX_PATH, as I prefer to set it from CLI):

@@ -8,10 +8,11 @@
       "binaryDir": "${sourceDir}/out/build/${presetName}",
       "installDir": "${sourceDir}/out/install/${presetName}",
       "cacheVariables": {
-        "CMAKE_C_COMPILER": "cl.exe",
-        "CMAKE_CXX_COMPILER": "cl.exe",
-        "CMAKE_TOOLCHAIN_FILE": "C:/Users/Fabian/dev/vcpkg/scripts/buildsystems/vcpkg.cmake",
-        "CMAKE_PREFIX_PATH": "C:/Users/Fabian/dev/vcpkg/installed/x64-windows/share;C:/Qt/6.9.1/msvc2022_64/lib/cmake"
+        "CMAKE_TOOLCHAIN_FILE":
+        {
+            "type": "FILEPATH",
+            "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
+        }
       },

and the configuration was invoked like this (I have a static Qt 6.8.1 at the moment, so I used that one):

$ cmake --preset x64-release -DCMAKE_PREFIX_PATH="d:/path/to/my/qt/6.8.1-static"
...
-- Configuring done (10.5s)
-- Generating done (0.2s)
-- Build files have been written to: E:/temp/iis/out/build/x64-release

It fails on building, though:

$ cd .\out\build\x64-release
$ cmake --build .
...
E:\temp\iis\src\InvoiceSystem\include\Accounts\UserBusiness\BusinessRepository.h(7): error C2027: use of undefined type 'AccountManager'

but that seems to be unrelated to your original problem.

I have kind of narrowed it down a little. It seems to be something to do with qt_add_executable. I am not sure why but changing it to just add_executable allows the generation to finish. But, I get an error saying theres no executable despite there being an executable listed in the run button on VS.