microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.48k stars 454 forks source link

Failed to configure a cmake project under drive root #3987

Open huangqinjin opened 3 months ago

huangqinjin commented 3 months ago

Brief Issue Summary

CMakeLists.txt

cmake_minimum_required(VERSION 3.30)
project(tmp)
file(TOUCH tmp.cpp)
add_library(tmp tmp.cpp)

Put the CMakeLists.txt under drive root, e.g. D:, (or any folder and then subst), then open drive root with vscode.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.92.1",
  "cmtVersion": "1.18.44",
  "configurations": [
    {
      "folder": "d:\\",
      "cmakeVersion": "3.30.2",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe",
        "CXX": "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:///d%3A/hello.cpp"
    ],
    "responses": [],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "tmp",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}

Debug Log

[proc] : "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE --no-warn-unused-cli -SD:. -Bd:/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is MSVC 19.40.33813.0
[cmake] -- The CXX compiler identification is MSVC 19.40.33813.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Configuring done (1.3s)
[cmake] CMake Error at CMakeLists.txt:4 (add_library):
[cmake]   Cannot find source file:
[cmake] 
[cmake]     tmp.cpp
[cmake] 
[cmake] 
[cmake] CMake Error at CMakeLists.txt:4 (add_library):
[cmake]   No SOURCES given to target: tmp
[cmake] 
[cmake] 
[cmake] CMake Generate step failed.  Build files cannot be regenerated correctly.

Additional Information

I suspect the option -SD:. passed to cmake is the cause.

calebnwokocha commented 3 months ago

The issue you're encountering with CMake appears to be related to the file(TOUCH tmp.cpp) command in your CMakeLists.txt. The file(TOUCH tmp.cpp) command creates an empty file tmp.cpp but doesn't ensure it is correctly handled by CMake, especially if the file isn't present at the time of configuration. Here are steps to resolve the problem:

  1. Create the Source File Manually: Ensure that tmp.cpp exists in the directory where CMake expects it. You can manually create tmp.cpp with some placeholder content, such as:

    // tmp.cpp
    int main() {
       return 0;
    }
  2. Modify CMakeLists.txt: To make your CMakeLists.txt more robust, you might want to specify tmp.cpp directly in the file command or use file(WRITE ...) to ensure the file content is initialized properly. For example:

    cmake_minimum_required(VERSION 3.30)
    project(tmp)
    
    # Ensure tmp.cpp exists with some content
    file(WRITE ${CMAKE_BINARY_DIR}/tmp.cpp "int main() { return 0; }")
    
    # Add the library
    add_library(tmp ${CMAKE_BINARY_DIR}/tmp.cpp)

    Note that ${CMAKE_BINARY_DIR} is used to ensure the file is created in the build directory.

  3. Verify Paths: Ensure that paths are correctly specified. The error might also be due to an issue with where CMake is looking for tmp.cpp. Ensure that tmp.cpp is present in the expected location relative to the CMakeLists.txt.

  4. Re-run CMake: After making these changes, delete the existing build directory or any existing configuration files, and then re-run CMake:

    cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja ..
  5. Check CMake Presets: If you're using CMake presets, ensure that the preset configuration matches the setup you intend to use. For instance, if using presets, you might need to adjust settings or paths in your CMakePresets.json file.

By ensuring tmp.cpp is present and correctly referenced in CMakeLists.txt, you should be able to resolve the issues you're facing.

huangqinjin commented 3 months ago

The issue you're encountering with CMake appears to be related to the file(TOUCH tmp.cpp) command in your CMakeLists.txt.

No. It is just to make the repro minimal.

huangqinjin commented 3 months ago

Reported upstream https://gitlab.kitware.com/cmake/cmake/-/issues/26222.

Evelyn-001 commented 3 months ago

@huangqinjin, thanks for reporting this issue. Today we verified this issue with the CMakeLists.txt you mentioned, but we didn't repro it. Please see the below video. For further investigation, could you please share us a demo video with clear repro steps? We are looking forward to hearing from you. Thanks. ENV: VS Code:1.92.2 CMake Tools: v1.18.44 CMake: 3.30 image image

huangqinjin commented 3 months ago

@Evelyn-001 you are configuring the project from command line, nothing related to cmake-tools, please check the upstream issue.

To reproduce my issue reported here (cmake-tools), please simply click the Build button at the bottom status bar.

Evelyn-001 commented 3 months ago

@huangqinjin, Thanks for your reply. We have reproduced this issue with below ENV. Our development team will investigate this issue later and we will provide you with any updates. Thank you for your support. Env: VS code: 1.92.2 CMake Tool: v1.18.44 081903