vcbuild.bat 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. @echo off
  2. cd %~dp0
  3. if /i "%1"=="help" goto help
  4. if /i "%1"=="--help" goto help
  5. if /i "%1"=="-help" goto help
  6. if /i "%1"=="/help" goto help
  7. if /i "%1"=="?" goto help
  8. if /i "%1"=="-?" goto help
  9. if /i "%1"=="--?" goto help
  10. if /i "%1"=="/?" goto help
  11. @rem Process arguments.
  12. set config=
  13. set target=Build
  14. set noprojgen=
  15. set nobuild=
  16. set run=
  17. set target_arch=ia32
  18. set vs_toolset=x86
  19. set platform=WIN32
  20. set library=static_library
  21. :next-arg
  22. if "%1"=="" goto args-done
  23. if /i "%1"=="debug" set config=Debug&goto arg-ok
  24. if /i "%1"=="release" set config=Release&goto arg-ok
  25. if /i "%1"=="test" set run=run-tests.exe&goto arg-ok
  26. if /i "%1"=="bench" set run=run-benchmarks.exe&goto arg-ok
  27. if /i "%1"=="clean" set target=Clean&goto arg-ok
  28. if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok
  29. if /i "%1"=="nobuild" set nobuild=1&goto arg-ok
  30. if /i "%1"=="x86" set target_arch=ia32&set platform=WIN32&set vs_toolset=x86&goto arg-ok
  31. if /i "%1"=="ia32" set target_arch=ia32&set platform=WIN32&set vs_toolset=x86&goto arg-ok
  32. if /i "%1"=="x64" set target_arch=x64&set platform=amd64&set vs_toolset=x64&goto arg-ok
  33. if /i "%1"=="shared" set library=shared_library&goto arg-ok
  34. if /i "%1"=="static" set library=static_library&goto arg-ok
  35. :arg-ok
  36. shift
  37. goto next-arg
  38. :args-done
  39. @rem Look for Visual Studio 2013
  40. if not defined VS120COMNTOOLS goto vc-set-2012
  41. if not exist "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2012
  42. call "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset%
  43. set GYP_MSVS_VERSION=2013
  44. goto select-target
  45. @rem Look for Visual Studio 2012
  46. :vc-set-2012
  47. if not defined VS110COMNTOOLS goto vc-set-2010
  48. if not exist "%VS110COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2010
  49. call "%VS110COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset%
  50. set GYP_MSVS_VERSION=2012
  51. goto select-target
  52. :vc-set-2010
  53. @rem Look for Visual Studio 2010
  54. if not defined VS100COMNTOOLS goto vc-set-2008
  55. if not exist "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2008
  56. call "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset%
  57. set GYP_MSVS_VERSION=2010
  58. goto select-target
  59. :vc-set-2008
  60. @rem Look for Visual Studio 2008
  61. if not defined VS90COMNTOOLS goto vc-set-notfound
  62. if not exist "%VS90COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-notfound
  63. call "%VS90COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset%
  64. set GYP_MSVS_VERSION=2008
  65. goto select-target
  66. :vc-set-notfound
  67. echo Warning: Visual Studio not found
  68. :select-target
  69. if not "%config%"=="" goto project-gen
  70. if "%run%"=="run-tests.exe" set config=Debug& goto project-gen
  71. if "%run%"=="run-benchmarks.exe" set config=Release& goto project-gen
  72. set config=Debug
  73. :project-gen
  74. @rem Skip project generation if requested.
  75. if defined noprojgen goto msbuild
  76. @rem Generate the VS project.
  77. if exist build\gyp goto have_gyp
  78. echo git clone https://git.chromium.org/external/gyp.git build/gyp
  79. git clone https://git.chromium.org/external/gyp.git build/gyp
  80. if errorlevel 1 goto gyp_install_failed
  81. goto have_gyp
  82. :gyp_install_failed
  83. echo Failed to download gyp. Make sure you have git installed, or
  84. echo manually install gyp into %~dp0build\gyp.
  85. exit /b 1
  86. :have_gyp
  87. if not defined PYTHON set PYTHON="python"
  88. %PYTHON% gyp_uv.py -Dtarget_arch=%target_arch% -Dlibrary=%library%
  89. if errorlevel 1 goto create-msvs-files-failed
  90. if not exist uv.sln goto create-msvs-files-failed
  91. echo Project files generated.
  92. :msbuild
  93. @rem Skip project generation if requested.
  94. if defined nobuild goto run
  95. @rem Check if VS build env is available
  96. if not defined VCINSTALLDIR goto msbuild-not-found
  97. goto msbuild-found
  98. :msbuild-not-found
  99. echo Build skipped. To build, this file needs to run from VS cmd prompt.
  100. goto run
  101. @rem Build the sln with msbuild.
  102. :msbuild-found
  103. msbuild uv.sln /t:%target% /p:Configuration=%config% /p:Platform="%platform%" /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
  104. if errorlevel 1 exit /b 1
  105. :run
  106. @rem Run tests if requested.
  107. if "%run%"=="" goto exit
  108. if not exist %config%\%run% goto exit
  109. echo running '%config%\%run%'
  110. %config%\%run%
  111. goto exit
  112. :create-msvs-files-failed
  113. echo Failed to create vc project files.
  114. exit /b 1
  115. :help
  116. echo vcbuild.bat [debug/release] [test/bench] [clean] [noprojgen] [nobuild] [x86/x64] [static/shared]
  117. echo Examples:
  118. echo vcbuild.bat : builds debug build
  119. echo vcbuild.bat test : builds debug build and runs tests
  120. echo vcbuild.bat release bench: builds release build and runs benchmarks
  121. goto exit
  122. :exit