Skip to content

Commit

Permalink
Fix CMakeDetectArch for x86
Browse files Browse the repository at this point in the history
  • Loading branch information
cbnolok committed Jun 26, 2024
1 parent 147dda9 commit b55c3d9
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 57 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build_linux_x86.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Linux x86
name: Linux x86

on:
- push
Expand Down Expand Up @@ -51,14 +51,14 @@ jobs:
#wget --quiet --output-document=temp2.deb http://launchpadlibrarian.net/355877538/libmariadb-dev_3.0.3-1build1_i386.deb
# Third choice: directly download and install packages from Debian repos?
echo "Packets to be installed by libmariadb3:"
dpkg-deb -c temp1.deb
#echo "Packages to be installed by libmariadb3:"
#dpkg-deb -c temp1.deb
echo "Installing via dpkg libmariadb3"
sudo dpkg -i temp1.deb
echo "Done"
echo "Packets to be installed by libmariadb-dev:"
dpkg-deb -c temp2.deb
#echo "Packages to be installed by libmariadb-dev:"
#dpkg-deb -c temp2.deb
echo "Installing via dpkg libmariadb-dev"
sudo dpkg -i temp2.deb
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_linux_x86_64.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Linux x86_64
name: Linux x86_64

on:
- push
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_osx_arm.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build MacOS ARM
name: MacOS ARM

on:
- push
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_osx_x86_64.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build MacOS x86_64
name: MacOS x86_64

on:
- push
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_win_x86.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Windows x86
name: Windows x86

on:
- push
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_win_x86_64.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Windows x86_64
name: Windows x86_64

on:
- push
Expand Down
96 changes: 58 additions & 38 deletions cmake/CMakeDetectArch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

# Convert CMake vars into the format that OpenBLAS expects (modified for SphereServer)

# TODO: Lazy workaround, this has to be fixed if someone desires to cross compile. !!!!!!!!
set (CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}" CACHE INTERNAL "" FORCE)
# If i'm not overriding it, use mine (host machine).
if (NOT CMAKE_SYSTEM_PROCESSOR)
set (CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}" CACHE INTERNAL "" FORCE)
endif ()

string(TOUPPER "${CMAKE_SYSTEM_NAME}" HOST_OS)
if ("${HOST_OS}" STREQUAL "WINDOWS")
Expand All @@ -22,6 +24,8 @@ if ("${HOST_OS}" STREQUAL "LINUX")
endif()
endif()

message (STATUS "Detecting target arch from SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
message (STATUS "Host machine: ${HOST_OS}")

if(MINGW)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpmachine
Expand All @@ -32,6 +36,22 @@ if(MINGW)
endif()
endif()


if (ARCH_BITS)
if ( NOT (ARCH_BITS EQUAL 64 OR ARCH_BITS EQUAL 32) )
message(ERROR "Invalid ARCH_BITS?")
endif ()
else ()
if (${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set (ARCH_BITS 64 CACHE INTERNAL "")
elseif (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
set (ARCH_BITS 32 CACHE INTERNAL "")
else ()
#set (ARCH_BITS -1)
message(ERROR "Unknown arch?")
endif ()
endif ()

# Pretty thorough determination of arch. Add more if needed
if(CMAKE_CL_64 OR MINGW64)
if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)")
Expand All @@ -50,23 +70,19 @@ elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "loongarch64.*")
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "riscv64.*")
set(RISCV64 1)
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "amd64.*|x86_64.*|AMD64.*" OR ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" AND "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i686.*|i386.*|x86.*"))
if (NOT ARCH_BITS)
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set(X86_64 1)
else()
set(X86 1)
endif()
else()
if (${ARCH_BITS} EQUAL 64)
if (${ARCH_BITS} EQUAL 64)
set(X86_64 1)
else ()
else ()
set(X86 1)
endif()
endif()
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
set(X86 1)
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i686.*|i386.*|x86.*|x86_64.*|amd64.*|AMD64.*")
if (${ARCH_BITS} EQUAL 64)
set(X86_64 1)
else ()
set(X86 1)
endif()
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*|armv8.*)")
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
if (${ARCH_BITS} EQUAL 64)
set(ARM64 1)
else()
set(ARM 1)
Expand All @@ -93,29 +109,31 @@ else ()
message(WARNING "Target ARCH could not be determined, got \"${CMAKE_SYSTEM_PROCESSOR}\"")
endif()

