How do I set unicode as character set in the ALL_BUILD and ZERO_CHECK Visual Studio 2013 projects that are generated by Cmake?
-
21-12-2019 - |
Question
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 ?
Solution
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
OTHER TIPS
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.
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.
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.