From 28d744c9ea332a10b9fc3061758d5f8031158727 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Wed, 5 Sep 2012 10:08:58 +0200 Subject: [PATCH] Add WindowsCE platform information files This enables CMake to create Makefiles targeting Windows CE devices. CMake needs to be run within a cross compile command prompt and requires a toolchain file which sets CMAKE_SYSTEM_NAME to "WindowsCE" and optionally CMAKE_SYSTEM_VERSION. --- Modules/Platform/Windows-MSVC.cmake | 54 +++++++++++++++++++---- Modules/Platform/WindowsCE-MSVC-C.cmake | 1 + Modules/Platform/WindowsCE-MSVC-CXX.cmake | 1 + Modules/Platform/WindowsCE-MSVC.cmake | 1 + Modules/Platform/WindowsCE.cmake | 1 + 5 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 Modules/Platform/WindowsCE-MSVC-C.cmake create mode 100644 Modules/Platform/WindowsCE-MSVC-CXX.cmake create mode 100644 Modules/Platform/WindowsCE-MSVC.cmake create mode 100644 Modules/Platform/WindowsCE.cmake diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index 238aa2467..cc48cfe29 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -38,8 +38,13 @@ endif() set(WIN32 1) -set(CMAKE_CREATE_WIN32_EXE /subsystem:windows) -set(CMAKE_CREATE_CONSOLE_EXE /subsystem:console) +if(CMAKE_SYSTEM_NAME MATCHES "WindowsCE") + set(CMAKE_CREATE_WIN32_EXE "/subsystem:windowsce /entry:WinMainCRTStartup") + set(CMAKE_CREATE_CONSOLE_EXE "/subsystem:windowsce /entry:mainACRTStartup") +else() + set(CMAKE_CREATE_WIN32_EXE "/subsystem:windows") + set(CMAKE_CREATE_CONSOLE_EXE "/subsystem:console") +endif() if(CMAKE_GENERATOR MATCHES "Visual Studio 6") set (CMAKE_NO_BUILD_TYPE 1) @@ -117,14 +122,38 @@ endif() # default to Debug builds set(CMAKE_BUILD_TYPE_INIT Debug) -if(MSVC_VERSION GREATER 1310) - set(_RTC1 "/RTC1") +if(CMAKE_SYSTEM_NAME MATCHES "WindowsCE") + string(TOUPPER "${MSVC_C_ARCHITECTURE_ID}" _MSVC_C_ARCHITECTURE_ID_UPPER) + string(TOUPPER "${MSVC_CXX_ARCHITECTURE_ID}" _MSVC_CXX_ARCHITECTURE_ID_UPPER) + + if("${CMAKE_SYSTEM_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)") + math(EXPR _CE_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}") + elseif("${CMAKE_SYSTEM_VERSION}" STREQUAL "") + 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_ID} /D_${_MSVC_C_ARCHITECTURE_ID_UPPER}_") + set(_PLATFORM_DEFINES_CXX " /D${MSVC_CXX_ARCHITECTURE_ID} /D_${_MSVC_CXX_ARCHITECTURE_ID_UPPER}_") + + set(_RTC1 "") set(_FLAGS_CXX " /GR /EHsc") - set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib") + set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib corelibc.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") else() - set(_RTC1 "/GZ") - set(_FLAGS_CXX " /GR /GX") - set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib") + set(_PLATFORM_DEFINES "/DWIN32") + + if(MSVC_VERSION GREATER 1310) + set(_RTC1 "/RTC1") + set(_FLAGS_CXX " /GR /EHsc") + set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib") + else() + set(_RTC1 "/GZ") + set(_FLAGS_CXX " /GR /GX") + set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib") + endif() endif() set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") @@ -136,6 +165,13 @@ set(_MACHINE_ARCH_FLAG ${MSVC_C_ARCHITECTURE_ID}) if(NOT _MACHINE_ARCH_FLAG) set(_MACHINE_ARCH_FLAG ${MSVC_CXX_ARCHITECTURE_ID}) endif() +if(CMAKE_SYSTEM_NAME MATCHES "WindowsCE") + if(_MACHINE_ARCH_FLAG MATCHES "ARM") + set(_MACHINE_ARCH_FLAG "THUMB") + elseif(_MACHINE_ARCH_FLAG MATCHES "SH") + set(_MACHINE_ARCH_FLAG "SH4") + endif() +endif() set (CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} /STACK:10000000 /machine:${_MACHINE_ARCH_FLAG}") @@ -196,7 +232,7 @@ macro(__windows_compiler_msvc lang) set(CMAKE_${lang}_LINK_EXECUTABLE "${_CMAKE_VS_LINK_EXE} ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} /Fe /Fd -link /implib: /version:. ${CMAKE_END_TEMP_FILE}") - set(CMAKE_${lang}_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000${_FLAGS_${lang}}") + set(CMAKE_${lang}_FLAGS_INIT "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} /D_WINDOWS /W3 /Zm1000${_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_RELWITHDEBINFO_INIT "/MD /Zi /O2 /Ob1 /D NDEBUG") diff --git a/Modules/Platform/WindowsCE-MSVC-C.cmake b/Modules/Platform/WindowsCE-MSVC-C.cmake new file mode 100644 index 000000000..ce8060bed --- /dev/null +++ b/Modules/Platform/WindowsCE-MSVC-C.cmake @@ -0,0 +1 @@ +include(Platform/Windows-MSVC-C) diff --git a/Modules/Platform/WindowsCE-MSVC-CXX.cmake b/Modules/Platform/WindowsCE-MSVC-CXX.cmake new file mode 100644 index 000000000..281eadc10 --- /dev/null +++ b/Modules/Platform/WindowsCE-MSVC-CXX.cmake @@ -0,0 +1 @@ +include(Platform/Windows-MSVC-CXX) diff --git a/Modules/Platform/WindowsCE-MSVC.cmake b/Modules/Platform/WindowsCE-MSVC.cmake new file mode 100644 index 000000000..d28b4aba0 --- /dev/null +++ b/Modules/Platform/WindowsCE-MSVC.cmake @@ -0,0 +1 @@ +include(Platform/Windows-MSVC) diff --git a/Modules/Platform/WindowsCE.cmake b/Modules/Platform/WindowsCE.cmake new file mode 100644 index 000000000..65b2eaed4 --- /dev/null +++ b/Modules/Platform/WindowsCE.cmake @@ -0,0 +1 @@ +include(Platform/Windows)