MantisBT - CMake
View Issue Details
0014552CMakeCMakepublic2013-11-08 06:572015-07-08 08:57
vzvezda 
Brad King 
normalmajoralways
closedfixed 
x86Windows8.1
CMake 2.8.12 
CMake 3.3CMake 3.3 
0014552: testCCompiler for WinCE ARMV4I and NMake generator fails with linker error
The "NMake Makefiles" generation fails when building for Windows CE with ARMV4I as system processor. The error is like the conflict in linker options and selected libraries:

  coredll.lib(COREDLL.dll) : fatal error LNK1112: module machine type 'THUMB'
  conflicts with target machine type 'ARM'

There is no such problem when building for CE x86.
1. Create a simple project
2. Start generation as described in:
http://www.cmake.org/Wiki/CMake_Cross_Compiling#Cross_compilation_for_Windows_CE [^]

=========== Steps
h:\temp\HelloWorld>set path=D:\sdk\cmake-2.8.12-win32-x86\bin;%path%
h:\temp\HelloWorld>"%VS80COMNTOOLS%vsvars32.bat"
Setting environment for using Microsoft Visual Studio 2005 x86 tools.
h:\temp\HelloWorld>cmake -E env_vs8_wince "STANDARDSDK_500 (ARMV4I)" >env.bat
h:\temp\HelloWorld>env.bat
Environment Selection: STANDARDSDK_500 (ARMV4I)
h:\temp\HelloWorld>cmake -G "NMake Makefiles" -DCMAKE_SYSTEM_NAME=WindowsCE -DCM
AKE_SYSTEM_PROCESSOR=ARMV4I .

============ The output

-- The C compiler identification is MSVC 14.0.60131
-- The CXX compiler identification is MSVC 14.0.60131
-- Check for working C compiler: D:/sdk/vc8/ce/bin/x86_arm/cl.exe
-- Check for working C compiler: D:/sdk/vc8/ce/bin/x86_arm/cl.exe -- broken
CMake Error at D:/sdk/cmake-2.8.12-win32-x86/share/cmake-2.8/Modules/CMakeTestCC
ompiler.cmake:61 (message):
  The C compiler "D:/sdk/vc8/ce/bin/x86_arm/cl.exe" is not able to compile a
  simple test program.

  It fails with the following output:

   Change Dir: H:/temp/HelloWorld/CMakeFiles/CMakeTmp



  Run Build Command:nmake /NOLOGO "cmTryCompileExec873074925\fast"

        D:\sdk\vc8\bin\nmake.exe -f
  CMakeFiles\cmTryCompileExec873074925.dir\build.make /nologo -L
  CMakeFiles\cmTryCompileExec873074925.dir\build

        D:\sdk\cmake-2.8.12-win32-x86\bin\cmake.exe -E cmake_progress_report
  H:\temp\HelloWorld\CMakeFiles\CMakeTmp\CMakeFiles 1

  Building C object
  CMakeFiles/cmTryCompileExec873074925.dir/testCCompiler.c.obj

        D:\sdk\vc8\ce\bin\x86_arm\cl.exe /D_WIN32_WCE=0x500 /DUNDER_CE /DARM
  /D_ARM_ /D_WINDOWS /W3 /D_DEBUG /MDd /Zi /Ob0 /Od
  /FoCMakeFiles\cmTryCompileExec873074925.dir\testCCompiler.c.obj
  /FdCMakeFiles\cmTryCompileExec873074925.dir/ -c
  H:\temp\HelloWorld\CMakeFiles\CMakeTmp\testCCompiler.c

  Microsoft (R) C/C++ Optimizing Compiler Version 14.00.60131 for ARM

  Copyright (C) Microsoft Corporation. All rights reserved.



  testCCompiler.c

  Linking C executable cmTryCompileExec873074925.exe

        D:\sdk\cmake-2.8.12-win32-x86\bin\cmake.exe -E vs_link_exe
  D:\sdk\vc8\ce\bin\x86_arm\link.exe
  @CMakeFiles\cmTryCompileExec873074925.dir\objects1.rsp
  /out:cmTryCompileExec873074925.exe /implib:cmTryCompileExec873074925.lib
  /pdb:H:\temp\HelloWorld\CMakeFiles\CMakeTmp\cmTryCompileExec873074925.pdb
  /version:0.0 /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib /machine:ARM
  /debug /INCREMENTAL:YES /subsystem:windowsce /entry:mainACRTStartup
  coredll.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib corelibc.lib

  Microsoft (R) Incremental Linker Version 8.00.50727.762

  Copyright (C) Microsoft Corporation. All rights reserved.



  CMakeFiles/cmTryCompileExec873074925.dir/testCCompiler.c.obj

  coredll.lib(COREDLL.dll) : fatal error LNK1112: module machine type 'THUMB'
  conflicts with target machine type 'ARM'

  LINK Pass 1 failed. with 1112

  NMAKE : fatal error U1077: 'D:\sdk\cmake-2.8.12-win32-x86\bin\cmake.exe' :
  return code '0xffffffff'

  Stop.

  NMAKE : fatal error U1077: 'D:\sdk\vc8\bin\nmake.exe' : return code '0x2'
