cmake 学习之路 记录中间所遇到过的所有错误与问题的解决

CMAKE_BUILD_TYPE  宏匹配问题:


错误代码:

    # Linux operation system
    IF (CMAKE_BUILD_TYPE MATCHES "Debug" 
            OR CMAKE_BUILD_TYPE MATCHES "None"
            OR CMAKE_BUILD_TYPE MATCHES "")
        ADD_DEFINITIONS(-D _DEBUG_CDB)
        ADD_DEFINITIONS(-D DEBUG)
    ELSEIF (CMAKE_BUILD_TYPE MATCHES "Release")
    ELSEIF (CMAKE_BUILD_TYPE MATCHES "RelWitchDebInfo")
    ELSEIF (CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
    ELSE ()
        MESSAGE(FATAL_ERROR "unknown CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE},"
                " CMAKE_BUILD_TYPE: Debug or None, Release, RelWitchDebInfo,"
                " RelWitchDebInfo")
    ENDIF ()

正确代码:

    # Linux operation system
    IF (CMAKE_BUILD_TYPE MATCHES "Debug" 
            OR CMAKE_BUILD_TYPE MATCHES "None")
        ADD_DEFINITIONS(-D _DEBUG_CDB)
        ADD_DEFINITIONS(-D DEBUG)
    ELSEIF (CMAKE_BUILD_TYPE MATCHES "Release")
    ELSEIF (CMAKE_BUILD_TYPE MATCHES "RelWitchDebInfo")
    ELSEIF (CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
    ELSE ()
        MESSAGE(FATAL_ERROR "unknown CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE},"
                " CMAKE_BUILD_TYPE: Debug or None, Release, RelWitchDebInfo,"
                " RelWitchDebInfo")
    ENDIF ()

如果你够仔细的话应该不难发现两者的差别仅仅是一行  CMAKE_BUILD_TYPE MATCHES "" 而以,我用的时候以为这个是匹配未定义呢,结果不是。未定义的时候该值为"None"   如果只给一个"" 那么它会匹配所有




你可能感兴趣的:(cmake)