Search code examples
cmakenmake

CMake NMake generator not generating ${PlatformToolset} variable


I have a find_package script that uses ${PlatformToolset} and ${Platform} to find the correct directories. However, when using the nmake generator, it seems these are not set. Am I correct in thinking that these variables are not set, or am I doing something wrong? Is there a replacement for these variables?


Solution

  • NMake sets MSVC_VERSION and other MSVC variables, so Platformtoolset and Platform can be derived from that:

    if(MSVC_VERSION GREATER 1900)
        set(PlatformToolSet v141)
    else()
        set(PlatformToolSet v140)
    endif()
    
    if(CMAKE_SIZEOF_VOID_P GREATER 4)
      set(Platform x64)
    else()
      set(Platform Win32)
    endif()