From 3daf4ee2906583dfc86e4f6986b40f843e7e3a3c Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 15 Apr 2023 00:25:50 -0700 Subject: [PATCH] quote CPUINFO in cmake (#983) Without these quotes, cmake fails in a confusing manner on systems whose cpuinfo output includes spaces. This arose in the context of attempting to compile natively on an m1 mac. $ /usr/sbin/sysctl -n machdep.cpu.features machdep.cpu.leaf7_features sysctl: unknown oid 'machdep.cpu.leaf7_features' Obviously, this didn't work out well; there is still much more to do. Still, the quotes are cheap and eliminate a confusing failure mode. For this reason, I added them to the linux as well as the darwin path. --- cmake/FindSSE.cmake | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cmake/FindSSE.cmake b/cmake/FindSSE.cmake index e1c58fbc9..0f1483487 100644 --- a/cmake/FindSSE.cmake +++ b/cmake/FindSSE.cmake @@ -4,7 +4,7 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") EXEC_PROGRAM(cat ARGS "/proc/cpuinfo" OUTPUT_VARIABLE CPUINFO) - STRING(REGEX REPLACE "^.*(sse2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(sse2).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "sse2" "${SSE_THERE}" SSE2_TRUE) IF (SSE2_TRUE) set(SSE2_FOUND true CACHE BOOL "SSE2 available on host") @@ -13,14 +13,14 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") ENDIF (SSE2_TRUE) # /proc/cpuinfo apparently omits sse3 :( - STRING(REGEX REPLACE "^.*[^s](sse3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*[^s](sse3).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "sse3" "${SSE_THERE}" SSE3_TRUE) IF (NOT SSE3_TRUE) - STRING(REGEX REPLACE "^.*(T2300).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(T2300).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "T2300" "${SSE_THERE}" SSE3_TRUE) ENDIF (NOT SSE3_TRUE) - STRING(REGEX REPLACE "^.*(ssse3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(ssse3).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "ssse3" "${SSE_THERE}" SSSE3_TRUE) IF (SSE3_TRUE OR SSSE3_TRUE) set(SSE3_FOUND true CACHE BOOL "SSE3 available on host") @@ -33,7 +33,7 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host") ENDIF (SSSE3_TRUE) - STRING(REGEX REPLACE "^.*(sse4_1).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(sse4_1).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "sse4_1" "${SSE_THERE}" SSE41_TRUE) IF (SSE41_TRUE) set(SSE4_1_FOUND true CACHE BOOL "SSE4.1 available on host") @@ -41,7 +41,7 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host") ENDIF (SSE41_TRUE) - STRING(REGEX REPLACE "^.*(sse4_2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(sse4_2).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "sse4_2" "${SSE_THERE}" SSE42_TRUE) IF (SSE42_TRUE) set(SSE4_2_FOUND true CACHE BOOL "SSE4.2 available on host") @@ -49,7 +49,7 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") set(SSE4_2_FOUND false CACHE BOOL "SSE4.2 available on host") ENDIF (SSE42_TRUE) - STRING(REGEX REPLACE "^.*(avx).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(avx).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "avx" "${SSE_THERE}" AVX_TRUE) IF (AVX_TRUE) set(AVX_FOUND true CACHE BOOL "AVX available on host") @@ -57,7 +57,7 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") set(AVX_FOUND false CACHE BOOL "AVX available on host") ENDIF (AVX_TRUE) - STRING(REGEX REPLACE "^.*(avx2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(avx2).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "avx2" "${SSE_THERE}" AVX2_TRUE) IF (AVX2_TRUE) set(AVX2_FOUND true CACHE BOOL "AVX2 available on host") @@ -65,7 +65,7 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") set(AVX2_FOUND false CACHE BOOL "AVX2 available on host") ENDIF (AVX2_TRUE) - STRING(REGEX REPLACE "^.*(avx512).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(avx512).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "avx512" "${SSE_THERE}" AVX512_TRUE) IF (AVX512_TRUE) set(AVX512_FOUND true CACHE BOOL "AVX512 available on host") @@ -76,7 +76,7 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") EXEC_PROGRAM("/usr/sbin/sysctl -n machdep.cpu.features machdep.cpu.leaf7_features" OUTPUT_VARIABLE CPUINFO) - STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "SSE2" "${SSE_THERE}" SSE2_TRUE) IF (SSE2_TRUE) set(SSE2_FOUND true CACHE BOOL "SSE2 available on host") @@ -84,7 +84,7 @@ ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") set(SSE2_FOUND false CACHE BOOL "SSE2 available on host") ENDIF (SSE2_TRUE) - STRING(REGEX REPLACE "^.*[^S](SSE3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*[^S](SSE3).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "SSE3" "${SSE_THERE}" SSE3_TRUE) IF (SSE3_TRUE) set(SSE3_FOUND true CACHE BOOL "SSE3 available on host") @@ -100,7 +100,7 @@ ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host") ENDIF (SSSE3_TRUE) - STRING(REGEX REPLACE "^.*(SSE4.1).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(SSE4.1).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "SSE4.1" "${SSE_THERE}" SSE41_TRUE) IF (SSE41_TRUE) set(SSE4_1_FOUND true CACHE BOOL "SSE4.1 available on host") @@ -108,7 +108,7 @@ ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host") ENDIF (SSE41_TRUE) - STRING(REGEX REPLACE "^.*(AVX).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(AVX).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "AVX" "${SSE_THERE}" AVX_TRUE) IF (AVX_TRUE) set(AVX_FOUND true CACHE BOOL "AVX available on host") @@ -116,7 +116,7 @@ ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") set(AVX_FOUND false CACHE BOOL "AVX available on host") ENDIF (AVX_TRUE) - STRING(REGEX REPLACE "^.*(AVX2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(AVX2).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "AVX2" "${SSE_THERE}" AVX2_TRUE) IF (AVX2_TRUE) set(AVX2_FOUND true CACHE BOOL "AVX2 available on host") @@ -124,7 +124,7 @@ ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") set(AVX2_FOUND false CACHE BOOL "AVX2 available on host") ENDIF (AVX2_TRUE) - STRING(REGEX REPLACE "^.*(avx512).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(avx512).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "avx512" "${SSE_THERE}" AVX512_TRUE) IF (AVX512_TRUE) set(AVX512_FOUND true CACHE BOOL "AVX512 available on host")