In a CMakeLists.txt for a C# project, I can set the LangVersion for the project:
set( CMAKE_CSharp_FLAGS "-langversion:8" )
This ends up in the generated .csproj file:
<LangVersion>8</LangVersion>
I would like to also set Nullable:
set( CMAKE_CSharp_FLAGS "-langversion:8 -nullable" )
What I expected in the generated .csproj file:
<Nullable>enabled</Nullable>
What I observed in the generated .csproj file:
<AdditionalOptions>-nullable</AdditionalOptions>
(With subsequent CS9632 warnings about nullable annotations etc.)
CMake is version 3.30.5.
How to enable nullable references in CMakeLists.txt?
2
So far the only way I found to make this work was to set the VS_GLOBAL_Nullable
target property:
set_property( TARGET MyTarget PROPERTY VS_GLOBAL_Nullable "enable" )
It feels somewhat icky. It should be possible to set this globally, but set_property( GLOBAL PROPERTY VS_GLOBAL_Nullable "enable" )
didn’t work either.
2