mdbx-cmake: provide CMAKE_HOST_ARCH and CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-04-22 17:45:28 +03:00
parent 039ebe1f14
commit 7770cae4b5

View File

@ -241,6 +241,61 @@ if(CMAKE_CXX_COMPILER_LOADED AND NOT CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID "${CMAKE_SYSTEM_ARCH}")
endif()
if(NOT CMAKE_HOST_ARCH)
if(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE)
set(CMAKE_HOST_ARCH "${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}")
elseif(CMAKE_HOST_PROCESSOR MATCHES "e2k.*|E2K.*|elbrus.*|ELBRUS.*")
set(CMAKE_HOST_ARCH "Elbrus")
elseif(CMAKE_HOST_PROCESSOR MATCHES "amd64.*|[xXiI]86_64.*|AMD64.*")
set(CMAKE_HOST_ARCH "x86_64")
elseif(CMAKE_HOST_PROCESSOR MATCHES "[iI][3-6]86.*|[xXiI]86.*")
set(CMAKE_HOST_ARCH "x86")
elseif(CMAKE_HOST_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|ARM64.*)")
set(CMAKE_HOST_ARCH "ARM64")
elseif(CMAKE_HOST_PROCESSOR MATCHES "^(arm.*|ARM.*)")
set(CMAKE_HOST_ARCH "ARM")
elseif(CMAKE_HOST_PROCESSOR MATCHES "^(powerpc|ppc)64.*")
set(CMAKE_HOST_ARCH "PPC64")
elseif(CMAKE_HOST_PROCESSOR MATCHES "^(powerpc|ppc).*")
set(CMAKE_HOST_ARCH "PPC")
elseif(CMAKE_HOST_PROCESSOR MATCHES "^(mips|MIPS)64.*")
set(CMAKE_HOST_ARCH "MIPS64")
elseif(CMAKE_HOST_PROCESSOR MATCHES "^(mips|MIPS).*")
set(CMAKE_HOST_ARCH "MIPS")
else()
set(CMAKE_HOST_ARCH "${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
endif()
if(NOT DEFINED CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
if(CMAKE_CROSSCOMPILING AND CMAKE_CROSSCOMPILING_EMULATOR)
set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET TRUE)
elseif(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET FALSE)
elseif(CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME
AND ((CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_PROCESSOR)
OR (CMAKE_SYSTEM_ARCH STREQUAL CMAKE_HOST_ARCH)
OR (WIN32 AND CMAKE_HOST_WIN32 AND X86_32 AND CMAKE_HOST_ARCH STREQUAL "x86_64")))
set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET TRUE)
message(STATUS
"Assume СAN RUN A BUILT EXECUTABLES, "
" since host (${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_ARCH})"
" match target (${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_ARCH})")
else()
if(CMAKE_C_COMPILER_LOADED)
include(CheckCSourceRuns)
check_c_source_runs("int main(void) { return 0; }" CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
elseif(CMAKE_CXX_COMPILER_LOADED)
include(CheckCXXSourceRuns)
check_cxx_source_runs("int main(void) { return 0; }" CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
endif()
if(NOT CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
message(STATUS "Force CMAKE_CROSSCOMPILING to TRUE")
set(CMAKE_CROSSCOMPILING TRUE)
endif()
endif()
endif()
if(MSVC)
check_compiler_flag("/WX" CC_HAS_WERROR)
else()