Unable to set C++ standard in a Visual Studio 2019 cmake "open folder" style project

I have tried every example I could find on the web for setting the C++ standard (to C++20, or at least C++17) in a cmake project in VS 2019  (v16.0.3), yet no matter what I try, Resharper C++ seems to consider the standard to remain at C++14. I know that for standard VS projects, setting the compiler option /std=c++latest would do the trick, but this is a cmake "open folder" scenario and not a VS "project".

My simple test is to code up a C++17 style nested namespace (i.e. namespace x::y ), resulting in Resharper highlighting the ::y part and stating that its a C++17 feature.

What I really want is to set the standard to C++20 (2a) so I can get access to the new resharper support for the forthcoming "Concepts TS (or working draft), however at the very least, C++17 is a must.

Is there a proper method for setting the C++ standard in cmake "open folder" scenarios such that Resharper accepts the features of that C++ standard?

 

1 comment
Comment actions Permalink

Hello!

The modern way to set the target language standard in CMake is to use target_compile_features (see e.g. https://cliutils.gitlab.io/modern-cmake/chapters/features/cpp11.html for more details):

cmake_minimum_required(VERSION 3.14)
project(MyApp)
add_executable(myExe main.cpp)
target_compile_features(myExe PUBLIC cxx_std_20)


If what you are saying is you have a CMake project that compiles but R++ shows red code inside it, please share the project with us and we'll investigate.

R++ 2019.1 does not support concepts yet, and neither does MSVC. Hopefully we'll add concepts support in 2019.2.

Thanks!

0

Please sign in to leave a comment.