No tags attached.
related to 0015404closed Brad King cmake dos not set CMAKE_RC_FLAGS to include the platform defines like WIN32_WCE UNDER_CE etc. 
zip HelloWorldAndOutput.zip (12,112) 2013-11-08 06:57
https://public.kitware.com/Bug/file/4942/HelloWorldAndOutput.zip
patch v1-0001-MSVC-Define-DWINCE-when-building-for-WinCE-platfo.patch (1,125) 2015-02-13 10:39
https://public.kitware.com/Bug/file/5381/v1-0001-MSVC-Define-DWINCE-when-building-for-WinCE-platfo.patch
patch v1-0002-MSVC-Distinguish-among-ARM-architectures-more-pre.patch (4,964) 2015-02-13 10:39
https://public.kitware.com/Bug/file/5382/v1-0002-MSVC-Distinguish-among-ARM-architectures-more-pre.patch
patch v1-0003-MSVC-Compile-with-arch-specific-flags-on-ARM-plat.patch (1,747) 2015-02-13 10:39
https://public.kitware.com/Bug/file/5383/v1-0003-MSVC-Compile-with-arch-specific-flags-on-ARM-plat.patch
Issue History
2013-11-08 06:57vzvezdaNew Issue
2013-11-08 06:57vzvezdaFile Added: HelloWorldAndOutput.zip
2013-11-08 10:38Brad KingAssigned To => Patrick R. Gansterer
2013-11-08 10:38Brad KingStatusnew => assigned
2014-07-10 11:57Gunnar RothNote Added: 0036342
2014-07-14 10:50Brad KingNote Added: 0036368
2014-07-15 04:12Gunnar RothNote Added: 0036386
2014-07-15 04:12Gunnar RothNote Added: 0036387
2014-07-15 09:20Brad KingNote Added: 0036396
2014-07-22 05:40Gunnar RothNote Added: 0036425
2014-07-22 10:50Brad KingNote Added: 0036426
2014-07-23 04:44Gunnar RothNote Added: 0036434
2014-07-23 10:15Brad KingNote Added: 0036438
2015-02-13 03:19Gunnar RothNote Added: 0037965
2015-02-13 09:47Brad KingRelationship addedrelated to 0015404
2015-02-13 10:39Brad KingFile Added: v1-0001-MSVC-Define-DWINCE-when-building-for-WinCE-platfo.patch
2015-02-13 10:39Brad KingFile Added: v1-0002-MSVC-Distinguish-among-ARM-architectures-more-pre.patch
2015-02-13 10:39Brad KingFile Added: v1-0003-MSVC-Compile-with-arch-specific-flags-on-ARM-plat.patch
2015-02-13 10:41Brad KingNote Added: 0037968
2015-02-13 11:16Gunnar RothNote Added: 0037969
2015-02-13 11:22Brad KingNote Added: 0037970
2015-02-23 08:58Gunnar RothNote Added: 0038019
2015-02-23 10:32Brad KingNote Added: 0038024
2015-02-23 10:32Brad KingAssigned ToPatrick R. Gansterer => Brad King
2015-02-23 10:32Brad KingStatusassigned => resolved
2015-02-23 10:32Brad KingResolutionopen => fixed
2015-02-23 10:32Brad KingFixed in Version => CMake 3.3
2015-02-23 10:32Brad KingTarget Version => CMake 3.3
2015-02-24 03:41Gunnar RothNote Added: 0038044
2015-02-24 09:34Brad KingNote Added: 0038050
2015-02-24 10:23Gunnar RothNote Added: 0038054
2015-07-08 08:57Robert MaynardNote Added: 0039063
2015-07-08 08:57Robert MaynardStatusresolved => closed

