Skip to content

Instantly share code, notes, and snippets.

@urbans0ft
Last active November 18, 2024 21:52
Show Gist options
  • Select an option

  • Save urbans0ft/c5327521c7337ba57d3872837e157cc9 to your computer and use it in GitHub Desktop.

Select an option

Save urbans0ft/c5327521c7337ba57d3872837e157cc9 to your computer and use it in GitHub Desktop.
Installation by Using cmd git cmake and MinGw
REM https://docs.opencv.org/4.x/d3/d52/tutorial_windows_install.html
PUSHD "%0\.."
mkdir opencv
cd opencv
set opencv_base_path=%CD%
mkdir src
mkdir build
mkdir release
cd src
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
cd ..
cd build
set CMAKE_OPTIONS= ^
-DBUILD_opencv_world:BOOL=OFF ^
-DBUILD_SHARED_LIBS:BOOL=ON ^
-DBUILD_PERF_TESTS:BOOL=OFF ^
-DBUILD_TESTS:BOOL=OFF ^
-DBUILD_DOCS:BOOL=OFF ^
-DWITH_CUDA:BOOL=OFF ^
-DBUILD_EXAMPLES:BOOL=OFF ^
-DINSTALL_CREATE_DISTRIB=ON ^
-DEIGEN_INCLUDE_PATH:STRING=C:/Develop/lib/eigen-3.4.0 ^
-DOpenBLAS_INCLUDE_DIR:STRING=C:/Develop/lib/OpenBLAS/include ^
-DOpenBLAS_LIB:STRING=C:/Develop/lib/OpenBLAS/lib/libopenblas.lib
cmake ^
-G"MinGW Makefiles" ^
%CMAKE_OPTIONS% ^
-DOPENCV_EXTRA_MODULES_PATH=..\src\opencv_contrib\modules ^
-DCMAKE_INSTALL_PREFIX="%opencv_base_path%\release" ^
"%opencv_base_path%\src\opencv" >..\opencv_cmake.log
cmake --build . --config release
cmake --build . --target install --config release
REM -DEIGEN_INCLUDE_PATH:STRING=C:/Develop/lib/eigen-3.4.0
REM https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.zip
REM https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.28/OpenBLAS-0.3.28-x64-64.zip
REM -DEIGEN_INCLUDE_PATH:STRING=C:/Develop/lib/eigen-3.4.0
REM -DOpenBLAS_INCLUDE_DIRS:STRING=C:/Develop/lib/OpenBLAS/include
REM -DOpenBLAS_LIB:STRING=C:/Develop/lib/OpenBLAS/lib
@echo off
cls
setlocal EnableDelayedExpansion
echo.******************************************************************************
echo.* ____ _______ __ *
echo.* / __ \ / ____\ \ / / *
echo.* ^| ^| ^| ^|_ __ ___ _ __ ^| ^| \ \ / / *
echo.* ^| ^| ^| ^| '_ \ / _ \ '_ \ ^| ^| \ \/ / *
echo.* ^| ^|__^| ^| ^|_) ^| __/ ^| ^| ^| ^| ^|____ \ / *
echo.* \____/^| .__/ \___^|_^| ^|_^| \_____^| \/ *
echo.* ^| ^| *
echo.* ^|_^| *
echo.* ___ ___ *
echo.* ^| \ _____ __ ^| __^|_ ___ __ *
echo.* ^| ^|) / -_) V / ^| _^|^| ^' \ V / *
echo.* ^|___/\___^|\_/ ^|___^|_^|^|_\_/ *
echo.* *
echo.******************************************************************************
:: Needed for colored output (error, warn, info, success)
call :setESC
:: Path to download software installer to
set download_path=%USERPROFILE%\Downloads
:: Path to install missing software to
set install_path=%LOCALAPPDATA%\Programs
:: Software (command line tools) needed
set needed_software=7z;code;git;g++;cmake;python;nasm;java
echo.
echo %ESC%[93mMissing software will be downloaded and installed automatically. %ESC%[0m
echo.
echo Download Path: %ESC%[7m%download_path%%ESC%[0m
echo Install Path: %ESC%[7m%install_path%%ESC%[0m
echo Command Line Tools:
for %%a in ("%needed_software:;=" "%") do (
echo. - %ESC%[7m%%~a%ESC%[0m
)
echo.
rem set /p y_or_n=Continue with download and installation (y/[n])^?
rem if /i "%y_or_n%" neq "y" goto end
:: Iterate over needed software and download and install if missing
for %%a in ("%needed_software:;=" "%") do (
where %%~a >nul 2>&1
if !ERRORLEVEL! neq 0 (
call :warn '%%~a' is missing!
call :%%~a || (call :error '%%~a' not installed! & goto end)
call :success '%%~a' installed!
) else (
call :success '%%~a' found!
)
echo.
)
:: Start new developer command prompt
start "Developer Command Prompt" /d "%CD%" "cmd echo asdlfjasd"
:end
exit /b 0
:: -----------------------------------------------------------------------------
:: subroutines -----------------------------------------------------------------
:: -----------------------------------------------------------------------------
:setESC
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set ESC=%%b
exit /b 0
)
exit /b 0
:verbose
echo %ESC%[7m[VERB] %*%ESC%[0m
exit /b
:info
echo %ESC%[96m[INFO] %*%ESC%[0m
exit /b
:success
echo %ESC%[92m[SUCC] %*%ESC%[0m
exit /b
:warn
echo %ESC%[93m[WARN] %*%ESC%[0m
exit /b
:error
echo %ESC%[91m[ERRO] %*%ESC%[0m
exit /b
:: -----------------------------------------------------------------------------
:7z
REM curl -H "Accept: application/vnd.github+json" "https://api.github.com/repos/ip7z/7zip/releases/latest" | findstr /r "browser_download_url.*x64\.exe"
call :info Setting up 7zip
if not exist "%install_path%\7-Zip" (
for /f "tokens=2 delims= " %%i in ('curl -H "Accept: application/vnd.github+json" "https://api.github.com/repos/ip7z/7zip/releases/latest" ^| findstr /r "browser_download_url.*x64\.exe"') do (
set url=%%i
set filename=%%~nxi
)
call :info Downloading 7zip
call :download "!url!" "%download_path%\!filename!" || exit /b 1
call :info Installing 7zip
"%download_path%\!filename!" /S /D="%install_path%\7-Zip" || exit /b 1
) else (
call :info '%install_path%\7-Zip' already installed.
)
set PATH=%install_path%\7-Zip;!PATH!
exit /b 0
:: -----------------------------------------------------------------------------
:code
call :info Setting up Microsoft VS Code
if not exist "%install_path%\Microsoft VS Code" (
call :info Downloading Microsoft VS Code
call :download "https://update.code.visualstudio.com/latest/win32-x64-user/stable" "%download_path%\vscode.exe" || exit /b 1
call :info Installing Microsoft VS Code
start "" /b /wait "%download_path%\vscode.exe" /verysilent /suppressmsgboxes /dir="%install_path%\Microsoft VS Code" /MERGETASKS=^^!runcode || exit /b 1
) else (
call :info '%install_path%\Microsoft VS Code' already installed.
)
set PATH=%install_path%\Microsoft VS Code;!PATH!
exit /b 0
:: -----------------------------------------------------------------------------
:git
call :info Setting up git
if not exist "%install_path%\git" (
for /f "tokens=2 delims= " %%i in ('curl -H "Accept: application/vnd.github+json" "https://api.github.com/repos/git-for-windows/git/releases/latest" ^| findstr /r "browser_download_url.*Portable.*64-bit\.7z\.exe"') do (
set url=%%i
set filename=%%~nxi
)
call :info Downloading git
call :download "!url!" "%download_path%\!filename!" || exit /b 1
call :info Installing git
7z.exe x "%download_path%\!filename!" -o"%install_path%\git" || exit /b 1
) else (
call :info '%install_path%\git' already installed.
)
set PATH=%install_path%\git\cmd;!PATH!
REM start "" /b /wait "%install_path%\git\post-install.bat"
exit /b 0
:: -----------------------------------------------------------------------------
:g++
call :info Setting up g++
if not exist "%install_path%\mingw64" (
for /f "usebackq tokens=2 delims= " %%i in (`curl -H "Accept: application/vnd.github+json" "https://api.github.com/repos/niXman/mingw-builds-binaries/releases/latest" ^| findstr /r "browser_download_url.*x86_64.*win32.*ucrt.*"`) do (
set url=%%i
set filename=%%~nxi
)
call :info Downloading g++
call :download !url! "%download_path%\!filename!" || exit /b 1
call :info Installing g++
7z.exe x "%download_path%\!filename!" -o"%install_path%" || exit /b 1
) else (
call :info '%install_path%\mingw64' already installed.
)
set PATH=%install_path%\mingw64\bin;!PATH!
exit /b 0
:: -----------------------------------------------------------------------------
:cmake
call :info Setting up cmake
if not exist %install_path%\cmake (
for /f "tokens=2 delims= " %%i in ('curl -H "Accept: application/vnd.github+json" "https://api.github.com/repos/Kitware/CMake/releases/latest" ^| findstr /r "browser_download_url.*x86_64\.zip"') do (
set url=%%i
set filename=%%~nxi
)
call :info Downloading cmake
call :download !url! "%download_path%\!filename!" || exit /b 1
call :info Installing cmake
7z.exe x "%USERPROFILE%\Downloads\!filename!" -o"%install_path%" || exit /b 1
move %install_path%\cmake* %install_path%\cmake
) else (
call :info '%install_path%\cmake' already installed.
)
set PATH=%install_path%\cmake\bin;!PATH!
exit /b 0
:: -----------------------------------------------------------------------------
:download
if not exist "%~2" (
call :verbose Source '%1'
call :verbose Destination '%2'
curl -L "%~1" --output "%~2"
set curl_error=!ERRORLEVEL!
if !curl_error! neq 0 (
:: delete possible corrupt left-over
del "%~2" /F /Q 2>&1 >nul
)
exit /b !curl_error!
) else (
call :info '%~2' already downloaded.
exit /b 0
)
:: -----------------------------------------------------------------------------
:python
REM python-3.13.0-amd64.exe /passive TargetDir=C:\Apps\python PrependPath=1 Shortcuts=0
call :info Setting up python
call :warn Python Version is Hardcoded to Python v3.13.0
if not exist "%install_path%\python" (
set url=https://www.python.org/ftp/python/3.13.0/python-3.13.0-amd64.exe
set filename=python-3.13.0-amd64.exe
call :info Downloading python
call :download !url! "%download_path%\!filename!" || exit /b 1
call :info Installing python
"%USERPROFILE%\Downloads\!filename!" /passive TargetDir="%install_path%\python" PrependPath=1 Shortcuts=0 InstallLauncherAllUsers=0 || exit /b 1
) else (
call :info '%install_path%\python' already installed.
)
"%install_path%\python\python" -m pip install --upgrade pip
"%install_path%\python\Scripts\pip.exe" install numpy
exit /b 0
:: -----------------------------------------------------------------------------
:nasm
call :info Setting up nasm
call :warn NASM Version is Hardcoded to NASM v2.16.03
if not exist "%install_path%\nasm" (
set url=https://www.nasm.us/pub/nasm/releasebuilds/2.16.03/win64/nasm-2.16.03-win64.zip
set filename=nasm-2.16.03-win64.zip
call :info Downloading nasm
call :download !url! "%download_path%\!filename!" || exit /b 1
call :info Installing nasm
7z.exe x "%USERPROFILE%\Downloads\!filename!" -o"%install_path%" || exit /b 1
move %install_path%\nasm* %install_path%\nasm
) else (
call :info '%install_path%\nasm' already installed.
)
set PATH=%install_path%\nasm;!PATH!
exit /b 0
:: -----------------------------------------------------------------------------
:java
call :info Setting up java
call :warn java Version is Hardcoded to java jdk23.0.1
if not exist "%install_path%\jdk" (
set url=https://download.java.net/java/GA/jdk23.0.1/c28985cbf10d4e648e4004050f8781aa/11/GPL/openjdk-23.0.1_windows-x64_bin.zip
set filename=openjdk-23.0.1_windows-x64_bin.zip
call :info Downloading java
call :download !url! "%download_path%\!filename!" || exit /b 1
call :info Installing java
7z.exe x "%USERPROFILE%\Downloads\!filename!" -o"%install_path%" || exit /b 1
move %install_path%\jdk* %install_path%\jdk
) else (
call :info '%install_path%\jdk' already installed.
)
set JAVA_HOME=%install_path%\jdk
set PATH=!JAVA_HOME!\bin;!PATH!
exit /b 0
:: -----------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment