Generate for VS2022 sets Character Set to "Use Multi-Byte Character Set"

Which I don’t want - I want it to be set to “Not Set” as I don’t want the _MBCS define to be generated by Visual Studio.

How can I stop this please?

The very first result from Google says to do so:

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # or just if(MSVC)
    target_compile_definitions(${PROJECT_NAME} # or your particular target name, if it's different
        PRIVATE
            "_UNICODE"
            "UNICODE"
    )
endif()

Have you tried that? Although if you want it to be set exactly to Not Set, that is probably not much better then.

No, I don’t want it set to a Unicode build.

PS What was your exact Google search please?

Thanks
David

I’ve been informed that:

CharacterSet is set as follows:

If the project adds a _UNICODE preprocessor definition, the CharacterSet is Unicode. If the project adds a _SBCS preprocessor definition, the CharacterSet is NotSet. Otherwise, the CharacterSet is MultiByte.

so

target_compile_definitions(example PRIVATE _SBCS)

should do the job.

D.

1 Like

What was your exact Google search please?

It was cmake "Use Multi-Byte Character Set", and that landed me here.

If the project adds a _SBCS preprocessor definition, the CharacterSet is NotSet

Thanks for coming back and posting it here, I’m sure that will be useful for others. I, for one, did not know about _SBCS definition.

You can probably even mark that comment as a solution for your topic.