Notes
(0036342)
Gunnar Roth   
2014-07-10 11:57   
This ia a serious issue for us. Sadly nobody cares for a fix.
As a workaorund i use the follwing patch, which as a CMAKE_OVERRIDE_MACHINE variable you have to set to THUMB in the call to cmake . like cmake -G"xxx" -DCMAKE_OVERRIDE_MACHINE=THUMB


--- a\share\cmake-3.0\Modules/Platform/Windows-MSVC.cmake
+++ b\share\cmake-3.0\Modules/Platform/Windows-MSVC.cmake
@@ -182,11 +183,13 @@
 set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")
 
 # executable linker flags
 set (CMAKE_LINK_DEF_FILE_FLAG "/DEF:")
 # set the machine type
-if(MSVC_C_ARCHITECTURE_ID)
+if(CMAKE_OVERRIDE_MACHINE)
+ set(_MACHINE_ARCH_FLAG "/machine:${CMAKE_OVERRIDE_MACHINE}")
+elseif(MSVC_C_ARCHITECTURE_ID)
   set(_MACHINE_ARCH_FLAG "/machine:${MSVC_C_ARCHITECTURE_ID}")
 elseif(MSVC_CXX_ARCHITECTURE_ID)
   set(_MACHINE_ARCH_FLAG "/machine:${MSVC_CXX_ARCHITECTURE_ID}")
 elseif(MSVC_Fortran_ARCHITECTURE_ID)
   set(_MACHINE_ARCH_FLAG "/machine:${MSVC_Fortran_ARCHITECTURE_ID}")
(0036368)
Brad King   
2014-07-14 10:50   
I'm not very familiar with WinCE or ARMV4I, but perhaps a "peheader" case needs to be added here?

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/CMakeDetermineCompilerId.cmake;hb=v3.0.0#l392 [^]
(0036386)
Gunnar Roth   
2014-07-15 04:12   
yes that need some extra code. I looked into my builds i have done for several platforms and got this result:
 50450000c401 armv7 ce 8 (arm thumb2)
 50450000c201 armv4i ce 6 (thumb)
 504500004c01 x86 ce 6, ce 8, win32
 504500006486 win32 x86 64 bit

wth of google , i found: https://gcc.gnu.org/ml/gcc-help/2013-03/msg00190.html [^]

it tells me this:
#define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian
#define IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM Thumb/Thumb-2 Little-Endian
#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2

so on wec2013 armnt is used ( which is the same as in arm winrt and wec2013 is indeed using thumb-2 code)

so for 0x01c2 we need machine thumb and for the other machine ARM, i think what machine type arm is in the end 1c2 or 1c4 depends on the compiler.

but in win32-msvc.cmake there is that code:
if(WINCE)
  foreach(lang C CXX)
    set(_MSVC_${lang}_ARCHITECTURE_FAMILY "${MSVC_${lang}_ARCHITECTURE_ID}")
    if(_MSVC_${lang}_ARCHITECTURE_FAMILY STREQUAL "THUMB")
      set(_MSVC_${lang}_ARCHITECTURE_FAMILY "ARM")

