mirror of
https://github.com/dhewm/dhewm3-sdk.git
synced 2024-11-24 05:21:20 +00:00
Fix Win32/VS build on Win64 hosts
Turns out that ${CMAKE_SYSTEM_PROCESSOR} is broken on Windows (both for Visual Studio and for 32bit MinGW/msys shells which for some reason seem to output x86_64 in uname -a)
This commit is contained in:
parent
967815d27e
commit
3b7cc39f28
1 changed files with 37 additions and 2 deletions
|
@ -67,12 +67,37 @@ if(cpu STREQUAL "powerpc")
|
|||
set(cpu "ppc")
|
||||
elseif(cpu MATCHES "i.86")
|
||||
set(cpu "x86")
|
||||
elseif(cpu MATCHES "[aA][mM][dD]64" OR cpu MATCHES "[xX]64")
|
||||
set(cpu "x86_64")
|
||||
endif()
|
||||
|
||||
if(MSVC AND CMAKE_CL_64)
|
||||
set(cpu "amd64")
|
||||
# On Windows ${CMAKE_SYSTEM_PROCESSOR} is broken (always returns host CPU)
|
||||
# which has only been reported >7 years ago (https://cmake.org/pipermail/cmake-developers/2014-September/011405.html)
|
||||
# so obviously a fix is too much to ask. Here's the special case to make that wonderful platform work;
|
||||
# except if it's Windows for ARM(64) I guess, no idea how to detect that properly (I don't own such hardware).
|
||||
if(MSVC)
|
||||
if(cpu MATCHES ".*[aA][rR][mM].*")
|
||||
message(FATAL_ERROR "please fix this code to work for Windows on ARM and send a pull request")
|
||||
endif()
|
||||
if(CMAKE_CL_64)
|
||||
set(cpu "x86_64")
|
||||
else()
|
||||
set(cpu "x86")
|
||||
endif()
|
||||
elseif(DEFINED ENV{MINGW_CHOST})
|
||||
# looks like it's broken in MinGW32 shells (or 32bit mingw-w64 shells) as well, this should help:
|
||||
message(STATUS "MINGW_CHOST = $ENV{MINGW_CHOST}")
|
||||
if($ENV{MINGW_CHOST} MATCHES "^i.86.*")
|
||||
set(cpu "x86")
|
||||
elseif($ENV{MINGW_CHOST} MATCHES "^x86_64.*")
|
||||
set(cpu "x86_64")
|
||||
else()
|
||||
message(FATAL_ERROR "please fix this code to work for MINGW_CHOST = $ENV{MINGW_CHOST} and send a pull request!")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_definitions(-DD3_ARCH="${cpu}" -DD3_SIZEOFPTR=${CMAKE_SIZEOF_VOID_P})
|
||||
|
||||
# target os
|
||||
if(APPLE)
|
||||
set(os "macosx")
|
||||
|
@ -80,6 +105,16 @@ else()
|
|||
string(TOLOWER "${CMAKE_SYSTEM_NAME}" os)
|
||||
endif()
|
||||
|
||||
add_definitions(-DD3_OSTYPE="${os}")
|
||||
|
||||
message(STATUS "Setting -DD3_ARCH=\"${cpu}\" -DD3_SIZEOFPTR=${CMAKE_SIZEOF_VOID_P} -DD3_OSTYPE=\"${os}\" ")
|
||||
|
||||
if(cpu MATCHES ".*64.*" AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
# tough luck if some CPU architecture has "64" in its name but uses 32bit pointers
|
||||
message(SEND_ERROR "CMake thinks sizeof(void*) == 4, but the target CPU looks like a 64bit CPU!")
|
||||
message(FATAL_ERROR "If you're building in a 32bit chroot on a 64bit host, switch to it with 'linux32 chroot' or at least call cmake with linux32 (or your OSs equivalent)!")
|
||||
endif()
|
||||
|
||||
# build type
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
|
||||
|
|
Loading…
Reference in a new issue