Detect architecture from the compiler instead of the host

This commit is contained in:
smallmodel 2025-08-06 20:19:04 +02:00 committed by Tim Angus
parent 404aa1bdb2
commit 074c0ecc4a
2 changed files with 9 additions and 12 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.18)
cmake_minimum_required(VERSION 3.25)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(identity)

View File

@ -4,20 +4,17 @@ set(DETECT_ARCH_C ${CMAKE_BINARY_DIR}/detect_arch.c)
file(WRITE ${DETECT_ARCH_C}
"#include \"${SOURCE_DIR}/qcommon/q_platform.h\"
#include <stdio.h>
int main()
{
puts(ARCH_STRING);
return 0;
}
#pragma message(\"@\" ARCH_STRING \"@\")
int main(void) { return 0; }
")
try_run(RUN_EXITCODE COMPILE_SUCCESS
${CMAKE_BINARY_DIR} ${DETECT_ARCH_C}
RUN_OUTPUT_VARIABLE ARCH)
try_compile(COMPILE_SUCCESS
SOURCES ${DETECT_ARCH_C}
OUTPUT_VARIABLE COMPILE_OUTPUT)
string(STRIP ${ARCH} ARCH)
string(REGEX MATCH "^[^\@]+@([a-zA-Z0-9_]+)@.*$" HAVE_MATCH ${COMPILE_OUTPUT})
set(ARCH ${CMAKE_MATCH_1})
if(NOT COMPILE_SUCCESS OR RUN_EXITCODE OR NOT ARCH)
if(NOT COMPILE_SUCCESS OR RUN_EXITCODE OR NOT HAVE_MATCH OR NOT ARCH)
message(FATAL_ERROR "Architecture detection failed")
endif()