Skip to content

Commit

Permalink
MSVC cross compiling handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ktakashi committed Dec 1, 2023
1 parent 89ee7da commit 4c7f8ed
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
61 changes: 37 additions & 24 deletions cmake/Triple.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,45 @@ MACRO (TRIPLE _PROCESSOR _PLATFORM _OS _VENDOR _TRIPLE)
CHECK_TYPE_SIZE(void* SIZEOF_VOIDP)
ENDIF()

# the code based on clang GetTriple.cmake
IF (${_PROCESSOR} STREQUAL "x86")
# CMake somehow does not detect proper processor on win64
IF (SIZEOF_VOIDP EQUAL 4)
SET(${_PROCESSOR} "i686")
ELSE()
# assume it's x86_64
# For MSVC cross compiler
IF (MSVC)
# Checking C compiler must be enough for our use case
MESSAGE(STATUS "MSVC architecture: ${MSVC_C_ARCHITECTURE_ID}")
IF (MSVC_C_ARCHITECTURE_ID MATCHES "^ARM")
STRING(TOLOWER ${MSVC_C_ARCHITECTURE_ID} ${_PROCESSOR})
ELSEIF(MSVC_C_ARCHITECTURE_ID STREQUAL "x64")
SET(${_PROCESSOR} "x86_64")
ENDIF()
ENDIF()

# on 64 bit Linux but trying to compile with 32 bit
# CMake does not pretend to be 32 bit archtecture.
# We need to modify it manually
IF (${_PROCESSOR} STREQUAL "x86_64")
IF (SIZEOF_VOIDP EQUAL 4)
ELSE()
SET(${_PROCESSOR} "i686")
ENDIF()
ENDIF()

# On Windows, if CMake works properly, the value must be this.
IF (${_PROCESSOR} STREQUAL "amd64")
IF (SIZEOF_VOIDP EQUAL 4)
SET(${_PROCESSOR} "i686")
ELSE()
SET(${_PROCESSOR} "x86_64")
ELSE()
# the code based on clang GetTriple.cmake
IF (${_PROCESSOR} STREQUAL "x86")
# CMake somehow does not detect proper processor on win64
IF (SIZEOF_VOIDP EQUAL 4)
SET(${_PROCESSOR} "i686")
ELSE()
# assume it's x86_64
SET(${_PROCESSOR} "x86_64")
ENDIF()
ENDIF()

# on 64 bit Linux but trying to compile with 32 bit
# CMake does not pretend to be 32 bit archtecture.
# We need to modify it manually
IF (${_PROCESSOR} STREQUAL "x86_64")
IF (SIZEOF_VOIDP EQUAL 4)
SET(${_PROCESSOR} "i686")
ENDIF()
ENDIF()

# On Windows, if CMake works properly, the value must be this.
IF (${_PROCESSOR} STREQUAL "amd64")
IF (SIZEOF_VOIDP EQUAL 4)
SET(${_PROCESSOR} "i686")
ELSE()
SET(${_PROCESSOR} "x86_64")
ENDIF()
ENDIF()
ENDIF()

Expand All @@ -82,4 +95,4 @@ MACRO (TRIPLE _PROCESSOR _PLATFORM _OS _VENDOR _TRIPLE)
ENDIF()
SET(${_TRIPLE} "${${_PROCESSOR}}-${${_VENDOR}}-${${_OS}}")
MESSAGE(STATUS "Architecture triple: ${${_TRIPLE}}")
ENDMACRO (TRIPLE)
ENDMACRO (TRIPLE)
6 changes: 2 additions & 4 deletions ext/ffi/libffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ elseif (${arch} STREQUAL "arm64")
endif()
endif()

add_definitions(-D${TARGET})

if (${TARGET} STREQUAL "X86_DARWIN")
# It may be on all x86_64 architectures HAVE_LONG_DOUBLE must be 1, mustn't it?
#if (${arch} STREQUAL "x86_64")
Expand All @@ -176,9 +174,9 @@ if (${TARGETDIR} STREQUAL "unknown")
message(STATUS "custom libffi has not been ported to ${host}")
else ()
configure_file(cmake/ffi.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/ffi.h)
configure_file(cmake/fficonfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/fficonfig.h)
configure_file(cmake/fficonfig.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/fficonfig.h)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)

Expand Down

0 comments on commit 4c7f8ed

Please sign in to comment.