How to detect if 64 bit MSVC with cmake?

后端 未结 7 1633
既然无缘
既然无缘 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:11

    On recent versions of CMake/Visual Studio the bitness is selected with CMAKE_GENERATOR_PLATFORM, which can be specified on the command line with -A option:

    cmake -G "Visual Studio 16 2019" -A Win32 -DCMAKE_BUILD_TYPE=Release ..
    

    So, based on this feature you can then query the value from within the CMakeLists.txt:

    if(NOT ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win64"))
        ...
    ENDIF()
    

提交回复
热议问题