that is actually making wec2013 work (as it sets arm as machine ,but getting me in the way with armv4i on ce 6.
(0036387)
Gunnar Roth   
2014-07-15 04:12   
btw wec2013 == ce 8
(0036396)
Brad King   
2014-07-15 09:20   
Re 0014552:0036386: Thanks. Can you please translate all that information into a patch? The code in question was contributed and I'm not familiar with all the WinCE and ARM terminology.
(0036425)
Gunnar Roth   
2014-07-22 05:40   
Hi Bard, actually that issue is more complicated and i think it cannot be solved without a parameter CMAKE_WINCE_CPU.
Ok here comes what i found.

1. i have no clue what the code in CMakeDetermineCompilerId.cmake is good for windows ce. i changed it like:
diff -r -U 5 -N -x '*.orig' -x '*.rej' -x '*.bak' -x Patches -x bin a\share\cmake-3.0\Modules/CMakeDetermineCompilerId.cmake b\share\cmake-3.0\Modules/CMakeDetermineCompilerId.cmake
--- a\share\cmake-3.0\Modules/CMakeDetermineCompilerId.cmake 2014-06-09 17:52:01.000000000 +0200
+++ b\share\cmake-3.0\Modules/CMakeDetermineCompilerId.cmake 2014-07-21 12:55:19.496628300 +0200
@@ -413,10 +413,15 @@
         set(ARCHITECTURE_ID "SH4")
       elseif(peheader STREQUAL "50450000a801")
         set(ARCHITECTURE_ID "SH5")
       elseif(peheader STREQUAL "50450000c201")
         set(ARCHITECTURE_ID "THUMB")
+ elseif(peheader STREQUAL "50450000c401")
+ set(ARCHITECTURE_ID "ARM")
+ elseif(peheader STREQUAL "50450000c001")
+ set(ARCHITECTURE_ID "ARM")
+
       endif()
     endif()

but that helped nothing. I cannot figure how it should as it would just look into a compiled binary which is already compiled and linked with the wrong options (hen and egg problem).

then i found /CMakePlatformId.h.in and the code:
elif defined(_M_ARM)
 define ARCHITECTURE_ID "ARM"

so that is the actual reason why machine type is arm always.
But _M_ARM has a value predefined from the compiler which is the number of the arm instrcution set, so 4 for arm4 and 7 for armv7 for example. The problem here is that there is ARMV4I (I for interwork thumb and arm) which is THUMB and ARMV4 which is ARM, but both have the value 4, so you cannot decide machine type on this information. as we have only used ar4vi for all our devices inn the last ten years , i made this patch.
--- a\share\cmake-3.0\Modules/CMakePlatformId.h.in 2014-06-09 17:52:01.000000000 +0200
+++ b\share\cmake-3.0\Modules/CMakePlatformId.h.in 2014-07-21 13:08:22.403628300 +0200
@@ -92,11 +92,14 @@
 # define ARCHITECTURE_ID "x64"
 
 # elif defined(_M_IX86)
 # define ARCHITECTURE_ID "X86"
 
-# elif defined(_M_ARM)
+# elif defined(_M_ARM) && (_M_ARM < 6)
+# define ARCHITECTURE_ID "THUMB"
+
+# elif defined(_M_ARM)
 # define ARCHITECTURE_ID "ARM"

this now worked albeit one minor glitch, now _DTHUMB and -D_THUMB_ is set by cmake, but code exspects also -DARM and -D_ARM. so i did another patch.

--- a\share\cmake-3.0\Modules/Platform/Windows-MSVC.cmake 2014-06-09 17:52:02.000000000 +0200
+++ b\share\cmake-3.0\Modules/Platform/Windows-MSVC.cmake 2014-07-22 10:03:03.151957000 +0200
@@ -130,13 +132,11 @@
 set(CMAKE_BUILD_TYPE_INIT Debug)
 
 if(WINCE)
   foreach(lang C CXX)
     set(_MSVC_${lang}_ARCHITECTURE_FAMILY "${MSVC_${lang}_ARCHITECTURE_ID}")
- if(_MSVC_${lang}_ARCHITECTURE_FAMILY STREQUAL "THUMB")
- set(_MSVC_${lang}_ARCHITECTURE_FAMILY "ARM")
- elseif(_MSVC_${lang}_ARCHITECTURE_FAMILY MATCHES "^SH")
+ if(_MSVC_${lang}_ARCHITECTURE_FAMILY MATCHES "^SH")
       set(_MSVC_${lang}_ARCHITECTURE_FAMILY "SHx")
     endif()
     string(TOUPPER "${_MSVC_${lang}_ARCHITECTURE_FAMILY}" _MSVC_${lang}_ARCHITECTURE_FAMILY_UPPER)
   endforeach()
 
@@ -149,11 +149,14 @@
   endif()
 
   set(_PLATFORM_DEFINES "/D_WIN32_WCE=0x${_CE_VERSION} /DUNDER_CE")
   set(_PLATFORM_DEFINES_C " /D${_MSVC_C_ARCHITECTURE_FAMILY} /D_${_MSVC_C_ARCHITECTURE_FAMILY_UPPER}_")
   set(_PLATFORM_DEFINES_CXX " /D${_MSVC_CXX_ARCHITECTURE_FAMILY} /D_${_MSVC_CXX_ARCHITECTURE_FAMILY_UPPER}_")
-
+ if(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "THUMB")
+ set(_PLATFORM_DEFINES_C ${_PLATFORM_DEFINES_C} " /DARM /D_ARM_")
+ set(_PLATFORM_DEFINES_CXX ${_PLATFORM_DEFINES_CXX} " /DARM /D_ARM_")
+ endif()
   set(_RTC1 "")
   set(_FLAGS_CXX " /GR /EHsc")
   set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib")
   set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib")
 

but as i said this not a 100% solution, as an armv4 based sdk would not get the right machine type ( arm) set with this changes. the only solution for me would be a CMAKE_WINCE_CPU_TYPE parameter where you can give ARMV4 if you want to override the automatic detection.
(0036426)
Brad King   
2014-07-22 10:50   
Re 0014552:0036425: Thanks for the detailed investigation and report.

Do projects expect -DTHUMB -D_THUMB_ in addition to -DARM -D_ARM_, such that your latter patch would be needed regardless of the rest of this issue?

Do ARMV4 and ARMV4I use separate toolchains? Is there any way to tell them apart, perhaps with another preprocessor macro besides _M_ARM?

Otherwise I agree we'll need an explicit override option for this.
(0036434)
Gunnar Roth   
2014-07-23 04:44   
Ok now i dug a lot more deeper into this issue. one thing is that i remembered that we always give the additional options /QRarch4T and /QRinterwork-return for out armv4i builds. i now found this in msdn:
"The I in the ARMV4I name means Interworking. For Windows CE 5.0 and later, ARMV4 is deprecated and all supported ARM processors are ARMV4I by default. /QRarch4T and /QRarch5T switches now enable /QRinterwork-return, to avoid generating code that might not run correctly if the user forgot to add /QRinterwork-return." from
http://msdn.microsoft.com/en-us/library/ms254245.aspx [^]

so /QRinterwork-return is not needed i you give /QRarch4T since ce 5.0, also we learn armv4 is deprectated. but if you do not give /QRarch4T you do not get it.
i checked the compiler defined flags and if i give the /QRarch4T option to cl i get: -D_M_ARM=4 -D_M_ARMT=_M_ARM so new define _M_ARMT appears.

if you create a wizard project fdor ce 5 or 6, the wizard add this defines $(ARCHFAM) $(_ARCHFAM_) $(PLATFORMDEFINES) $(INSTRUCTIONSET) _WIN32_WCE=$(CEVER) UNDER_CE WINCE the $() are read from the sdk information which is stored in
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcpackages\WCE.VCPlatform.config
and looks like
                <Macro Name="PLATFORMDEFINES" Value="WIN32_PLATFORM_WFSP"/>
                <Macro Name="CEVER" Value="0x420"/>
                <Macro Name="ARCHFAM" Value="ARM"/>
                <Macro Name="_ARCHFAM_" Value="_ARM_"/>
                <Macro Name="INSTRUCTIONSET" Value="ARMV4"/>

so to answer your question doing -DTHUMB -D_THUMB_ is wrong, this would only be write if you really compile thumb code for which you need to give /QRthumb.
you get these defines then predefined -D_M_ARM=4 -D_M_ARMT=_M_ARM
-D_M_THUMB=_M_ARM -iw16

btw. this is how i get the compiler setting when i give some option to cl.exe:

compile the follwing code as dispvcdefs.c
/************
************************************/

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    char *p;

    if ((p = getenv("MSC_CMD_FLAGS")) != NULL)
        printf("MSC_CMD_FLAGS:\n%s\n", p);

    if ((p = getenv("MSC_IDE_FLAGS")) != NULL)
        printf("MSC_IDE_FLAGS:\n%s\n", p);

    return EXIT_FAILURE;
}

