Interface project generated for Visual Studio uses default c++ standard version
CMake fails to set the C++ Standard used for interface (Utility) projects in Visual Studio. Meaning that code inside the project is treated by the IDE using the default C++14 language standard and therefore the syntax highlighting and auto-complete doesn't work as desired. I know this doesn't technically affect the build but it is very inconvenient to use the IDE and can sometimes result in incorrect code being inserted.
To reproduce have the following in a top level project CMakeLists.txt file:
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Then include the interface project using add_subdirectory
, and the utility project generated from the interface library will not have the "C++ Language Standard" set in Visual Studio.
I've attached a minimal solution which can demonstrate this behaviour. CMake_Projects_Bug.zip
When this is generated with the "Visual Studio 17 2022"
generator, you can open up the "General Properties" page see that the Main project has the correct C++20 language standard but the Util project has only the default C++14 set. The impact of this can be tested by #include <string_view>
then typing std::string_view
and hitting space or enter and letting it auto complete to some different type.
Hopefully this will be a quick and easy fix.