[libc-commits] [PATCH] D95203: [CMake][libc] Don't do CPU feature detection when cross-compiling
Petr Hosek via Phabricator via libc-commits
libc-commits at lists.llvm.org
Thu Jan 28 12:55:00 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4819eec1a2a: [CMake][libc] Don't do CPU feature detection when cross-compiling (authored by phosek).
Herald added a project: libc-project.
Herald added a subscriber: libc-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95203/new/
https://reviews.llvm.org/D95203
Files:
libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
libc/test/src/string/CMakeLists.txt
Index: libc/test/src/string/CMakeLists.txt
===================================================================
--- libc/test/src/string/CMakeLists.txt
+++ libc/test/src/string/CMakeLists.txt
@@ -183,12 +183,12 @@
libc.src.string.strtok_r
)
-# Tests all implementations that can run on the host.
+# Tests all implementations that can run on the target CPU.
function(add_libc_multi_impl_test name)
get_property(fq_implementations GLOBAL PROPERTY ${name}_implementations)
foreach(fq_config_name IN LISTS fq_implementations)
get_target_property(required_cpu_features ${fq_config_name} REQUIRE_CPU_FEATURES)
- host_supports(can_run "${required_cpu_features}")
+ cpu_supports(can_run "${required_cpu_features}")
if(can_run)
add_libc_unittest(
${fq_config_name}_test
Index: libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
+++ libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -7,15 +7,15 @@
list(SORT ALL_CPU_FEATURES)
endif()
-# Function to check whether the host supports the provided set of features.
+# Function to check whether the target CPU supports the provided set of features.
# Usage:
-# host_supports(
+# cpu_supports(
# <output variable>
# <list of cpu features>
# )
-function(host_supports output_var features)
- _intersection(a "${HOST_CPU_FEATURES}" "${features}")
- if("${a}" STREQUAL "${features}")
+function(cpu_supports output_var features)
+ _intersection(var "${LIBC_CPU_FEATURES}" "${features}")
+ if("${var}" STREQUAL "${features}")
set(${output_var} TRUE PARENT_SCOPE)
else()
unset(${output_var} PARENT_SCOPE)
@@ -126,12 +126,22 @@
endif()
endfunction()
-# Populates the HOST_CPU_FEATURES list.
-# Use -march=native only when the compiler supports it.
-include(CheckCXXCompilerFlag)
-CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
-if(COMPILER_SUPPORTS_MARCH_NATIVE)
- _check_defined_cpu_feature(HOST_CPU_FEATURES MARCH native)
+set(LIBC_CPU_FEATURES "" CACHE PATH "supported CPU features")
+
+if(CMAKE_CROSSCOMPILING)
+ _intersection(cpu_features "${ALL_CPU_FEATURES}" "${LIBC_CPU_FEATURES}")
+ if(NOT "${cpu_features}" STREQUAL "${LIBC_CPU_FEATURES}")
+ message(FATAL_ERROR "Unsupported CPU features: ${cpu_features}")
+ endif()
+ set(LIBC_CPU_FEATURES "${cpu_features}")
else()
- _check_defined_cpu_feature(HOST_CPU_FEATURES)
+ # Populates the LIBC_CPU_FEATURES list.
+ # Use -march=native only when the compiler supports it.
+ include(CheckCXXCompilerFlag)
+ CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
+ if(COMPILER_SUPPORTS_MARCH_NATIVE)
+ _check_defined_cpu_feature(LIBC_CPU_FEATURES MARCH native)
+ else()
+ _check_defined_cpu_feature(LIBC_CPU_FEATURES)
+ endif()
endif()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95203.319944.patch
Type: text/x-patch
Size: 2886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210128/0e7e8809/attachment-0001.bin>
More information about the libc-commits
mailing list