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)