From 704bc423cc77f0d5c1a12550a31c6b04b885c610 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Tue, 20 Jul 2021 15:59:44 +0800 Subject: [PATCH] refact(cmake): change mcx16 detection to facilitate cross compiling (#351) * refact(cmake): change mcx16 detection to facilitate cross compiling Signed-off-by: SchrodingerZhu --- CMakeLists.txt | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34f6e53..613af3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,16 +116,6 @@ if(NOT MSVC) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") target_link_libraries(snmalloc_lib INTERFACE atomic) endif() - if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - # XXX elseif ARM? - endif() endif() if (WIN32) @@ -141,17 +131,11 @@ if (WIN32) endif() endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - endif() -endif () +# detect support for cmpxchg16b; werror is needed to make sure mcx16 must be used by targets +check_cxx_compiler_flag("-Werror -Wextra -Wall -mcx16" SNMALLOC_COMPILER_SUPPORT_MCX16) +if(SNMALLOC_COMPILER_SUPPORT_MCX16) + target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) +endif() # Have to set this globally, as can't be set on an interface target. if(SNMALLOC_USE_CXX20)