Detect version of MSVC in GYP

I am trying to detect a version of msvc during node-gyp configurein my binding.gyp file. Basically, I want to be able to link to a specific 3rdparty library based on the Visual C ++ version:

['OS=="win"' and 'toolset="vc12"' , {
    'libraries': [
        "opencv/lib/vc12/opencv_world300.lib"
    ],
}],

['OS=="win"' and 'toolset="vc11"' , {
    'libraries': [
        "opencv/lib/vc11/opencv_world300.lib"
    ],
}],

['OS=="win"' and 'toolset="vc10"' , {
    'libraries': [
        "opencv/lib/vc10/opencv_world300.lib"
    ],
}]

Unfortunately, neither variables toolsetnor _toolsetnor are $(TOOLSET)they defined in GYP. I could not find such a variable in the GYP documentation. Is it possible at all?

+4
source share
1 answer

, , : https://chromium.googlesource.com/external/gyp/+/master/docs/UserDocumentation.md#Skeleton-of-a-typical-executable-target-in-a-gyp-file.

@saper GitHub , MSVS_VERSION :

['OS=="win"' and 'MSVS_VERSION=="2013"' , {
    'libraries': [
        "opencv/lib/vc12/opencv_world300.lib"
    ],
}],

['OS=="win"' and 'MSVS_VERSION=="2012"' , {
    'libraries': [
        "opencv/lib/vc11/opencv_world300.lib"
    ],
}],

['OS=="win"' and 'MSVS_VERSION=="2010"' , {
    'libraries': [
        "opencv/lib/vc10/opencv_world300.lib"
    ],
}]

(nit: , toolset gyp, = ==)

: https://github.com/saper/node-sass/blob/c7e9cf0f0e0098e8316bd41722fc2edf4a835d9f/src/libsass.gyp#L91-L94.

1:

, .targets .vcxproj (, this), .vcxproj - , MSVS, , , .vcxproj / .

MSVS gyp , , :

CMD:

SET GYP_MSVS_VERSION=2012

PowerShell:

$env:GYP_MSVS_VERSION=2015

:

node_modules/.bin/node-gyp build --msvs_version=2012

env-var , CLI arg .

CLI npm, , Windows MSVCR .

..

2:

CLI MSVS : --min-msvs-version.

3:

MSBUILD node -gyp MSBUILD ( ) / .vcxproj, PATH. , , C99/++ 1 [1/4/7], VS2015. :

  • reset PATH MSBuild bin.
  • node-gyp build rebuild node-gyp configure, "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild" build/binding.sln /p:Configuration=Release ( posh, : &"${env:ProgramFiles(x86)}\MSBuild\14.0\Bin\MSBuild" build\binding.sln /p:Configuration=Release)
  • Pull node -gyp pangyp, MSBUILD, , Windows , .:)
+5

All Articles