How to detect if 64 bit MSVC with cmake?

后端 未结 7 1647
既然无缘
既然无缘 2020-12-09 08:42

I have a project which uses cmake, one target is set to only build with MSVC:

 if (MSVC)
     add_library(test SHARED source.cpp) 
 endif()

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-09 09:10

    There are several ways - also used by CMake itself - that will check for "not 64Bit":

    if(NOT "${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
        ...
    endif()
    
    if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
        ...
    endif()
    
    if(NOT CMAKE_CL_64)
       ...
    endif()
    

    References

    • CMAKE_GENERATOR
    • CMAKE_SIZEOF_VOID_P
    • CMAKE_CL_64

提交回复
热议问题