提取码:6666
这个工具起初是之前外出时部署程序出现问题 在客户那边机器又不好搭建复杂的环境,所制作的一套绿色的便携编译器。
支持原始的cl nmake和cmake编译。例子参考ZProject里面
精简优化了一下脚本。如有需要如下可以自己做点调整。
:CMDMAIN
REG ADD "HKEY_CURRENT_USER\CONSOLE" /V "WindowAlpha" /T REG_DWORD /D 217 /F
@ECHO OFF&CLS
SET DRIVER=%~D0
SET WORKDIR=%~DP0
SET SYSDIR=%SYSTEMROOT%\SYSTEM32;%SYSTEMROOT%
IF /I "%1"=="BUILDWORK" (CALL:PROBUILDWORK)
IF /I "%1"=="BUILDONLY" (CALL:PROBUILDONLY)
IF /I "%1"=="RUN" (CALL:PRORUN)
IF /I "%1"=="PACK" (CALL:PROPACK)
IF /I "%1"=="CLEAN" (CALL:PROCLEAN)
IF /I "%1"=="LINK" (CALL:FUN_LINK %WORKDIR% VC VC.BAT)
IF /I "%1"=="CMAKE" (CALL:FUN_CMAKE %2)
IF /I "%1"=="X86" (CALL:FUN_CLRUN X86)
IF /I "%1"=="X64" (CALL:FUN_CLRUN X64)
IF /I "%1"=="X86_AMD64" (CALL:FUN_CLRUN X86)
IF /I "%1"=="SETPATH" (CALL:FUN_MSVCNUM %2 %3)
IF /I "%1"=="HELP" (CALL:HELP)
IF /I "%1"=="" (CALL:FUN_MSVCNUM 17 X64 SHELL)
IF /I "%2"=="" (CALL:FUN_MSVCNUM %1 X64) ELSE (CALL:FUN_MSVCNUM %1 %2)
::CALL:HELP
GOTO EOF
:HELP
CLS
ECHO 输入如下命令选择编译器版本:
ECHO TO VC6(无64BIT) INPUT: [VC 6]
ECHO TO VC7(无64BIT) INPUT: [VC 7]
ECHO TO VC2005 INPUT: [VC 8]
ECHO TO VC2008 INPUT: [VC 9]
ECHO TO VC2010 INPUT: [VC 10]
ECHO TO VC2012 INPUT: [VC 11]
ECHO TO VC2013 INPUT: [VC 12]
ECHO TO VC2015 INPUT: [VC 14]
ECHO TO VC2017 INPUT: [VC 15]
ECHO TO VC2019 INPUT: [VC 16]
ECHO TO VC2022 INPUT: [VC 17]
ECHO TO MSYS64 INPUT: [VC MSYS]
ECHO 进入VC2022 INPUT: [VC 17][VC 17 X64][VC 17 X86_AMD64]
ECHO 帮助 INPUT: [VC HELP]
GOTO EOF
:FUN_MSVCNUM
::CALL:FUN_MSVCNUM 16 X64 SHELL
IF %1==6 CALL:FUN_MSVCVER %2 6 VC6 V5.0 V60 60 5.0 %3
IF %1==7 CALL:FUN_MSVCVER %2 7 VC7 V5.0 V70 70 5.0 %3
IF %1==8 CALL:FUN_MSVCVER %2 2005 VC8 V6.0A V80 80 6.0 %3
IF %1==9 CALL:FUN_MSVCVER %2 2008 VC9 V7.1A V90 90 7.1 %3
IF %1==10 CALL:FUN_MSVCVER %2 2010 VC10 V7.1A V10 100 7.1 %3
IF %1==11 CALL:FUN_MSVCVER %2 2012 VC11 V8.0A V11 110 8.0 %3
IF %1==12 CALL:FUN_MSVCVER %2 2013 VC12 V8.1A V12 120 8.1 %3
IF %1==14 CALL:FUN_MSVCVER %2 2015 VC14 V10.0A V140 140 10.0.17763.0 %3
IF %1==15 CALL:FUN_MSVCVER %2 2017 VC15 V10.0A V150 150 10.0.17763.0 %3
IF %1==16 CALL:FUN_MSVCVER %2 2019 VC16 V10.1A V160 160 10.0.18362.0 %3
IF %1==17 CALL:FUN_MSVCVER %2 2022 VC17 V10.1A V170 170 10.0.18362.0 %3
IF %1==13 CALL:HELP
GOTO EOF
:FUN_MSVCVER
SET PLATFORM=%1
SET VSNUMID=%2
SET VCNUM=%3
SET DDKNUM=%4
SET VSID=%5
SET VCID=%6
SET DDKID=%7
SET LOOP=%8
IF /I "%PLATFORM%"=="X86" COLOR 0A
IF /I "%PLATFORM%"=="X64" COLOR 5F
IF /I "%PLATFORM%"=="X86_AMD64" COLOR 8F
IF /I "%PLATFORM%"=="ARM" COLOR 1F
IF %VSNUMID%==6 (COLOR 1F&SET PLATFORM=X86)
IF %VSNUMID%==7 (COLOR 1F&SET PLATFORM=X86)
CLS&TITLE AGAN NATIVE C++ VC%VSNUMID% %PLATFORM% TOOLS!
::CLPLATFORM X86_AMD64
SET MSDIR=%WORKDIR%MSBUILD
SET WDKDIR=%MSDIR%\WINDOWSKITS
SET WDKDIRNUM=%WDKDIR%\%DDKNUM%
SET WDKINC=%WDKDIRNUM%\INCLUDE;%WDKDIR%\AGAN
SET WDKLIB=%WDKDIRNUM%\LIB\%PLATFORM%
SET WDKEXE=%WDKDIRNUM%\BIN\%PLATFORM%
SET VCREDIST=%WDKDIR%\VCREDIST
SET VCRUNEXE=%VCREDIST%\%VCNUM%\%PLATFORM%
SET VCDIR=%WORKDIR%VC%VSNUMID%
SET VCBIN=%VCDIR%\BIN;%VCDIR%\BIN\%PLATFORM%
SET VCINC=%VCDIR%\CRT\INCLUDE;%VCDIR%\ATLMFC\INCLUDE
SET VCLIB=%VCDIR%\CRT\LIB\%PLATFORM%;%VCDIR%\ATLMFC\LIB\%PLATFORM%
SET DXSDK_DIR=%WDKDIR%\D3D
SET INC3RD=%DXSDK_DIR%\INCLUDE
SET LIB3RD=%DXSDK_DIR%\LIB\%PLATFORM%
SET BIN3RD=%DXSDK_DIR%\BIN\%PLATFORM%
SET EXEDIR=%MSDIR%\BIN
SET RUNDIR=%WORKDIR%;%MSDIR%;%WDKDIR%;%VCRUNEXE%;%WDKEXE%;%VCBIN%;%EXEDIR%;
::$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
CALL:FUN_MSVCEXPCL3RD
CALL:FUN_MSVCEXLIB3RD
IF EXIST "%MSDIR%\SHARE\RUBY" (CALL:FUN_MSVCEX3RDSELFSHELL) ELSE (CALL:FUN_MSVCEX3RDSHELL)
::$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
SET BIN3RD=%BIN3RD%
SET PATH=%RUNDIR%;%SYSDIR%;%BIN3RD%;
SET INCLUDE=%VCINC%;%WDKINC%;%INC3RD%;
SET LIB=%VCLIB%;%WDKLIB%;%LIB3RD%;
SET LIBPATH=%LIB%
::$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
IF /I "%8"=="SHELL" (CLS&%COMSPEC% /K) ELSE (GOTO EOF)
GOTO EOF
:FUN_MSVCEX3RDSELFSHELL
SET SHELLSELFDIR=%MSDIR%\SHARE\
SET BIN3RD=%BIN3RD%;%SHELLSELFDIR%PYTHON27\
SET BIN3RD=%BIN3RD%;%SHELLSELFDIR%PERL\BIN
SET BIN3RD=%BIN3RD%;%SHELLSELFDIR%RUBY\BIN
GOTO EOF
:FUN_MSVCEX3RDSHELL
SET SHELLDIR=%DRIVER%\DEVELOP\SHELL\
IF NOT EXIST %SHELLDIR% (GOTO EOF)
SET JAVA_HOME=%SHELLDIR%JDK\%PLATFORM%
SET CLASSPATH=%JAVA_HOME%\LIB;%JAVA_HOME%\LIB\DT.JAR;%JAVA_HOME%\LIB\TOOLS.JAR;
SET BIN3RD=%BIN3RD%;%JAVA_HOME%\BIN;%JAVA_HOME%\JRE\BIN
%SYSTEMROOT%\REGEDIT.EXE /S %SHELLDIR%JDK\%PLATFORM%\JAVA.REG
SET BIN3RD=%BIN3RD%;%SHELLDIR%PYTHON36
SET BIN3RD=%BIN3RD%;%SHELLDIR%PERL\%PLATFORM%\BIN
SET BIN3RD=%BIN3RD%;%SHELLDIR%RUBY\%PLATFORM%\BIN
GOTO EOF
:FUN_MSVCEXPCL3RD
CD /D %WORKDIR%
FOR /F "DELIMS=" %%K IN ('DIR /A:D /B MSBUILD\*') DO (
IF /I "%%K"=="WINDOWSKITS" (ECHO OFF) ELSE (
IF /I "%%K"=="SHARE" (ECHO OFF) ELSE (
IF /I "%%K"=="BIN" (ECHO OFF) ELSE (
ECHO %%K|FINDSTR /B /I "0">NUL && (CALL:EOF) || (CALL:FUN_MSVCSET3RD MSBUILD %%K) ))))
GOTO EOF
:FUN_MSVCEXLIB3RD
::CALL:FUN_MSVCEXLIB3RD LIBRARY %%K %VCNUM%
CD /D %WORKDIR%
FOR /F "DELIMS=" %%K IN ('DIR /A:D /B LIBRARY\*') DO (
ECHO %%K|FINDSTR /B /I "0">NUL && (CALL:EOF) || (
ECHO %%K|FINDSTR /B /I "LIB">NUL && (CALL:FUN_MSVCSET3RD LIBRARY %%K) || (CALL:FUN_MSVCSET3RD LIBRARY %%K %VCNUM%) ))
GOTO EOF
:FUN_MSVCSET3RD
SET LIBDIR=%WORKDIR%%1
IF EXIST "%LIBDIR%\%2\VERSION.BAT" (CALL "%LIBDIR%\%2\VERSION.BAT") ELSE (SET LIBVERSION=)
SET PATH3RD=%LIBDIR%\%2%LIBVERSION%
SET TMPINC=%PATH3RD%\INCLUDE
SET TMPEXE=%PATH3RD%;%PATH3RD%\%3%PLATFORM%
SET TMPLIB=%PATH3RD%\%3%PLATFORM%
SET INC3RD=%INC3RD%;%TMPINC%
SET BIN3RD=%BIN3RD%;%TMPEXE%
SET LIB3RD=%LIB3RD%;%TMPLIB%
GOTO EOF
:FUN_CLRUN
::CALL:FUN_CLRUN X86 SHELL
SET PLATFORM=%1
IF /I "%PLATFORM%"=="X86" (COLOR 0A) ELSE (COLOR 5F)
TITLE VC2019_16.6 FOR %PLATFORM%
SET VCDIR=%WORKDIR%VC2019
SET LIBNOTE=%WORKDIR%LIBRARY
SET VCBIN=%WORKDIR%;%VCDIR%\BIN;%VCDIR%\%PLATFORM%
SET VCINC=%VCDIR%\INCLUDE\CRT;%VCDIR%\INCLUDE\ATLMFC;%VCDIR%\INCLUDE\WDK;%VCDIR%\INCLUDE\AGAN;%VCDIR%\INCLUDE
SET VCLIB=%VCDIR%\%PLATFORM%\CRT;%VCDIR%\%PLATFORM%\ATLMFC;%VCDIR%\%PLATFORM%\WDK;%VCDIR%\%PLATFORM%
::$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
SET INC3RD=%LIBNOTE%\OPENCV3\INCLUDE\;%LIBNOTE%\FFMPEG\INCLUDE;%LIBNOTE%\LIVE555\INCLUDE
SET LIB3RD=%LIBNOTE%\OPENCV3\VC16%PLATFORM%;%LIBNOTE%\FFMPEG\VC16%PLATFORM%;%LIBNOTE%\LIVE555\VC16%PLATFORM%
SET INC3RD=%INC3RD%;%LIBNOTE%\QT4\INCLUDE;
SET LIB3RD=%LIB3RD%;%LIBNOTE%\QT4\VC16%PLATFORM%;
::$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
SET PATH=%VCBIN%;%SYSDIR%;%LIB3RD%
SET INCLUDE=%VCINC%;%INC3RD%
SET LIB=%VCLIB%;%LIB3RD%
SET LIBPATH=%LIB%
::$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
IF /I "%2"=="SHELL" (CLS&%COMSPEC% /K) ELSE (GOTO EOF)
GOTO EOF
:FUN_LINK
::CALL:FUN_LINK C:\WINDOWS\ DESKTOP EXPLORER.EXE
SET EXEPATH=%1
SET LNKNAME=%2
IF "%3"=="" (SET RUNNAME=%2.EXE) ELSE (SET RUNNAME=%3)
IF NOT EXIST ""%EXEPATH%\%RUNNAME%"" GOTO EOF
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\%LNKNAME%.lnk""):b.TargetPath=""%EXEPATH%\%RUNNAME%"":b.WorkingDirectory=""%EXEPATH%"":b.Save:close")
REG ADD "HKEY_CURRENT_USER\CONSOLE" /V "WINDOWSIZE" /T REG_DWORD /D 2621525 /F
GOTO EOF
:FUN_KILLALL
::CALL:FUN_KILLALL EXEPLORER.EXE
IF "%1"=="" (GOTO EOF) ELSE (TASKKILL /F /IM %1)
GOTO EOF
:FUN_AUTOEXERUN
::CALL:FUN_AUTOEXERUN C:\WINDOWS\EXPLORER.EXE DESKTOP
SET PATHNAME=%1
SET SHOWNAME=%2
REG ADD HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN /V %SHOWNAME% /T REG_SZ /D "%PATHNAME%"
::REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN /V %SHOWNAME% /T REG_SZ /D "%PATHNAME%"
GOTO EOF
:FUN_READROWTXT
::CALL:FUN_READROWTXT 35 CMAKELIST.TXT
FOR /F "SKIP=%1 TOKENS=* DELIMS=" %%I IN ('FIND /V "" %2') DO (
SET EXENAME=%%I
GOTO EOF)
:FUN_CMAKE
::CALL:FUN_CMAKE 30
CALL:PROCLEAN
FOR /F "SKIP=%1 DELIMS=" %%A IN ('TYPE %SELF%') DO (
IF "%%A"=="CMAKETXTEND" (GOTO EOF) ELSE (ECHO %%A>>%WDIR%CMAKELISTS.TXT) )
GOTO EOF
:FUN_QTMOC
RD /S /Q %WDIR%MOC&MKDIR %WDIR%MOC
FOR /F "TOKENS=1,2 DELIMS=" %%i IN ('DIR /B /S %WDIR%%1\*.cpp') DO (moc.exe %%i -o %WDIR%moc\%%~ni.moc)
FOR /F "TOKENS=1,2 DELIMS=" %%i IN ('DIR /B /S %WDIR%%1\*.qrc') DO (rcc.exe %%i -o %WDIR%moc\qrc_%%~ni.cpp)
FOR /F "TOKENS=1,2 DELIMS=" %%i IN ('DIR /B /S %WDIR%%1\*.h') DO (moc.exe %%i -o %WDIR%moc\moc_%%~ni.cpp)
FOR /F "TOKENS=1,2 DELIMS=" %%i IN ('DIR /B /S %WDIR%%1\*.ui') DO (uic.exe %%i -o %WDIR%moc\ui_%%~ni.h)
GOTO EOF
:FUN_MUTIMAKE
::CALL:FUN_MUTIMAKE 8 30
CALL:FUN_CMAKE %2
IF /I %QTBUILD%==1 (CALL:FUN_QTMOC %WORKDOC%)
MD %WDIR%TMP&CD /D %WDIR%TMP
IF /I %1==1 (
CMAKE -G "NMake Makefiles" %WDIR% -DCMAKE_BUILD_TYPE:STRING=release
NMAKE
) ELSE (
CMAKE -G "NMake Makefiles JOM" %WDIR%
JOM -j %1)
CD /D %WDIR%
IF EXIST "%WDIR%CBIN\%EXENAME%.%EXTYPE%" (
SIGNFLAG.EXE %WDIR%CBIN\%EXENAME%.%EXTYPE%
MOVE %WDIR%CBIN\%EXENAME%.%EXTYPE% %WDIR%CBIN\%RUNEXE%
IF /I %BUG%==0 (CALL:PROCLEAN)
CALL:PRORUN
) ELSE (PAUSE)
GOTO EOF
:FUN_REMUTIMAKE
::CALL:FUN_REMUTIMAKE CORENUM //IF CORENUM=1 TO NMAKE
IF /I %QTBUILD%==1 (CALL:FUN_QTMOC %WORKDOC%)
CD /D %WDIR%TMP
IF /I %1==1 (NMAKE) ELSE (JOM -j %1)
CD /D %WDIR%
IF EXIST "%WDIR%CBIN\%EXENAME%.%EXTYPE%" (
MOVE %WDIR%CBIN\%EXENAME%.%EXTYPE% %WDIR%CBIN\%RUNEXE%
CALL:PRORUN
) ELSE (PAUSE)
GOTO EOF
:FUN_GETTIME
::CALL:FUN_GETTIME SDATE
IF /I "%1" =="SDATE" (SET YTIME=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%) ELSE (
SET YTIME=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%%TIME:~9,2%)
SET "YTIME=%YTIME: =0%"
::ECHO %YTIME%
GOTO EOF
:FUN_DESKTOPPATH
FOR /F "TOKENS=3,*" %%I IN ('REG QUERY "HKCU\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\EXPLORER\SHELL FOLDERS" /V "DESKTOP"'
) DO (SET DESKTOPPATH=%%I)
::ECHO %DESKTOPPATH%
GOTO EOF
:PROBUILDWORK
::SET SELF=%0 //BAT FILE
::SET EXTYPE=EXE //EX NAME
::SET PLATFORM=X86 //PLATFORM
::SET CORENUM=2 //BUILD CORENUM
::SET WORKDOC=SRC //SRC
::SET QTBUILD=0 //QT ABOUT
::SET CMAKEROWNUM=30 //CMAKE BEGIN ROW
::SET EXENAMEROWNUM=35 //CMAKE NAME ROW
::SET EX3RDPATH=C:\CUDA //EX3RDPATH
CALL:FUN_READROWTXT %EXENAMEROWNUM% %SELF%
SET RUNEXE=%EXENAME%_%CCNUM%%PLATFORM%.%EXTYPE%
CALL:FUN_MSVCNUM %CCNUM% %PLATFORM%&COLOR E0
IF NOT EXIST "%WDIR%CBIN\%RUNEXE%" (CALL:FUN_MUTIMAKE %CORENUM% %CMAKEROWNUM%) ELSE (
IF EXIST "%WDIR%TMP\MAKEFILE" (CALL:FUN_REMUTIMAKE %CORENUM%) ELSE (CALL:PRORUN))
GOTO EOF
:PROBUILDONLY
CALL:FUN_READROWTXT %EXENAMEROWNUM% %SELF%
SET RUNEXE=%EXENAME%_%CCNUM%%PLATFORM%.%EXTYPE%
CALL:FUN_MSVCNUM %CCNUM% %PLATFORM%&COLOR E0
IF NOT EXIST "%WDIR%CBIN\%RUNEXE%" (CALL:FUN_MUTIMAKE %CORENUM% %CMAKEROWNUM%) ELSE (
IF EXIST "%WDIR%TMP\MAKEFILE" (CALL:FUN_REMUTIMAKE %CORENUM%))
GOTO EOF
:PROCLEAN
RD /S /Q %WDIR%TMP %WDIR%MOC
DEL /F /Q %WDIR%CMAKELISTS.TXT
DEL /F /S /Q %WDIR%*.MANIFEST
GOTO EOF
:PRORUN
SET PATH=%PATH%;%EX3RDPATH%
CD /D %WDIR%CBIN
IF /I "%EXTYPE%"=="EXE" (START %WDIR%CBIN\%RUNEXE%) ELSE (ECHO "MAKE IS SUCCESS!")
GOTO EOF
:PROPACK
CALL:FUN_GETTIME SDATE
@7Z A -T7Z -SFX ../QUICKCPP_%YTIME%.EXE ../QUICKCPP -PHAMIGUA -MX=9 -MS=200M -MF -MHC -MHCF -MMT -XR!WORK -XR!ZPROJECT
GOTO EOF
:END
EXIT
:EOF
end
|