c++visual-studiocmakeintellisense

CMake / Intellisense - False Errors breaking intellisense


I'm seeing the below errors thrown up by Visual Studios intellisense:

command-line error: invalid number: --wchar_t_keyword

command-line error: invalid number: --use_pch full code error

I understand that these usually appear when you're using incorrect compile commands for your compiler e.g. -Wall instead of /W4 when using MSVC.

However, I am using MSVC defined commands, so I do not know why it is transforming them.

target_precompile_headers(project1 PRIVATE src/stdafx.h)
target_compile_options(project1 PRIVATE /permissive)
# struct alignment 1 byte
target_compile_options(project1 PRIVATE /Zp)
# treat wchar_t as built in type
target_compile_options(project1 PRIVATE /Zc:wchar_t)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
# C/C++ -> Optimization -> String Pooling
target_compile_options(project1 PRIVATE /GF)
# C/C++ -> Optimization -> Omite Frame Pointers
target_compile_options(project1 PRIVATE /Oy)
# Only explicit inline function expansion
target_compile_options(project1 PRIVATE /Ob1) 
endif()

Additionally, there aren't any issues with building the project. It's just Visual Studio's intellisense calling out these errors (and as a result not having nice colour formatting throughout the source files).

Any suggestions would be appreciated. I've tried putting the commands behind an if (MSVC) wrap to no avail.

The code in the attached repo can replicate the issue for me: https://github.com/fo000xx/cmake-intellisense-test

I have tried to wrap the arguments in an if (MSVC) statement, as well as changing to things like add_compile_options instead of target_compile_options.

I have cleared the .vs intellisense cache (as well as created a brand new directory to test and replicate)


Solution

  • The issue was target_compile_options(project1 PRIVATE /Zp).

    I assume intellisense was expecting the next item to be passed to be the argument. As /Zp is the same as /Zp1 I had left it empty. Adding the argument of 1 has made the intellisense errors dissappear.