19

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 ?

Cem Kalyoncu
  • 14,120
  • 4
  • 40
  • 62
Rémi Loze
  • 241
  • 1
  • 2
  • 8
  • Any reason why you'd want to change the ALL_BUILD and ZERO_CHECK projects in the first place? They are meta-projects only and the settings there should not have any effect on the code being generated. – ComicSansMS Feb 25 '14 at 14:20
  • @ComicSansMS Well I am using the Windows MFC and since the ZERO_PROJECT is being compiled before the others, I get this error message : Building an MFC project for a non-Unicode character set is deprecated. You must change the project property to Unicode or download an additional library. See http://go.microsoft.com/fwlink/p/?LinkId=286820 for more information. Using CMake very often, I have to set the character to Unicode manually each time. It is, from my point of view, really annoying. – Rémi Loze Feb 26 '14 at 07:11

4 Answers4

5

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

Community
  • 1
  • 1
Rémi Loze
  • 241
  • 1
  • 2
  • 8
4

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.

E. Vakili
  • 1,036
  • 1
  • 10
  • 25
1

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.

Maxim Suslov
  • 4,335
  • 1
  • 35
  • 29
  • So, what is the resulting CMake code that works? I cant vote for an answer that says what not to do. – Sandburg Jun 07 '21 at 08:58
0

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.

mike.dld
  • 2,929
  • 20
  • 21
  • Does that mean that with CMake I have no control at all over those meta-targets ? Is there a way to automatically put Unicode as default character set for any Visual 2013 project? Or will I have to set that parameter by hand each time I regenerate my solution using CMake ? Anyway, thanks :) – Rémi Loze Feb 28 '14 at 07:55
  • Yes, you don't have control over those targets. As for adding flags to all targets at once, all you need to do is call `add_definitions()` once in your top-level CMakeLists.txt. All the projects added later via `add_subdirectory()` would inherit those defines. – mike.dld Feb 28 '14 at 10:23