then call it like this :
cl <options> /Bxdispvcdefs.exe c.cpp
for cpp

cl <options> /Bdispvcdefs.exe c.c
for c

so i think we definitely need to give the instruction set as a parameter ( if generating for vcproj we can read it from sdk name . there are yet some defines and compiler options missing like /QRarch4T if instruction set is armv4i)

i suggest using _M_ARM to get the pure arm version in CMakePlatformId.h.in and defaulting to new ARCHITECTURE_ID ARMV4I if it is 4, if it is 7 then we can simply use id ARMV7 ( luckily in arm 6 and 7 there is always interworking active, no other mode exists) and set the /machine ARCHFAM _ARCHFAM_ and INSTRUCTIONSET defines accordingly.
(0036438)
Brad King   
2014-07-23 10:15   
Re 0014552:0036434: Thanks. If you teach CMakeDetermineCompilerId.cmake to add the proper content to the test .vcproj file for the WinCE variants of the VS generators then the compiler-id binary can be built with the proper flags so that the right information is detected.
(0037965)
Gunnar Roth   
2015-02-13 03:19   
Hi, it has been a long time , but today i decided to finally gave my changes to the public. This only supports wince 5.0 and up ( so only ARMv4I )
and it works like a charm for our ce 6 and ce 8 (wec2013) devices.

