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

**URL:** <https://discourse.cmake.org/t/cmake-qt-project-suddenly-failing-cannot-find-source-file-with-duplicated-file-path-after-git-reset-vcpkg-changes/14481>\
**Category:** Code\
**Created:** [August 2, 2025, 9:57am UTC](https://discourse.cmake.org/t/cmake-qt-project-suddenly-failing-cannot-find-source-file-with-duplicated-file-path-after-git-reset-vcpkg-changes/14481 "2025-08-02T09:57:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FabianDim](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fabiandim/32/5705_2.png) [@FabianDim](https://discourse.cmake.org/u/FabianDim)\
**Post date:** [August 2, 2025, 9:57am UTC](https://discourse.cmake.org/t/cmake-qt-project-suddenly-failing-cannot-find-source-file-with-duplicated-file-path-after-git-reset-vcpkg-changes/14481/1 "2025-08-02T09:57:05Z")

</div>

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:

```auto
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

```

```auto
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):

```auto
├── src/
│ ├── InvoiceSystem/
│ │ └── ... [core logic]
│ └── app/
│ └── main.cpp
├── CMakeLists.txt
├── src/app/CMakeLists.txt
Root CMakeLists.txt (snippet):

```

```auto
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.

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [August 2, 2025, 12:42pm UTC](https://discourse.cmake.org/t/cmake-qt-project-suddenly-failing-cannot-find-source-file-with-duplicated-file-path-after-git-reset-vcpkg-changes/14481/2 "2025-08-02T12:42:41Z")

</div>

Assuming [this](https://github.com/FabianDim/InvokeInvoiceSystem/tree/INFURIATING) 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](https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell).

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_):

```diff
@@ -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_):

```sh
$ 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:

```sh
$ 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.

---

<div class="post-metadata">

**Author:** ![FabianDim](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fabiandim/32/5705_2.png) [@FabianDim](https://discourse.cmake.org/u/FabianDim)\
**Post date:** [August 3, 2025, 3:45am UTC](https://discourse.cmake.org/t/cmake-qt-project-suddenly-failing-cannot-find-source-file-with-duplicated-file-path-after-git-reset-vcpkg-changes/14481/3 "2025-08-03T03:45:58Z")

</div>

> [@retif](#):
>
> `C:/Users/Fabian/dev/vcpkg/installed/x64-windows/share`

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.