if (X86_64)
set(ARCH "x86_64" CACHE INTERNAL "")
set(ARCH_BASE "x86" CACHE INTERNAL "")
elseif(X86)
set(ARCH "x86" CACHE INTERNAL "")
set(ARCH_BASE "x86" CACHE INTERNAL "")
elseif(POWER)
set(ARCH "power" CACHE INTERNAL "")
set(ARCH_BASE "power" CACHE INTERNAL "")
elseif(MIPS32)
set(ARCH "mips" CACHE INTERNAL "")
set(ARCH_BASE "mips" CACHE INTERNAL "")
elseif(MIPS64)
set(ARCH "mips64" CACHE INTERNAL "")
set(ARCH_BASE "mips" CACHE INTERNAL "")
elseif(ARM)
set(ARCH "arm" CACHE INTERNAL "")
set(ARCH_BASE "arm" CACHE INTERNAL "")
elseif(ARM64)
set(ARCH "arm64" CACHE INTERNAL "")
set(ARCH_BASE "arm" CACHE INTERNAL "")
else()
set(ARCH ${CMAKE_SYSTEM_PROCESSOR} CACHE INTERNAL "Target Architecture")
if (NOT ARCH)
if (X86_64)
set(ARCH "x86_64" CACHE INTERNAL "")
set(ARCH_BASE "x86" CACHE INTERNAL "")
elseif(X86)
set(ARCH "x86" CACHE INTERNAL "")
set(ARCH_BASE "x86" CACHE INTERNAL "")
elseif(POWER)
set(ARCH "power" CACHE INTERNAL "")
set(ARCH_BASE "power" CACHE INTERNAL "")
elseif(MIPS32)
set(ARCH "mips" CACHE INTERNAL "")
set(ARCH_BASE "mips" CACHE INTERNAL "")
elseif(MIPS64)
set(ARCH "mips64" CACHE INTERNAL "")
set(ARCH_BASE "mips" CACHE INTERNAL "")
elseif(ARM)
set(ARCH "arm" CACHE INTERNAL "")
set(ARCH_BASE "arm" CACHE INTERNAL "")
elseif(ARM64)
set(ARCH "arm64" CACHE INTERNAL "")
set(ARCH_BASE "arm" CACHE INTERNAL "")
else()
set(ARCH ${CMAKE_SYSTEM_PROCESSOR} CACHE INTERNAL "Target Architecture")
endif ()
endif ()

if (NOT ARCH_BITS)
Expand All @@ -131,3 +149,5 @@ if(ARCH_BITS EQUAL 64)
else()
set(ARCH_BITS32 1 CACHE INTERNAL "")
endif()

MESSAGE (STATUS "Target Arch: ${ARCH}")
3 changes: 2 additions & 1 deletion cmake/toolchains/Linux-Clang-x86.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ function (toolchain_after_project)
MESSAGE (STATUS "Toolchain: Linux-Clang-x86.cmake.")
#SET(CMAKE_SYSTEM_NAME "Linux" PARENT_SCOPE)
SET(ARCH_BASE "x86" CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 64 CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 32 CACHE INTERNAL "" FORCE) # override
SET(ARCH "x86" CACHE INTERNAL "" FORCE) # override
SET(CMAKE_SYSTEM_PROCESSOR "${ARCH}" CACHE INTERNAL "" FORCE)

toolchain_after_project_common()

Expand Down
1 change: 1 addition & 0 deletions cmake/toolchains/Linux-Clang-x86_64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function (toolchain_after_project)
SET(ARCH_BASE "x86" CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 64 CACHE INTERNAL "" FORCE) # override
SET(ARCH "x86_64" CACHE INTERNAL "" FORCE) # override
SET(CMAKE_SYSTEM_PROCESSOR "${ARCH}" CACHE INTERNAL "" FORCE)

toolchain_after_project_common()

Expand Down
3 changes: 2 additions & 1 deletion cmake/toolchains/Linux-GNU-x86.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ function (toolchain_after_project)
MESSAGE (STATUS "Toolchain: Linux-GNU-x86.cmake.")
#SET(CMAKE_SYSTEM_NAME "Linux" PARENT_SCOPE)
SET(ARCH_BASE "x86" CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 64 CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 32 CACHE INTERNAL "" FORCE) # override
SET(ARCH "x86" CACHE INTERNAL "" FORCE) # override
SET(CMAKE_SYSTEM_PROCESSOR "${ARCH}" CACHE INTERNAL "" FORCE)

toolchain_after_project_common()

Expand Down
1 change: 1 addition & 0 deletions cmake/toolchains/Linux-GNU-x86_64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function (toolchain_after_project)
SET(ARCH_BASE "x86" CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 64 CACHE INTERNAL "" FORCE) # override
SET(ARCH "x86_64" CACHE INTERNAL "" FORCE) # override
SET(CMAKE_SYSTEM_PROCESSOR "${ARCH}" CACHE INTERNAL "" FORCE)

toolchain_after_project_common()

Expand Down
1 change: 1 addition & 0 deletions cmake/toolchains/OSX-AppleClang-x86_64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function (toolchain_after_project)
SET(ARCH_BASE "x86" CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 64 CACHE INTERNAL "" FORCE) # override
SET(ARCH "x86_64" CACHE INTERNAL "" FORCE) # override
SET(CMAKE_SYSTEM_PROCESSOR "${ARCH}" CACHE INTERNAL "" FORCE)

toolchain_after_project_common()

Expand Down
3 changes: 2 additions & 1 deletion cmake/toolchains/Windows-Clang-x86.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ function (toolchain_after_project)
MESSAGE (STATUS "Toolchain: Windows-Clang-x86.cmake.")
#SET(CMAKE_SYSTEM_NAME "Windows" PARENT_SCOPE)
SET(ARCH_BASE "x86" CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 64 CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 32 CACHE INTERNAL "" FORCE) # override
SET(ARCH "x86" CACHE INTERNAL "" FORCE) # override
SET(CMAKE_SYSTEM_PROCESSOR "${ARCH}" CACHE INTERNAL "" FORCE)

toolchain_after_project_common() # To enable RC language, to compile Windows Resource files

Expand Down
1 change: 1 addition & 0 deletions cmake/toolchains/Windows-Clang-x86_64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function (toolchain_after_project)
SET(ARCH_BASE "x86" CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 64 CACHE INTERNAL "" FORCE) # override
SET(ARCH "x86_64" CACHE INTERNAL "" FORCE) # override
SET(CMAKE_SYSTEM_PROCESSOR "${ARCH}" CACHE INTERNAL "" FORCE)

toolchain_after_project_common() # To enable RC language, to compile Windows Resource files

Expand Down
3 changes: 2 additions & 1 deletion cmake/toolchains/Windows-GNU-x86.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ function (toolchain_after_project)
MESSAGE (STATUS "Toolchain: Windows-GNU-x86.cmake.")
#SET(CMAKE_SYSTEM_NAME "Windows" PARENT_SCOPE)
SET(ARCH_BASE "x86" CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 64 CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 32 CACHE INTERNAL "" FORCE) # override
SET(ARCH "x86" CACHE INTERNAL "" FORCE) # override
SET(CMAKE_SYSTEM_PROCESSOR "${ARCH}" CACHE INTERNAL "" FORCE)

toolchain_after_project_common() # Also to enable RC language, to compile Windows Resource files

Expand Down
1 change: 1 addition & 0 deletions cmake/toolchains/Windows-GNU-x86_64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function (toolchain_after_project)
SET(ARCH_BASE "x86" CACHE INTERNAL "" FORCE) # override
SET(ARCH_BITS 64 CACHE INTERNAL "" FORCE) # override
SET(ARCH "x86_64" CACHE INTERNAL "" FORCE) # override
SET(CMAKE_SYSTEM_PROCESSOR "${ARCH}" CACHE INTERNAL "" FORCE)

toolchain_after_project_common() # To enable RC language, to compile Windows Resource files

Expand Down
8 changes: 8 additions & 0 deletions cmake/toolchains/Windows-MSVC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ function (toolchain_after_project)
SET(ARCH_BITS 32 CACHE INTERNAL "" FORCE) # override
ENDIF ()
]]
if (NOT CMAKE_VS_PLATFORM_NAME)
set (CMAKE_VS_PLATFORM_NAME "${CMAKE_VS_PLATFORM_NAME_DEFAULT}")
endif ()
if (${CMAKE_VS_PLATFORM_NAME} STREQUAL "Win32")
set (CMAKE_SYSTEM_PROCESSOR "x86" CACHE INTERNAL "" FORCE)
endif ()
set (CMAKE_SYSTEM_PROCESSOR "${CMAKE_VS_PLATFORM_NAME}" CACHE INTERNAL "" FORCE)

include ("${CMAKE_SOURCE_DIR}/cmake/CMakeDetectArch.cmake")

MESSAGE (STATUS "Target Arch: ${ARCH}")
Expand Down
1 change: 0 additions & 1 deletion cmake/toolchains/include/Linux-Clang_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ endfunction ()

function (toolchain_after_project_common)
include ("${CMAKE_SOURCE_DIR}/cmake/CMakeDetectArch.cmake")
MESSAGE (STATUS "Target Arch: ${ARCH}")
endfunction ()

function (toolchain_exe_stuff_common)
Expand Down
1 change: 0 additions & 1 deletion cmake/toolchains/include/Linux-GNU_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ endfunction ()

function (toolchain_after_project_common)
include ("${CMAKE_SOURCE_DIR}/cmake/CMakeDetectArch.cmake")
MESSAGE (STATUS "Target Arch: ${ARCH}")
endfunction ()

function (toolchain_exe_stuff_common)
Expand Down
1 change: 0 additions & 1 deletion cmake/toolchains/include/OSX-AppleClang_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ endfunction ()

function (toolchain_after_project_common)
include ("${CMAKE_SOURCE_DIR}/cmake/CMakeDetectArch.cmake")
MESSAGE (STATUS "Target Arch: ${ARCH}")
endfunction ()

function (toolchain_exe_stuff_common)
Expand Down
1 change: 0 additions & 1 deletion cmake/toolchains/include/Windows-Clang_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ endfunction ()
function (toolchain_after_project_common)
ENABLE_LANGUAGE(RC)
include ("${CMAKE_SOURCE_DIR}/cmake/CMakeDetectArch.cmake")
MESSAGE (STATUS "Target Arch: ${ARCH}")
endfunction ()


Expand Down
1 change: 0 additions & 1 deletion cmake/toolchains/include/Windows-GNU_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ endfunction ()
function (toolchain_after_project_common)
ENABLE_LANGUAGE(RC)
include ("${CMAKE_SOURCE_DIR}/cmake/CMakeDetectArch.cmake")
MESSAGE (STATUS "Target Arch: ${ARCH}")
endfunction ()


Expand Down

0 comments on commit b55c3d9

Please sign in to comment.