--- a\share\cmake-3.1\Modules/CMakeDetermineCompilerId.cmake 2015-01-14 10:35:07.855173400 +0100
+++ b\share\cmake-3.1\Modules/CMakeDetermineCompilerId.cmake 2015-01-14 15:18:12.099153000 +0100
@@ -472,12 +472,10 @@
         set(ARCHITECTURE_ID "SH3DSP")
       elseif(peheader STREQUAL "50450000a601")
         set(ARCHITECTURE_ID "SH4")
       elseif(peheader STREQUAL "50450000a801")
         set(ARCHITECTURE_ID "SH5")
- elseif(peheader STREQUAL "50450000c201")
- set(ARCHITECTURE_ID "THUMB")
       endif()
     endif()
 
     # Check if a valid compiler and platform were found.
     if(COMPILER_ID AND NOT COMPILER_ID_TWICE)


this will be always thumb as the compiler is default to this, and we do not use architecture thumb, we have armv4i archictecture then machine type is thumb or archictecture armv7 then machine type is ARM, albeit the code actually is thumb-2. Confusing , i know.

--- a\share\cmake-3.1\Modules/CMakePlatformId.h.in 2015-01-14 10:35:08.175173400 +0100
+++ b\share\cmake-3.1\Modules/CMakePlatformId.h.in 2015-02-03 10:34:39.893457400 +0100
@@ -94,10 +94,12 @@
 #else /* unknown platform */
 # define PLATFORM_ID ""
 
 #endif
 
+#define STR_HLP(x) #x
+#define STRINGIZE(x) STR_HLP(x)
 /* For windows compilers MSVC and Intel we can determine
    the architecture of the compiler being used. This is because
    the compilers do not have flags that can change the architecture,
    but rather depend on which compiler is being used
 */
@@ -109,13 +111,16 @@
 # define ARCHITECTURE_ID "x64"
 
 # elif defined(_M_IX86)
 # define ARCHITECTURE_ID "X86"
 
+# elif defined(_M_ARM) && (_M_ARM == 4)
+# define ARCHITECTURE_ID "ARMV4I"
+# elif defined(_M_ARM) && (_M_ARM == 5)
+# define ARCHITECTURE_ID "ARMV5I"
 # elif defined(_M_ARM)
-# define ARCHITECTURE_ID "ARM"
-
+# define ARCHITECTURE_ID "ARMV" STRINGIZE(_M_ARM)
 # elif defined(_M_MIPS)
 # define ARCHITECTURE_ID "MIPS"
 
 # elif defined(_M_SH)
 # define ARCHITECTURE_ID "SHx"


this will set ARMV4I or ARMV5I as architecture and anything higher will be set by stringizing value of _M_ARM

--- a\share\cmake-3.1\Modules/Platform/Windows-MSVC.cmake 2015-01-14 10:35:12.204173400 +0100
+++ b\share\cmake-3.1\Modules/Platform/Windows-MSVC.cmake 2015-02-04 16:19:22.810338400 +0100
@@ -132,13 +132,11 @@
 set(CMAKE_BUILD_TYPE_INIT Debug)
 
 if(WINCE)
   foreach(lang C CXX)
     set(_MSVC_${lang}_ARCHITECTURE_FAMILY "${MSVC_${lang}_ARCHITECTURE_ID}")
