0

I have a code that needs to run with MSVC as well as g++. Therefore I use Cmake. I want to use designated initializers which are part C++20. Since they exist since C99 they are already in g++ but in MSVC++ they are only available with the flag /std:latest.

What's the best way to enable this option for MSVC in a CMake file?

1
  • 1
    What have you tried so far? Please post a minimal example of your CMake file to demonstrate what you have tried so far, and any error messages or unexpected behavior you might be getting. Commented Sep 3, 2019 at 12:32

1 Answer 1

2

You can set the variables CMAKE_CXX_FLAGS_RELEASE (applies to release builds only), CMAKE_CXX_FLAGS_DEBUG (applies to debug builds only) and CMAKE_CXX_FLAGS (applies to both release and debug). In case you use also other compilers, you should only set the options for msvc:

if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:latest") endif() 
Sign up to request clarification or add additional context in comments.

1 Comment

that's what I needed. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.