MantisBT - CMake
View Issue Details
0014827CMakeDevelopmentpublic2014-03-24 07:132016-06-10 14:31
Vikas Pachisia 
Kitware Robot 
highmajoralways
closedmoved 
AMD64WindowsAny
CMake 2.8.12.2 
 
0014827: Preprocessor definitions for x64 projects are not correct on Windows Platform.
When trying to make a x64 windows project using CMake it always assigns the platform defines as WIN32 while it should be assigning the platform define as WIN64.
1. Try to make a simple basic x64 project that will create a visual studio solution file (.sln) file.
2. Open the solution file that contains the x64 project.
3. Check the Project Properties for C++ -> Preprocessor -> Preprocessor Definitions
4. You can see WIN32 as the preprocessor defines where as it should be WIN64.
The following change can fix this for most projects:

1. Open the CMake file:
    C:\Program Files (x86)\CMake 2.8\share\cmake-2.8\Modules\Platform\Windows-MSVC.cmake

2. Search for the code:
if(MSVC_C_ARCHITECTURE_ID MATCHES 64 OR MSVC_CXX_ARCHITECTURE_ID MATCHES 64)
  set(CMAKE_CL_64 1)
else()
  set(CMAKE_CL_64 0)
endif()
if(CMAKE_FORCE_WIN64 OR CMAKE_FORCE_IA64)
  set(CMAKE_CL_64 1)
endif()

3. Add the following new code after the end if mentioned above:
if(CMAKE_CL_64)
    set(WIN64 1)
else()
    set(WIN32 1)
endif()

4. Search for 'set(_PLATFORM_DEFINES "/DWIN32")'
5. Replace the above line with the following code:
        if(CMAKE_CL_64)
        set(_PLATFORM_DEFINES "/DWIN64")
    else()
        set(_PLATFORM_DEFINES "/DWIN32")
    endif()
No tags attached.
? Windows-MSVC.cmake (10,672) 2014-03-24 07:13
https://public.kitware.com/Bug/file/5102/Windows-MSVC.cmake
Issue History
2014-03-24 07:13Vikas PachisiaNew Issue
2014-03-24 07:13Vikas PachisiaFile Added: Windows-MSVC.cmake
2014-03-24 08:34Brad KingNote Added: 0035479
2014-03-28 09:13Vikas PachisiaNote Added: 0035553
2014-03-31 09:20Brad KingNote Added: 0035569
2016-06-10 14:29Kitware RobotNote Added: 0042514
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0035479)
Brad King   
2014-03-24 08:34   
The proper preprocessor symbols to test in your C and C++ code are "_WIN32" and "_WIN64" as defined by the compiler:

 http://msdn.microsoft.com/en-us/library/b0084kay.aspx [^]

CMake adds /DWIN32 on Windows for historical reasons.

In CMake code "WIN32" is CMake's way of spelling "Windows" (again, for historical reasons). One could also check for "Windows" in CMAKE_SYSTEM_NAME.
(0035553)
Vikas Pachisia   
2014-03-28 09:13   
I understand "_WIN32" and "_WIN64" are the preprocessors to be checked but they are internal preprocessors defined by the compiler. Where as /DWIN32 was user defined preprocessor for use in users code and I guess more than users Microsoft SDKs have utilized /DWIN32 and to be compatible with the SDKs it would be preferrable to define /DWIN32 and /DWIN64 (again for historical reasons such as to signal Microsoft SDKs to act accordingly based on these user defined macros).
(0035569)
Brad King   
2014-03-31 09:20   
Re 0014827:0035553: Can you provide a link to MS documentation that says one must define /DWIN64 to use the SDK correctly?

AFAIK the correct macros for all code to use are _WIN32 and _WIN64. The only reason CMake defines WIN32 is because the project for which it grew up 14 years ago wanted that defined.
(0042514)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.