- if(_MSVC_${lang}_ARCHITECTURE_FAMILY STREQUAL "THUMB")
- set(_MSVC_${lang}_ARCHITECTURE_FAMILY "ARM")
- elseif(_MSVC_${lang}_ARCHITECTURE_FAMILY MATCHES "^SH")
+ if(_MSVC_${lang}_ARCHITECTURE_FAMILY MATCHES "^SH")
       set(_MSVC_${lang}_ARCHITECTURE_FAMILY "SHx")
     endif()
     string(TOUPPER "${_MSVC_${lang}_ARCHITECTURE_FAMILY}" _MSVC_${lang}_ARCHITECTURE_FAMILY_UPPER)
   endforeach()
 
@@ -148,19 +146,30 @@
     set(_CE_VERSION "500")
   else()
     message(FATAL_ERROR "Invalid Windows CE version: ${CMAKE_SYSTEM_VERSION}")
   endif()
 
- set(_PLATFORM_DEFINES "/D_WIN32_WCE=0x${_CE_VERSION} /DUNDER_CE")
- set(_PLATFORM_DEFINES_C " /D${_MSVC_C_ARCHITECTURE_FAMILY} /D_${_MSVC_C_ARCHITECTURE_FAMILY_UPPER}_")
- set(_PLATFORM_DEFINES_CXX " /D${_MSVC_CXX_ARCHITECTURE_FAMILY} /D_${_MSVC_CXX_ARCHITECTURE_FAMILY_UPPER}_")
+ set(_PLATFORM_DEFINES "/D_WIN32_WCE=0x${_CE_VERSION} /DUNDER_CE /DWINCE /D${_MSVC_C_ARCHITECTURE_FAMILY}")
+ if(_MSVC_C_ARCHITECTURE_FAMILY MATCHES "^ARMV")
+ set(_PLATFORM_DEFINES_C ${_PLATFORM_DEFINES_C} " /DARM /D_ARM_")
+ set(_PLATFORM_DEFINES_CXX ${_PLATFORM_DEFINES_CXX} " /DARM /D_ARM_")
+ else()
+ set(_PLATFORM_DEFINES_C " /D${_MSVC_C_ARCHITECTURE_FAMILY} /D_${_MSVC_C_ARCHITECTURE_FAMILY_UPPER}_")
+ set(_PLATFORM_DEFINES_CXX " /D${_MSVC_CXX_ARCHITECTURE_FAMILY} /D_${_MSVC_CXX_ARCHITECTURE_FAMILY_UPPER}_")
+ endif()
 
