在 CMAKE 中替代 STREQUAL
Alternate for STREQUAL in CMAKE
在 CMAKE 文件中,平台架构由以下代码决定。不考虑 ARM 板(armv7l、armhf 等),我只比较前三个字母“arm”。但是 STREQUAL 会比较所有字符。那么是否有任何其他 CMAKE 函数,如 strncmp() 仅比较基于用户输入的字符或在“armv7l”中搜索“arm”?
if( ${ARCHITECTURE} STREQUAL "x86_64" )
set(arch_x86_64 ON CACHE BOOL "X86_64 Architecture")
else()
if( ${ARCHITECTURE} STREQUAL "arm")```
So is there any other CMAKE functions like strncmp() which compares only characters based on user's input or to serach "arm" in "armv7l" ?
您可以提取子串并比较:
string(SUBSTRING "${ARCHITECTURE}" 0 3 tmp)
if("${tmp}" STREQUAL "arm")
但只要使用正则表达式即可:
if("${ARCHITECTURE}" MATCHES "^arm")
在 CMAKE 文件中,平台架构由以下代码决定。不考虑 ARM 板(armv7l、armhf 等),我只比较前三个字母“arm”。但是 STREQUAL 会比较所有字符。那么是否有任何其他 CMAKE 函数,如 strncmp() 仅比较基于用户输入的字符或在“armv7l”中搜索“arm”?
if( ${ARCHITECTURE} STREQUAL "x86_64" )
set(arch_x86_64 ON CACHE BOOL "X86_64 Architecture")
else()
if( ${ARCHITECTURE} STREQUAL "arm")```
So is there any other CMAKE functions like strncmp() which compares only characters based on user's input or to serach "arm" in "armv7l" ?
您可以提取子串并比较:
string(SUBSTRING "${ARCHITECTURE}" 0 3 tmp)
if("${tmp}" STREQUAL "arm")
但只要使用正则表达式即可:
if("${ARCHITECTURE}" MATCHES "^arm")