From b55c3d9acafc5b2a68d44a7315c54807ecf020f6 Mon Sep 17 00:00:00 2001 From: cbnolok Date: Wed, 26 Jun 2024 17:16:25 +0200 Subject: [PATCH] Fix CMakeDetectArch for x86 --- .github/workflows/build_linux_x86.yml | 10 +- .github/workflows/build_linux_x86_64.yml | 2 +- .github/workflows/build_osx_arm.yml | 2 +- .github/workflows/build_osx_x86_64.yml | 2 +- .github/workflows/build_win_x86.yml | 2 +- .github/workflows/build_win_x86_64.yml | 2 +- cmake/CMakeDetectArch.cmake | 96 +++++++++++-------- cmake/toolchains/Linux-Clang-x86.cmake | 3 +- cmake/toolchains/Linux-Clang-x86_64.cmake | 1 + cmake/toolchains/Linux-GNU-x86.cmake | 3 +- cmake/toolchains/Linux-GNU-x86_64.cmake | 1 + cmake/toolchains/OSX-AppleClang-x86_64.cmake | 1 + cmake/toolchains/Windows-Clang-x86.cmake | 3 +- cmake/toolchains/Windows-Clang-x86_64.cmake | 1 + cmake/toolchains/Windows-GNU-x86.cmake | 3 +- cmake/toolchains/Windows-GNU-x86_64.cmake | 1 + cmake/toolchains/Windows-MSVC.cmake | 8 ++ .../include/Linux-Clang_common.inc.cmake | 1 - .../include/Linux-GNU_common.inc.cmake | 1 - .../include/OSX-AppleClang_common.inc.cmake | 1 - .../include/Windows-Clang_common.inc.cmake | 1 - .../include/Windows-GNU_common.inc.cmake | 1 - 22 files changed, 89 insertions(+), 57 deletions(-) diff --git a/.github/workflows/build_linux_x86.yml b/.github/workflows/build_linux_x86.yml index 84899d273..db8fe8c76 100644 --- a/.github/workflows/build_linux_x86.yml +++ b/.github/workflows/build_linux_x86.yml @@ -1,4 +1,4 @@ -name: Build Linux x86 +name: Linux x86 on: - push @@ -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 diff --git a/.github/workflows/build_linux_x86_64.yml b/.github/workflows/build_linux_x86_64.yml index b478e48d4..2eee6222f 100644 --- a/.github/workflows/build_linux_x86_64.yml +++ b/.github/workflows/build_linux_x86_64.yml @@ -1,4 +1,4 @@ -name: Build Linux x86_64 +name: Linux x86_64 on: - push diff --git a/.github/workflows/build_osx_arm.yml b/.github/workflows/build_osx_arm.yml index 51e8a2948..4ec9673ec 100644 --- a/.github/workflows/build_osx_arm.yml +++ b/.github/workflows/build_osx_arm.yml @@ -1,4 +1,4 @@ -name: Build MacOS ARM +name: MacOS ARM on: - push diff --git a/.github/workflows/build_osx_x86_64.yml b/.github/workflows/build_osx_x86_64.yml index 1b1fd9580..ded620c17 100644 --- a/.github/workflows/build_osx_x86_64.yml +++ b/.github/workflows/build_osx_x86_64.yml @@ -1,4 +1,4 @@ -name: Build MacOS x86_64 +name: MacOS x86_64 on: - push diff --git a/.github/workflows/build_win_x86.yml b/.github/workflows/build_win_x86.yml index a7d776c9a..476da38d1 100644 --- a/.github/workflows/build_win_x86.yml +++ b/.github/workflows/build_win_x86.yml @@ -1,4 +1,4 @@ -name: Build Windows x86 +name: Windows x86 on: - push diff --git a/.github/workflows/build_win_x86_64.yml b/.github/workflows/build_win_x86_64.yml index b796f2e04..7c464127d 100644 --- a/.github/workflows/build_win_x86_64.yml +++ b/.github/workflows/build_win_x86_64.yml @@ -1,4 +1,4 @@ -name: Build Windows x86_64 +name: Windows x86_64 on: - push diff --git a/cmake/CMakeDetectArch.cmake b/cmake/CMakeDetectArch.cmake index ba61e3c46..2f0f0eec0 100644 --- a/cmake/CMakeDetectArch.cmake +++ b/cmake/CMakeDetectArch.cmake @@ -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") @@ -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 @@ -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.*)") @@ -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) @@ -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) @@ -131,3 +149,5 @@ if(ARCH_BITS EQUAL 64) else() set(ARCH_BITS32 1 CACHE INTERNAL "") endif() + +MESSAGE (STATUS "Target Arch: ${ARCH}") diff --git a/cmake/toolchains/Linux-Clang-x86.cmake b/cmake/toolchains/Linux-Clang-x86.cmake index 87ff5463d..c7c69b4e5 100644 --- a/cmake/toolchains/Linux-Clang-x86.cmake +++ b/cmake/toolchains/Linux-Clang-x86.cmake @@ -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() diff --git a/cmake/toolchains/Linux-Clang-x86_64.cmake b/cmake/toolchains/Linux-Clang-x86_64.cmake index d86300853..a7636ccb8 100644 --- a/cmake/toolchains/Linux-Clang-x86_64.cmake +++ b/cmake/toolchains/Linux-Clang-x86_64.cmake @@ -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() diff --git a/cmake/toolchains/Linux-GNU-x86.cmake b/cmake/toolchains/Linux-GNU-x86.cmake index 6f9a00441..6b32b9504 100644 --- a/cmake/toolchains/Linux-GNU-x86.cmake +++ b/cmake/toolchains/Linux-GNU-x86.cmake @@ -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() diff --git a/cmake/toolchains/Linux-GNU-x86_64.cmake b/cmake/toolchains/Linux-GNU-x86_64.cmake index ce4100b90..1d6afcaa7 100644 --- a/cmake/toolchains/Linux-GNU-x86_64.cmake +++ b/cmake/toolchains/Linux-GNU-x86_64.cmake @@ -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() diff --git a/cmake/toolchains/OSX-AppleClang-x86_64.cmake b/cmake/toolchains/OSX-AppleClang-x86_64.cmake index c4a05c417..a21f849ef 100644 --- a/cmake/toolchains/OSX-AppleClang-x86_64.cmake +++ b/cmake/toolchains/OSX-AppleClang-x86_64.cmake @@ -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() diff --git a/cmake/toolchains/Windows-Clang-x86.cmake b/cmake/toolchains/Windows-Clang-x86.cmake index 2377d59fd..3bf957ce5 100644 --- a/cmake/toolchains/Windows-Clang-x86.cmake +++ b/cmake/toolchains/Windows-Clang-x86.cmake @@ -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 diff --git a/cmake/toolchains/Windows-Clang-x86_64.cmake b/cmake/toolchains/Windows-Clang-x86_64.cmake index 0e6c1a029..7d360d96d 100644 --- a/cmake/toolchains/Windows-Clang-x86_64.cmake +++ b/cmake/toolchains/Windows-Clang-x86_64.cmake @@ -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 diff --git a/cmake/toolchains/Windows-GNU-x86.cmake b/cmake/toolchains/Windows-GNU-x86.cmake index 25f2ac1a7..28f3a1aa7 100644 --- a/cmake/toolchains/Windows-GNU-x86.cmake +++ b/cmake/toolchains/Windows-GNU-x86.cmake @@ -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 diff --git a/cmake/toolchains/Windows-GNU-x86_64.cmake b/cmake/toolchains/Windows-GNU-x86_64.cmake index 83c2e37d8..2c1ce7b94 100644 --- a/cmake/toolchains/Windows-GNU-x86_64.cmake +++ b/cmake/toolchains/Windows-GNU-x86_64.cmake @@ -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 diff --git a/cmake/toolchains/Windows-MSVC.cmake b/cmake/toolchains/Windows-MSVC.cmake index df0917f36..29b032cb1 100644 --- a/cmake/toolchains/Windows-MSVC.cmake +++ b/cmake/toolchains/Windows-MSVC.cmake @@ -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}") diff --git a/cmake/toolchains/include/Linux-Clang_common.inc.cmake b/cmake/toolchains/include/Linux-Clang_common.inc.cmake index a4258d74e..80eab79d1 100644 --- a/cmake/toolchains/include/Linux-Clang_common.inc.cmake +++ b/cmake/toolchains/include/Linux-Clang_common.inc.cmake @@ -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) diff --git a/cmake/toolchains/include/Linux-GNU_common.inc.cmake b/cmake/toolchains/include/Linux-GNU_common.inc.cmake index 5999fc514..13473b9ca 100644 --- a/cmake/toolchains/include/Linux-GNU_common.inc.cmake +++ b/cmake/toolchains/include/Linux-GNU_common.inc.cmake @@ -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) diff --git a/cmake/toolchains/include/OSX-AppleClang_common.inc.cmake b/cmake/toolchains/include/OSX-AppleClang_common.inc.cmake index e35638665..72bb9a765 100644 --- a/cmake/toolchains/include/OSX-AppleClang_common.inc.cmake +++ b/cmake/toolchains/include/OSX-AppleClang_common.inc.cmake @@ -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) diff --git a/cmake/toolchains/include/Windows-Clang_common.inc.cmake b/cmake/toolchains/include/Windows-Clang_common.inc.cmake index e0fede999..6337bb373 100644 --- a/cmake/toolchains/include/Windows-Clang_common.inc.cmake +++ b/cmake/toolchains/include/Windows-Clang_common.inc.cmake @@ -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 () diff --git a/cmake/toolchains/include/Windows-GNU_common.inc.cmake b/cmake/toolchains/include/Windows-GNU_common.inc.cmake index a56db52ce..5d482e05c 100644 --- a/cmake/toolchains/include/Windows-GNU_common.inc.cmake +++ b/cmake/toolchains/include/Windows-GNU_common.inc.cmake @@ -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 ()