+ if(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARMV4I")
+ set(_PLATFORM_COMPILE_FLAGS " /QRarch4T")
+ elseif(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARMV5I")
+ set(_PLATFORM_COMPILE_FLAGS " /QRarch5T")
+ endif()
   set(_RTC1 "")
   set(_FLAGS_CXX " /GR /EHsc")
   set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib")
   set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib")
-
+ set(CMAKE_RC_FLAGS "${_PLATFORM_DEFINES} ${_PLATFORM_DEFINES_C}")
+
   if (MSVC_VERSION LESS 1600)
     set(CMAKE_C_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT} corelibc.lib")
   endif ()
 elseif(WINDOWS_PHONE OR WINDOWS_STORE)
   set(_PLATFORM_DEFINES "/DWIN32")
@@ -198,13 +207,25 @@
 # executable linker flags
 set (CMAKE_LINK_DEF_FILE_FLAG "/DEF:")
 # set the machine type
 if(MSVC_C_ARCHITECTURE_ID)
- set(_MACHINE_ARCH_FLAG "/machine:${MSVC_C_ARCHITECTURE_ID}")
+ if(_MSVC_C_ARCHITECTURE_FAMILY MATCHES "^ARMV.I")
+ set(_MACHINE_ARCH_FLAG "/machine:THUMB")
+ elseif(_MSVC_C_ARCHITECTURE_FAMILY MATCHES "^ARM")
+ set(_MACHINE_ARCH_FLAG "/machine:ARM")
+ else()
+ set(_MACHINE_ARCH_FLAG "/machine:${MSVC_C_ARCHITECTURE_ID}")
+ endif()
 elseif(MSVC_CXX_ARCHITECTURE_ID)
- set(_MACHINE_ARCH_FLAG "/machine:${MSVC_CXX_ARCHITECTURE_ID}")
+ if(_MSVC_CXX_ARCHITECTURE_FAMILY MATCHES "^ARMV.I")
+ set(_MACHINE_ARCH_FLAG "/machine:THUMB")
+ elseif(_MSVC_CXX_ARCHITECTURE_FAMILY MATCHES "^ARM")
+ set(_MACHINE_ARCH_FLAG "/machine:ARM")
+ else()
+ set(_MACHINE_ARCH_FLAG "/machine:${MSVC_CXX_ARCHITECTURE_ID}")
+ endif()
 elseif(MSVC_Fortran_ARCHITECTURE_ID)
   set(_MACHINE_ARCH_FLAG "/machine:${MSVC_Fortran_ARCHITECTURE_ID}")
 endif()
 set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} ${_MACHINE_ARCH_FLAG}")
 unset(_MACHINE_ARCH_FLAG)

@@ -266,12 +287,19 @@
   set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
   set(CMAKE_${lang}_LINK_EXECUTABLE
     "${_CMAKE_VS_LINK_EXE}<CMAKE_LINKER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR>${_PLATFORM_LINK_FLAGS} <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
 
- set(CMAKE_${lang}_FLAGS_INIT "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} /D_WINDOWS /W3${_FLAGS_${lang}}")
+ set(CMAKE_${lang}_FLAGS_INIT "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} ${_PLATFORM_COMPILE_FLAGS} /D_WINDOWS /W3${_FLAGS_${lang}}")
   set(CMAKE_${lang}_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od ${_RTC1}")
   set(CMAKE_${lang}_FLAGS_RELEASE_INIT "/MD /O2 /Ob2 /D NDEBUG")
   set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG")
   set(CMAKE_${lang}_LINKER_SUPPORTS_PDB ON)

thats setting it all up correctly.with this i am able to easily compile cmake based projects ( like libjpeg-turbo) with minor tweaks ( different library names for sockets , some functions missing from ce)
(0037968)
Brad King   
2015-02-13 10:41   
Re 0014552:0037965: Thanks. I split the patch up into 3 distinct parts and simplified some of the logic by using the notion of an ARM family. I left out the RC flags part discussed separately in 0015404. Please try out the v1-*.patch files attached.
(0037969)
Gunnar Roth   
2015-02-13 11:16   
thanks brad, your patches look excellent. I would still like to test them, but i am now on vacation for one week to flee the cold here. So some patience is needed until i can verify the patches. I hope end of the month i can do that.

Best regards,
Gunnar
(0037970)
Brad King   
2015-02-13 11:22   
Re 0014552:0037969: Okay, please report back here once you've tested them and I'll look at integrating the changes upstream.
(0038019)
Gunnar Roth   
2015-02-23 08:58   
Hi Brad, now i found the time to test your patch.
Well it did not work first , but its easy to fix. you use non existent _MSVC_CXX_ARCHITECTURE_ID and _MSVC_C_ARCHITECTURE_ID. Just remove the leading underscore. after that it works as expected. i tested it with libjpeg-turbo and i can build ce6 x86 , ce6 armv4i, ce 8 armv7 and ce 8 x86.
(0038024)
Brad King   
2015-02-23 10:32   
Re 0014552:0038019: Thanks for testing. I fixed the typos to use _ as a prefix for _FAMILY but not for _ID. Applied:

 MSVC: Define /DWINCE when building for WinCE platforms
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bee22eec [^]

 MSVC: Distinguish among ARM architectures more precisely
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8e3d535a [^]

 MSVC: Compile with arch-specific flags on ARM platforms
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=dbe53d48 [^]

Please test the version as of commit dbe53d48.
(0038044)
Gunnar Roth   
2015-02-24 03:41   
test successfully completed.
thank you very much.
so waiting for cmake 3.3 having nearly ( as bug 15404 still needs a fix) excellent windows ce support.

Best regards,
Gunnar
(0038050)
Brad King   
2015-02-24 09:34   
Re 0014552:0038024: I had to revise the commits further because the middle one broke non-WinCE ARM platforms:

 MSVC: Define /DWINCE when building for WinCE platforms
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ea986676 [^]

 MSVC: Distinguish among ARM architectures more precisely
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=886dcaa7 [^]

 MSVC: Compile with arch-specific flags on ARM platforms
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3d612c73 [^]
(0038054)
Gunnar Roth   
2015-02-24 10:23   
ok i looked at the change and for my case its the same with or without it.
(0039063)
Robert Maynard   
2015-07-08 08:57   
Closing resolved issues that have not been updated in more than 4 months.