Search code examples
visual-studio-2013cmakewindows-xpnmake

how to set v120xp in cmake with vs2013's NMake


I'm using win7-32bit + cmake + vs2013's NMake.exe to build exe, I need the exe be able to run on WinXP, I know how to do that with vs2013 IDE(set the Platform-Toolset to v120xp), but I'm not using the IDE, I just use its NMake. This is how I generate the project file and exe:

build> cmake -G "NMake Makefiles" ..
build> nmake

Question 1: In the CMakeLists.txt, how to set it use v120xp?

Question 2: Is it necessary to build all static lib with the v120xp? Or just the exe?


Solution

  • Try setting CMAKE_GENERATOR_TOOLSET. It allows selecting the toolset for Genertors that support it. Generators that support Toolsets are Visual Studio and XCode.

    Your call to CMake should look like this:

    cmake -G "NMake Makefiles" -DCMAKE_GENERATOR_TOOLSET=v120_xp ..
    

    Update 1: As pointed out in the comments NMake doesn't support Toolsets

    Thes solution is to specify

    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE,5.01")
    

    for console applications, or

    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01")
    

    for windows applications.