Open wheeeper opened 9 months ago
@wheeeper To help me investigate this and to fully understand your problem, could you please attach a zip of a reproduction of this issue, so that I can investigate it on my machine?
More specifically, I'm not fully understanding where I should be looking for the issue. I've somewhat reproduced the CMakePresets and CMakeLists, but where is the issue actually arising?
@gcampbell-msft Here is a project for reproduction: vscode-cmake-bug.zip
There are two issues that I'm noticing:
Lets say that you select preset DEV1 first. If you then open firstly a header file (in this case the dll/dll.h), you don't get correct IntelliSense information, and in the C/C++ debug you can see that it ignores settings set in c_cpp_properties.json as well (at least the C++ standard). If you then inspect a source file (in this case dll/dll.cpp), the IntelliSense info gets "loaded" and is shown correctly, even when you go back to the aforementioned header file.
If you then select another preset, lets say DEV2, and look in dll/dll.cpp, the IntelliSense info doesn't get updated, even though that with change of the preset the previously set macro is not defined and different is defined. Looking in the C/C++ debug confirms this, as it shows the old defines. Also if you're again looking firstly in the header file, the whole IntelliSense info is missing again.
Brief Issue Summary
Summary
I have multiple presets defined in
CMakePresets.json
and each looks like this.The configured variable TARGET_CONFIG is then passed to CMakeLists.txt by using
add_compile_definitions(${TARGET_CONFIG})
.When I load the project, the a last used preset is used. If I look in the header file, where the used macro is used, it doesn't recognize the macro defined, and when looking in the C/C++ tab in debug mode, it shows that it ignores the configuration in
c_cpp_properties.json
, as it shows it uses for example the default c++ standard, instead of the one defined in the configuration file. Then, when I look in cpp file, where the header file is used, it correctly shows the macro defined and uses thec_cpp_properties.json
.This all also depends in which CMakeLists.txt file the macro is defined. I have this CMake structure
Where the top level looks like this
This is because both of the subproject are independent from each other and can be compiled separately, with the top level CMake tying these two project together, so they can be compiled and run conveniently. The macro stored in
TARGET_CONFIG
is relevant for thedll
subproject and if I dont define it in the top level CMake, the IntelliSense wont work at all, even though everything compiles successfully.CMake Tools Diagnostics
Debug Log
Additional Information
As u can also see in the CMake Tools Diagnostic, even though the DEV2 is selected (which changes the name of the shared library), but it doesn't change the set define.