In my CMakeLists.txt there is:
set(CMAKE_CXX_STANDARD 20)
# ...
add_library(mytarget)
# ...
target_compile_options(mytarget PRIVATE
/Zc:char8_t- # Disables C++20 conforming char8_t type support.
# https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1423r3.html
# https://stackoverflow.com/questions/59325910/whats-the-msvc-equivalent-for-fno-char8-t
)
It produces different command lines if I use Visual or Ninja generators. With Visual generator:
cl.exe [...] /std:c++20 [...] /Zc:char8_t-
With Ninja generator:
cl.exe [...] /Zc:char8_t- [...] -std:c++20
The order of compile flags matters here, because /std:c++20
reactivates /Zc:char8_t
(note the absence of "-" here). So the build fails using Ninja.
At the time of this writing, I am using CMake 3.25.1.
Is there a way to tell CMake to put /std:c++20
before any other compile flags?