Issue
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?
Solution
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()
Answered By - flba