Last active
June 16, 2025 15:01
-
-
Save zedalaye/573605edb25c8165e37794f2e99daddd to your computer and use it in GitHub Desktop.
Build script for ZeroMQ with LibSodium, CZMQ and Zyre using CMAKE and Visual Studio 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal EnableDelayedExpansion | |
@REM Build LibZMQ, CZMQ et Zyre with their dependencies | |
@REM Toolchain : Visual Studio 2022 with Windows 10 SDK | |
@REM Dependencies : GIT (Git for Windows), CMAKE | |
@REM | |
@REM After successful build the resulting DLL are moved into zmq_build_%TODAY%\out | |
@REM | |
@REM To regenerate CZMQ/Zyre bindings a Linux system is required : | |
@REM * Ubuntu : Install build-essential and libpcre3-dev | |
@REM * Install GSL | |
@REM $ git clone https://github.com/zeromq/gsl.git | |
@REM $ cd gsl/src && make && sudo make install | |
@REM * Install ZProject | |
@REM $ git clone https://github.com/zeromq/zproject.git | |
@REM $ cd zproject && ./autogen.sh && ./configure && make && sudo make install | |
@REM * Get sources of CZMQ et Zyre | |
@REM $ git clone https://github.com/zeromq/czmq.git | |
@REM $ git clone https://github.com/zeromq/zyre.git | |
@REM * Rebuild files maintained by ZProject | |
@REM $ cd czmq && gsl project.xml | |
@REM $ cd zyre && gsl project.xml | |
if not defined VisualStudioVersion ( | |
pushd "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools" | |
call VsDevCmd.bat | |
popd | |
) | |
@REM Find the installed version of Windows SDK and define variable WTPV10 | |
for /F "skip=2 tokens=2,*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0" /reg:32 /v ProductVersion') do set "WTPV10=%%B" | |
echo Found Windows SDK version %WTPV10% | |
@REM Force version 10.0.17763.0 | |
@REM set WTPV10=10.0.17763.0 | |
@REM WindowsTargetPlatformVersion need a 4 digit version whilst registry key value has only the first 3. | |
set WTPV10="WindowsTargetPlatformVersion=%WTPV10%.0" | |
@REM Check for presence of required binaries | |
call :_which git.exe Git | |
if ERRORLEVEL 1 goto :eof | |
call :_which cmake.exe CMake | |
if ERRORLEVEL 1 goto :eof | |
call :_which msbuild.exe MSBuild | |
if ERRORLEVEL 1 goto :eof | |
@REM Bare clone repositories of ZeroMQ and its dependencies | |
if not exist sources ( | |
mkdir sources | |
) | |
pushd sources | |
@REM ZeroMQ projects | |
call :_get_sources libsodium https://github.com/jedisct1/libsodium.git | |
call :_get_sources libzmq https://github.com/zeromq/libzmq.git | |
call :_get_sources czmq https://github.com/zeromq/czmq.git | |
call :_get_sources zyre https://github.com/zeromq/zyre.git | |
popd | |
@REM Build a timestamped root directory | |
for /f %%X in ('wmic path win32_localtime get Year^,Month^,Day /format:list ^| findstr "="') do (set %%X) | |
set TODAY=%Year%-%Month%-%Day% | |
set BUILD_ROOT=%~dp0 | |
set BUILD_ROOT=!BUILD_ROOT:~0,-1!\build_zmq_%TODAY% | |
set TODAY= | |
@REM Prepare working directory | |
if exist %BUILD_ROOT% ( | |
rd %BUILD_ROOT% /S /Q | |
) | |
mkdir %BUILD_ROOT% | |
mkdir %BUILD_ROOT%\out | |
mkdir %BUILD_ROOT%\deps | |
mkdir %BUILD_ROOT%\deps\bin | |
mkdir %BUILD_ROOT%\deps\lib | |
mkdir %BUILD_ROOT%\deps\include | |
cd %BUILD_ROOT% | |
set SODIUM_BRANCH=stable | |
call :_clone_local libsodium %SODIUM_BRANCH% | |
cd builds\msvc\vs2022 | |
msbuild /m /v:n /p:Configuration=DynRelease /p:Platform=Win32 /p:%WTPV10% libsodium.sln | |
if ERRORLEVEL 1 goto :eof | |
popd | |
copy libsodium\bin\Win32\Release\v143\dynamic\libsodium.dll %BUILD_ROOT%\deps\bin\ | |
copy libsodium\bin\Win32\Release\v143\dynamic\libsodium.lib %BUILD_ROOT%\deps\lib\ | |
copy libsodium\src\libsodium\include\sodium.h %BUILD_ROOT%\deps\include\ | |
mkdir %BUILD_ROOT%\deps\include\sodium\ | |
copy libsodium\src\libsodium\include\sodium\*.h %BUILD_ROOT%\deps\include\sodium\ | |
@REM Build LibZMQ | |
set LIBZMQ_VERSION=4.3.6 | |
set LIBZMQ_LIB=libzmq-v143-mt-%LIBZMQ_VERSION:.=_% | |
@REM call :_clone_local libzmq v%LIBZMQ_VERSION% | |
call :_clone_local libzmq master | |
cmake -DCMAKE_PREFIX_PATH="%BUILD_ROOT%\deps"^ | |
-DCMAKE_INSTALL_PREFIX=%BUILD_ROOT%\deps^ | |
-DBUILD_STATIC=OFF^ | |
-DBUILD_SHARED=ON^ | |
-DENABLE_DRAFTS=ON^ | |
-DENABLE_CURVE=ON^ | |
-DWITH_LIBSODIUM=ON^ | |
-DPOLLER=epoll^ | |
-DZMQ_BUILD_TESTS=OFF^ | |
-DWITH_PERF_TOOL=OFF^ | |
-B build^ | |
-A Win32 | |
cmake --build build --config Release --target install | |
if ERRORLEVEL 1 goto :eof | |
popd | |
@REM Build CZMQ | |
set CZMQ_VERSION=4.2.2 | |
@REM call :_clone_local czmq v%CZMQ_VERSION% | |
call :_clone_local czmq master | |
cmake -DCMAKE_PREFIX_PATH=%BUILD_ROOT%\deps^ | |
-DCMAKE_INSTALL_PREFIX=%BUILD_ROOT%\deps^ | |
-DENABLE_DRAFTS=ON^ | |
-DCZMQ_BUILD_STATIC=OFF^ | |
-DCZMQ_BUILD_SHARED=ON^ | |
-B build^ | |
-A Win32 | |
cmake --build build --config Release --target install | |
if ERRORLEVEL 1 goto :eof | |
popd | |
@REM Build Zyre | |
set ZYRE_VERSION=2.0.1 | |
@REM call :_clone_local zyre v%ZYRE_VERSION% | |
call :_clone_local zyre master | |
cmake -DCMAKE_PREFIX_PATH=%BUILD_ROOT%\deps^ | |
-DCMAKE_INSTALL_PREFIX=%BUILD_ROOT%\deps^ | |
-DENABLE_DRAFTS=ON^ | |
-DZYRE_BUILD_STATIC=OFF^ | |
-DZYRE_BUILD_SHARED=ON^ | |
-B build^ | |
-A Win32 | |
cmake --build build --config Release --target install | |
if ERRORLEVEL 1 goto :eof | |
popd | |
@REM Copy compiled librairies into %BUILD_ROOT%\out | |
copy deps\bin\*.dll %BUILD_ROOT%\out\ 1>NUL 2>&1 | |
@echo( | |
@echo Done. | |
@echo Build was done into: %BUILD_ROOT% | |
@echo Libraries have been moved to: %BUILD_ROOT%\out | |
goto :eof | |
:_which | |
@REM Check if an executable exists | |
for %%X in (%1) do (set FOUND=%%~$PATH:X) | |
if not defined FOUND ( | |
@echo %2 not found, bye | |
exit /B 1 | |
) | |
exit /B 0 | |
:_get_sources | |
@REM Clone or update a bare git repository | |
if exist .\%1.git\ ( | |
cd %1.git | |
git fetch origin +refs/heads/*:refs/heads/* --prune | |
cd .. | |
) else ( | |
git clone --bare %2 %1.git | |
) | |
exit /B 0 | |
:_clone_local | |
@REM Prepare local worktree by cloning local bare repo and moving into it | |
cd %BUILD_ROOT% | |
git clone --depth 1 --single-branch --branch %2 file://%cd%\..\sources\%1.git %1 | |
pushd %1 | |
exit /B 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal EnableDelayedExpansion | |
@REM Build LibZMQ, CZMQ et Zyre with their dependencies | |
@REM Toolchain : Visual Studio 2022 with Windows 10 SDK | |
@REM Dependencies : GIT (Git for Windows), CMAKE | |
@REM | |
@REM After successful build the resulting DLL are moved into zmq_build_%TODAY%\out | |
@REM | |
@REM To regenerate CZMQ/Zyre bindings a Linux system is required : | |
@REM * Ubuntu : Install build-essential and libpcre3-dev | |
@REM * Install GSL | |
@REM $ git clone https://github.com/zeromq/gsl.git | |
@REM $ cd gsl/src && make && sudo make install | |
@REM * Install ZProject | |
@REM $ git clone https://github.com/zeromq/zproject.git | |
@REM $ cd zproject && ./autogen.sh && ./configure && make && sudo make install | |
@REM * Get sources of CZMQ et Zyre | |
@REM $ git clone https://github.com/zeromq/czmq.git | |
@REM $ git clone https://github.com/zeromq/zyre.git | |
@REM * Rebuild files maintained by ZProject | |
@REM $ cd czmq && gsl project.xml | |
@REM $ cd zyre && gsl project.xml | |
if not defined VisualStudioVersion ( | |
pushd "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\" | |
call vcvars64.bat | |
popd | |
) | |
@REM Find the installed version of Windows SDK and define variable WTPV10 | |
for /F "skip=2 tokens=2,*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0" /reg:32 /v ProductVersion') do set "WTPV10=%%B" | |
echo Found Windows SDK version %WTPV10% | |
@REM Force version 10.0.17763.0 | |
@REM set WTPV10=10.0.17763.0 | |
@REM WindowsTargetPlatformVersion need a 4 digit version whilst registry key value has only the first 3. | |
set WTPV10="WindowsTargetPlatformVersion=%WTPV10%.0" | |
@REM Check for presence of required binaries | |
call :_which git.exe Git | |
if ERRORLEVEL 1 goto :eof | |
call :_which cmake.exe CMake | |
if ERRORLEVEL 1 goto :eof | |
call :_which msbuild.exe MSBuild | |
if ERRORLEVEL 1 goto :eof | |
@REM Bare clone repositories of ZeroMQ and its dependencies | |
if not exist sources ( | |
mkdir sources | |
) | |
pushd sources | |
@REM ZeroMQ projects | |
call :_get_sources libsodium https://github.com/jedisct1/libsodium.git | |
call :_get_sources libzmq https://github.com/zeromq/libzmq.git | |
call :_get_sources czmq https://github.com/zeromq/czmq.git | |
call :_get_sources zyre https://github.com/zeromq/zyre.git | |
popd | |
@REM Build a timestamped root directory | |
for /f %%X in ('wmic path win32_localtime get Year^,Month^,Day /format:list ^| findstr "="') do (set %%X) | |
set TODAY=%Year%-%Month%-%Day% | |
set BUILD_ROOT=%~dp0 | |
set BUILD_ROOT=!BUILD_ROOT:~0,-1!\build_zmq64_%TODAY% | |
set TODAY= | |
@REM Prepare working directory | |
if exist %BUILD_ROOT% ( | |
rd %BUILD_ROOT% /S /Q | |
) | |
mkdir %BUILD_ROOT% | |
mkdir %BUILD_ROOT%\out | |
mkdir %BUILD_ROOT%\deps | |
mkdir %BUILD_ROOT%\deps\bin | |
mkdir %BUILD_ROOT%\deps\lib | |
mkdir %BUILD_ROOT%\deps\include | |
cd %BUILD_ROOT% | |
set SODIUM_BRANCH=stable | |
call :_clone_local libsodium %SODIUM_BRANCH% | |
cd builds\msvc\vs2022 | |
msbuild /m /v:n /p:Configuration=DynRelease /p:Platform=x64 /p:%WTPV10% libsodium.sln | |
if ERRORLEVEL 1 goto :eof | |
popd | |
copy libsodium\bin\x64\Release\v143\dynamic\libsodium.dll %BUILD_ROOT%\deps\bin\ | |
copy libsodium\bin\x64\Release\v143\dynamic\libsodium.lib %BUILD_ROOT%\deps\lib\ | |
copy libsodium\src\libsodium\include\sodium.h %BUILD_ROOT%\deps\include\ | |
mkdir %BUILD_ROOT%\deps\include\sodium\ | |
copy libsodium\src\libsodium\include\sodium\*.h %BUILD_ROOT%\deps\include\sodium\ | |
@REM Build LibZMQ | |
set LIBZMQ_VERSION=4.3.6 | |
set LIBZMQ_LIB=libzmq-v143-mt-%LIBZMQ_VERSION:.=_% | |
@REM call :_clone_local libzmq v%LIBZMQ_VERSION% | |
call :_clone_local libzmq master | |
cmake -DCMAKE_PREFIX_PATH="%BUILD_ROOT%\deps"^ | |
-DCMAKE_INSTALL_PREFIX=%BUILD_ROOT%\deps^ | |
-DBUILD_STATIC=OFF^ | |
-DBUILD_SHARED=ON^ | |
-DENABLE_DRAFTS=ON^ | |
-DENABLE_CURVE=ON^ | |
-DWITH_LIBSODIUM=ON^ | |
-DPOLLER=epoll^ | |
-DZMQ_BUILD_TESTS=OFF^ | |
-DWITH_PERF_TOOL=OFF^ | |
-B build^ | |
-A x64 | |
cmake --build build --config Release --target install | |
if ERRORLEVEL 1 goto :eof | |
popd | |
@REM Build CZMQ | |
set CZMQ_VERSION=4.2.2 | |
@REM call :_clone_local czmq v%CZMQ_VERSION% | |
call :_clone_local czmq master | |
cmake -DCMAKE_PREFIX_PATH=%BUILD_ROOT%\deps^ | |
-DCMAKE_INSTALL_PREFIX=%BUILD_ROOT%\deps^ | |
-DENABLE_DRAFTS=ON^ | |
-DCZMQ_BUILD_STATIC=OFF^ | |
-DCZMQ_BUILD_SHARED=ON^ | |
-B build^ | |
-A x64 | |
cmake --build build --config Release --target install | |
if ERRORLEVEL 1 goto :eof | |
popd | |
@REM Build Zyre | |
set ZYRE_VERSION=2.0.1 | |
@REM call :_clone_local zyre v%ZYRE_VERSION% | |
call :_clone_local zyre master | |
cmake -DCMAKE_PREFIX_PATH=%BUILD_ROOT%\deps^ | |
-DCMAKE_INSTALL_PREFIX=%BUILD_ROOT%\deps^ | |
-DENABLE_DRAFTS=ON^ | |
-DZYRE_BUILD_STATIC=OFF^ | |
-DZYRE_BUILD_SHARED=ON^ | |
-B build^ | |
-A x64 | |
cmake --build build --config Release --target install | |
if ERRORLEVEL 1 goto :eof | |
popd | |
@REM Copy compiled librairies into %BUILD_ROOT%\out | |
copy deps\bin\*.dll %BUILD_ROOT%\out\ 1>NUL 2>&1 | |
@echo( | |
@echo Done. | |
@echo Build was done into: %BUILD_ROOT% | |
@echo Libraries have been moved to: %BUILD_ROOT%\out | |
goto :eof | |
:_which | |
@REM Check if an executable exists | |
for %%X in (%1) do (set FOUND=%%~$PATH:X) | |
if not defined FOUND ( | |
@echo %2 not found, bye | |
exit /B 1 | |
) | |
exit /B 0 | |
:_get_sources | |
@REM Clone or update a bare git repository | |
if exist .\%1.git\ ( | |
cd %1.git | |
git fetch origin +refs/heads/*:refs/heads/* --prune | |
cd .. | |
) else ( | |
git clone --bare %2 %1.git | |
) | |
exit /B 0 | |
:_clone_local | |
@REM Prepare local worktree by cloning local bare repo and moving into it | |
cd %BUILD_ROOT% | |
git clone --depth 1 --single-branch --branch %2 file://%cd%\..\sources\%1.git %1 | |
pushd %1 | |
exit /B 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment