AW: [CMake] "Treat wchar as built-in type" in Cmake ?

Gerhard Grimm ggrimm at
Mon Feb 11 03:32:38 EST 2008

Hi Stephen,

there are two ways to have this compiler flag added in a non-global fashion:

- You can add it to specific targets using

  set_target_properties(mytarget1 mytarget2 ...
                        PROPERTIES COMPILE_FLAGS "/Zc:wchar_t-")

- You can add it to specific source files using

  set_source_files_properties(mysource1 mysource2 ...
                              PROPERTIES COMPILE_FLAGS "/Zc:wchar_t-")

Usually you want to take the first approach - unless you are using the
"NMake Makefiles" generator and have a resource script (.rc file) among
your sources. In this case your custom compile flags will be passed to the
resource compiler as well, causing it to either error out or generate an
invalid .res file (happens with the /MT option BTW) that will crash the
linker. Go for the second approach then.

The "Visual Studio xxx" generators behave more useful here. They filter
out any target compile flags unsuitable for the resource compiler and only
pass /I or /D flags to it.

Best regards, Gerhard
-----Ursprüngliche Nachricht-----
Gesendet: Samstag, 9. Februar 2008 22:29
Cc: CMake at
Betreff: Re: [CMake] "Treat wchar as built-in type" in Cmake ?

Stefan Buschmann wrote:
> Just add the corresponding command line option for the compiler:
>      /Zc:wchar_t-                                # Treat wchar_t as
> built-in type
> )
> BTW: The command line switch for a specific option is usually mentioned
> in the comments for that option in Visual Studio.

Thanks. However, as far as I can see, ADD_DEFINITIONS adds the
option globally for all projects. I want to restrict it to
one only - is that possible ?



Steve Collyer
Netspinner Ltd
CMake mailing list
CMake at

More information about the CMake mailing list