mirror of
https://github.com/dhewm/dhewm3-sdk.git
synced 2024-11-29 15:52:03 +00:00
Fix build with Visual Studio's builtin CMake support
For some reason MSVCs integrated CMake doesn't set CMAKE_GENERATOR_PLATFORM so my CPU arch detection magic in CMakeLists.txt didn't work in that case.. Now (when using MSVC) the CPU architecture (D3_ARCH) is set in neo/sys/platform.h instead (NOTE: the sys/platform.h part was merged in "Sync sys/platform.h, incl. Workaround for MCST-LCC compiler").
This commit is contained in:
parent
bd4f0556bf
commit
695dfbc923
1 changed files with 20 additions and 24 deletions
|
@ -1,4 +1,4 @@
|
||||||
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
|
cmake_minimum_required(VERSION 2.8...3.22 FATAL_ERROR)
|
||||||
project(dhewm3sdk)
|
project(dhewm3sdk)
|
||||||
|
|
||||||
option(BASE "Build the base (game/) game code" OFF)
|
option(BASE "Build the base (game/) game code" OFF)
|
||||||
|
@ -80,21 +80,9 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR))
|
||||||
# special case: cross-compiling, here CMAKE_SYSTEM_PROCESSOR should be correct, hopefully
|
# special case: cross-compiling, here CMAKE_SYSTEM_PROCESSOR should be correct, hopefully
|
||||||
# (just leave cpu at ${CMAKE_SYSTEM_PROCESSOR})
|
# (just leave cpu at ${CMAKE_SYSTEM_PROCESSOR})
|
||||||
elseif(MSVC)
|
elseif(MSVC)
|
||||||
message(STATUS "CMAKE_GENERATOR_PLATFORM: ${CMAKE_GENERATOR_PLATFORM}")
|
# because all this wasn't ugly enough, it turned out that, unlike standalone CMake, Visual Studio's
|
||||||
if(CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
|
# integrated CMake doesn't set CMAKE_GENERATOR_PLATFORM, so I gave up on guessing the CPU arch here
|
||||||
set(cpu "x86")
|
# and moved the CPU detection to MSVC-specific code in neo/sys/platform.h
|
||||||
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
|
|
||||||
set(cpu "x86_64")
|
|
||||||
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
|
|
||||||
# at least on RPi 32bit, gcc -dumpmachine outputs "arm-linux-gnueabihf",
|
|
||||||
# so we'll use "arm" there => use the same for 32bit ARM on MSVC
|
|
||||||
set(cpu "arm")
|
|
||||||
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
|
|
||||||
set(cpu "arm64")
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Unknown Target CPU/platform ${CMAKE_GENERATOR_PLATFORM}")
|
|
||||||
endif()
|
|
||||||
message(STATUS " => CPU architecture extracted from that: \"${cpu}\"")
|
|
||||||
else() # not MSVC and not cross-compiling, assume GCC or clang (-compatible), seems to work for MinGW as well
|
else() # not MSVC and not cross-compiling, assume GCC or clang (-compatible), seems to work for MinGW as well
|
||||||
execute_process(COMMAND ${CMAKE_C_COMPILER} "-dumpmachine"
|
execute_process(COMMAND ${CMAKE_C_COMPILER} "-dumpmachine"
|
||||||
RESULT_VARIABLE cc_dumpmachine_res
|
RESULT_VARIABLE cc_dumpmachine_res
|
||||||
|
@ -132,8 +120,6 @@ elseif(cpu MATCHES "[aA][rR][mM].*") # some kind of arm..
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions(-DD3_ARCH="${cpu}" -DD3_SIZEOFPTR=${CMAKE_SIZEOF_VOID_P})
|
|
||||||
|
|
||||||
# target os
|
# target os
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
set(os "macosx")
|
set(os "macosx")
|
||||||
|
@ -141,15 +127,23 @@ else()
|
||||||
string(TOLOWER "${CMAKE_SYSTEM_NAME}" os)
|
string(TOLOWER "${CMAKE_SYSTEM_NAME}" os)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions(-DD3_OSTYPE="${os}")
|
add_definitions(-DD3_OSTYPE="${os}" -DD3_SIZEOFPTR=${CMAKE_SIZEOF_VOID_P})
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
# for MSVC D3_ARCH is set in code (in neo/sys/platform.h)
|
||||||
|
message(STATUS "Setting -DD3_SIZEOFPTR=${CMAKE_SIZEOF_VOID_P} -DD3_OSTYPE=\"${os}\" - NOT setting D3_ARCH, because we're targeting MSVC (VisualC++)")
|
||||||
|
# make sure ${cpu} isn't (cant't be) used by CMake when building with MSVC
|
||||||
|
unset(cpu)
|
||||||
|
else()
|
||||||
|
add_definitions(-DD3_ARCH="${cpu}")
|
||||||
message(STATUS "Setting -DD3_ARCH=\"${cpu}\" -DD3_SIZEOFPTR=${CMAKE_SIZEOF_VOID_P} -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)
|
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
|
# 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(SEND_ERROR "CMake thinks sizeof(void*) == 4, but the target CPU ${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)!")
|
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()
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# build type
|
# build type
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
@ -312,7 +306,9 @@ configure_file(
|
||||||
"${CMAKE_BINARY_DIR}/config.h"
|
"${CMAKE_BINARY_DIR}/config.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(NOT MSVC)
|
||||||
message(STATUS "Building ${CMAKE_BUILD_TYPE} for ${os}-${cpu}")
|
message(STATUS "Building ${CMAKE_BUILD_TYPE} for ${os}-${cpu}")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(NOT APPLE AND NOT WIN32)
|
if(NOT APPLE AND NOT WIN32)
|
||||||
message(STATUS "The install target will use the following directories:")
|
message(STATUS "The install target will use the following directories:")
|
||||||
|
|
Loading…
Reference in a new issue