Open atom0s opened 6 months ago
Following up on this; I've done some more testing and have found the cause of the above error happening again. This time it does not appear to be the same cause as the last time, but this does look to be a potential new bug.
This new cause for this error message appears to be based on when the following is potentially called:
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH OFF)
If a project makes use of this setting in the same manner anywhere before the project is actually defined using the project(..)
call, then this error will occur. This can happen if:
include(..)
that makes this call.find_package(..)
that makes this call.CMakeLists.txt
prior to calling project(..)
.I believe this is technically a bug still as the documentation for CMake does not strictly state when this call can happen. It is also not explicit when describing when project(..)
should be called, other than that it must be called in the main CMakeLists.txt
. It also only recommends in the docs that the call to project(..)
is made close to the top of the file and only encourages its use after cmake_minimum_required
is called.
Moving the project(..)
call above any attempts of using the above fixes the error.
@atom0s Thanks for the additional investigation and information! Do you happen to know if this reproduced on the command line as well?
Could you please send us a repro project so that I can also find your investigation findings? It'd be good to make sure we have an entirely full understanding so that we can know where the issue (or at least the confusion) is stemming from. It may be that this issue is not stemming from the extension but from CMake itself. Thank you!
Do you happen to know if this reproduced on the command line as well?
Yes, this same issue happens directly from CMakes command line. This is looking more like a CMake bug or simply a lack of good documentation on when project(..)
should be called. The official documentation page gives some basic overview of when it should be called but doesn't explicitly say other calls can't come before it except that cmake_minimum_required
must be first.
https://cmake.org/cmake/help/latest/command/project.html#project
Could you please send us a repro project so that I can also find your investigation findings?
Sure, I don't believe this issue is the fault of vscode-cmake-tools now after command line testing, but will still attach and explain my process in case its useful for other purposes.
Attached to this post is a simple project that tries to build a single .cpp
file. I tried to keep things bare minimum to reproduce the bug and still be able to compile normally when 'fixed'.
As-is, the project should fail to configure with CMake due to this 'bug'.
To reproduce with the zip I have attached, here's the steps I am using locally:
C:\Users\atom0s\Desktop\test_cmake_bug\
Developer Command Prompt for VS 2022 (x86)
and navigate it to this new folder.cmake -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=C:/Users/atom0s/Desktop/test_cmake_bug/out/install/x86-debug-win -SC:/Users/atom0s/Desktop/test_cmake_bug -BC:/Users/atom0s/Desktop/test_cmake_bug/out/build/x86-debug-win -G Ninja
The error can be fixed by simply moving where project(..)
is called in the main CMakeLists.txt
of the project.
CMakeLists.txt
file in Notepad.project("test_cmake_bug" CXX)
line above the first set(..)
call.Attached is the example project. test_cmake_bug.zip
@atom0s Thank you very much for the detailed information. My apologies for the delayed response.
In order to best try to get you answers and possibly a solution, could you please open an issue on https://gitlab.kitware.com/cmake/cmake/-/issues? I would typically do this for you, but I think you'll be best suited to give all of the necessary context and explanation.
In the meantime, I've moved this issue to the Tracking
milestone and marked it in our project and with a label that it is an external issue.
Thank you!
Brief Issue Summary
I am once again getting this error upon updating to the latest VSCode Insiders and vscode-cmake-tools extension versions.
Previous error reported here: https://github.com/microsoft/vscode-cmake-tools/issues/3443
CMake Tools Diagnostics
Debug Log
Additional Information
This is happening similar to the previous time I reported this. https://github.com/microsoft/vscode-cmake-tools/issues/3443