VS: CXX Standard Not Set for Interface Targets
Visual Studio 2022 and 2019 (maybe earlier, only have 2022 and 2019 available) let you set the C++ language standard on header-only targets. Without this, the headers are incorrectly treated as the default (c++14) standard by IntelliSense. I tried target_compile_features(name INTERFACE cxx_std_20)
, set_target_properties(taos2 PROPERTIES CXX_STANDARD 20)
, and a global set(CMAKE_CXX_STANDARD 20)
. Visual Studio itself adds a <ClCompile><<LanguageStandard>...
to <ItemDefinitionGroup ...>
in .vcxproj when you set the language standard regardless of if the target is actually building any sources. CMake generated vcxproj has:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
which VS changes to:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
</ItemDefinitionGroup>
(repeat Release) when the language standard is set on a header-only target. It would be very helpful if CMake set this correctly on interface targets (especially since .vcxproj seems to be wiped out every time CMake is re-run).