Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set unicode as character set in the ALL_BUILD and ZERO_CHECK Visual Studio 2013 projects that are generated by Cmake?

I am currently using CMake to create a bunch of Visual Studio 2013 projects and it works. However, the automatically created ZERO_CHECK and ALL_BUILD projects are set to use MBCS by default although I want them to use the Unicode character set.

I did specify the use of the Unicode character set for my projects with the following :

ADD_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-D_UNICODE)

and it worked. I tried to set the c++ compiler flags with something like :

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /UMBCS /D_UNICODE /DUNICODE")

or even :

ADD_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-D_UNICODE)

before my project settings, but it did not affect ZERO_CHECK and ALL_BUILD at all. Any Ideas ?

like image 672
Rémi Loze Avatar asked Feb 25 '14 10:02

Rémi Loze


2 Answers

In my case in cmake file CMAKE_MFC_FLAG was set to non-zero value:

if(NOT WIN_HEAPINSPECTOR)
    #static link runtime lib
    set(CMAKE_MFC_FLAG 1) 
elseif()
    #dynamic link runtime lib
    set(CMAKE_MFC_FLAG 2) 
endif()

I changed it to 0 and then it compiled.

like image 170
Maxim Suslov Avatar answered Oct 25 '22 02:10

Maxim Suslov


You could use cmake --build . -- /p:CharacterSet=Unicode to build your project with Unicode set as characterset. In fact by this way you pass a parameter to do this to MSBuild itself, not CMake.

like image 27
E. Vakili Avatar answered Oct 25 '22 02:10

E. Vakili