CMake STREQUAL在不应该返回false时返回false

时间:2015-07-16 14:54:01

标签: cmake

我正在尝试将CMAKE_CXX_COMPILER_ID与预期ID进行比较以设置标志等,但cmake正在给出一些非常奇怪的行为。我想这样做:

message("Compiler ID: '${CMAKE_CXX_COMPILER_ID}'")
if ("${CMAKE_CXX_COMIPLER_ID}" STREQUAL "GNU")
    message("Using GNU")
    set(warnings "-Wall")
    set(options "-std=c++11")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    set(warnings "/W4 /XW /EHsc")
else ()
    message("wtf")
endif()

我得到了输出:

-- The C compiler identification is GNU 5.1.0
-- The CXX compiler identification is GNU 5.1.0
-- Check for working C compiler: /usr/sbin/cc
-- Check for working C compiler: /usr/sbin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/sbin/c++
-- Check for working CXX compiler: /usr/sbin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Compiler ID: 'GNU'
wtf

显然编译器id是“GNU”,但是带有“GNU”的STREQUAL是错误的。类似的问题涉及过时的缓存,但我已经清除它,所以我不认为这是我的问题。有任何想法吗?感谢。

1 个答案:

答案 0 :(得分:2)

有一个拼写错误:

if ("${CMAKE_CXX_COMIPLER_ID}" STREQUAL "GNU")

应该是

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")