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

一曲冷凌霜 提交于 2019-12-08 15:24:25

问题


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 ?


回答1:


I found a solution.

Thanks to Mike, I realized I was searching in the wrong direction. Since CMake does not give access to the meta-targets (and I can understand why), one must set up the Visual Studio environment to make MFC compile with MBCS.

This link explains why Microsoft did remove native MBCS support for MFC projects and this link provides a download for the MFC-MBCS package.

I'll remain careful with this because I still want my projects to use Unicode, and I'll use CMake flags accordingly. However, ZERO_PROJECT and ALL_BUILD now compile just fine.

It is Raman Sharma's post that made me finally see the light.

Thanks you guys, you made my day :D

Best regards !

RL




回答2:


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.




回答3:


ZERO_CHECK and ALL_BUILD are meta-targets. All your projects depend on ZERO_CHECK, all your projects are dependencies of ALL_BUILD, but those two projects themselves do not produce any libraries or executables, thus you need not to care about their build settings.

There could also be other such meta-targets, e.g. INSTALL if you used install() function.




回答4:


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.



来源:https://stackoverflow.com/questions/22011610/how-do-i-set-unicode-as-character-set-in-the-all-build-and-zero-check-visual-stu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!