|
| 1 | +@echo off |
| 2 | +setlocal EnableDelayedExpansion |
| 3 | + |
| 4 | +REM Build DCMTK-HTJ2K for WebAssembly using Emscripten (emsdk latest) and mingw32-make. |
| 5 | +REM Prerequisites: Git, CMake, MinGW (mingw32-make on PATH), and emsdk installed. |
| 6 | +REM Ensure emsdk and MinGW are available on PATH. |
| 7 | + |
| 8 | +where emsdk.bat >nul 2>nul |
| 9 | +if errorlevel 1 ( |
| 10 | + echo Warning: emsdk not found on PATH. |
| 11 | + echo Install emsdk or Add the EMSDK to PATH. |
| 12 | + echo Install emsdk from: https://emscripten.org/docs/getting_started/downloads.html |
| 13 | + exit /b 1 |
| 14 | +) |
| 15 | + |
| 16 | +REM Ensure mingw32-make is available (MinGW bin on PATH) |
| 17 | +where mingw32-make >nul 2>nul |
| 18 | +if errorlevel 1 ( |
| 19 | + echo Warning: mingw32-make not found on PATH. Add MinGW to PATH. |
| 20 | + exit /b 1 |
| 21 | +) |
| 22 | + |
| 23 | +set "PROJECT_ROOT=%CD%" |
| 24 | +set "BUILD_TYPE=Release" |
| 25 | +set "OTS_WASM=%CD%\ots_wasm" |
| 26 | +set "BUILD_DIR=%CD%\build_wasm" |
| 27 | +set "BUILD_DIR_LIB=%CD%\build_wasm\%BUILD_TYPE%" |
| 28 | + |
| 29 | + |
| 30 | +if not exist "%OTS_WASM%" mkdir "%OTS_WASM%" |
| 31 | +cd /d "%OTS_WASM%" |
| 32 | + |
| 33 | +REM ----- DCMTK (WASM) ----- |
| 34 | +if not exist "dcmtk" git clone https://github.com/DCMTK/dcmtk.git |
| 35 | +cd dcmtk |
| 36 | +git fetch |
| 37 | +git checkout -f DCMTK-3.6.9 |
| 38 | +REM Apply Emscripten fix for ofwhere.c (DCMTK unchanged; patch applied at build time) |
| 39 | +call git apply "%PROJECT_ROOT%\patches\dcmtk-ofwhere-emscripten.patch" |
| 40 | +if errorlevel 1 ( |
| 41 | + echo ERROR: Failed to apply patches\dcmtk-ofwhere-emscripten.patch |
| 42 | + echo Ensure the patch matches your DCMTK version. |
| 43 | + exit /b 1 |
| 44 | +) |
| 45 | +if not exist "%BUILD_TYPE%" mkdir "%BUILD_TYPE%" |
| 46 | +cd %BUILD_TYPE% |
| 47 | + |
| 48 | +call emcmake cmake .. -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=mingw32-make ^ |
| 49 | + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ^ |
| 50 | + -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^ |
| 51 | + -DCMAKE_CXX_STANDARD=11 ^ |
| 52 | + -DDCMTK_MODULES=ofstd;oficonv;oflog;dcmdata;dcmimgle;dcmimage;dcmjpeg;dcmjpls ^ |
| 53 | + -DDCMTK_ENABLE_STL=OFF ^ |
| 54 | + -DDCMTK_WIDE_CHAR_FILE_IO_FUNCTIONS=OFF ^ |
| 55 | + -DDCMTK_DEFAULT_DICT=builtin ^ |
| 56 | + -DDCMTK_WITH_TIFF=OFF ^ |
| 57 | + -DDCMTK_WITH_PNG=OFF ^ |
| 58 | + -DDCMTK_WITH_OPENSSL=OFF ^ |
| 59 | + -DDCMTK_WITH_XML=OFF ^ |
| 60 | + -DDCMTK_WITH_ZLIB=OFF ^ |
| 61 | + -DDCMTK_WITH_SNDFILE=OFF ^ |
| 62 | + -DDCMTK_WITH_ICONV=ON ^ |
| 63 | + -DDCMTK_WITH_WRAP=OFF ^ |
| 64 | + -DBUILD_APPS=OFF ^ |
| 65 | + -DCMAKE_INSTALL_PREFIX=%OTS_WASM%/dcmtk/%BUILD_TYPE% ^ |
| 66 | + -DCMAKE_POLICY_DEFAULT_CMP0091=NEW |
| 67 | +REM Continue to make even if cmake returned non-zero (e.g. missing BISON/FLEX) |
| 68 | + |
| 69 | +call emmake mingw32-make -j%NUMBER_OF_PROCESSORS% |
| 70 | +if errorlevel 1 (echo ERROR: DCMTK make failed. & exit /b 1) |
| 71 | +call emmake mingw32-make install |
| 72 | +if errorlevel 1 (echo ERROR: DCMTK install failed. & exit /b 1) |
| 73 | + |
| 74 | +cd /d "%OTS_WASM%" |
| 75 | + |
| 76 | +REM ----- OpenJPH (WASM) ----- |
| 77 | +if not exist "openjph" git clone https://github.com/aous72/openjph.git |
| 78 | +cd openjph |
| 79 | +git fetch |
| 80 | +git checkout -f 0.26.0 |
| 81 | +if not exist "%BUILD_TYPE%" mkdir "%BUILD_TYPE%" |
| 82 | +cd %BUILD_TYPE% |
| 83 | + |
| 84 | +call emcmake cmake .. -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=mingw32-make ^ |
| 85 | + -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^ |
| 86 | + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ^ |
| 87 | + -DCMAKE_CXX_STANDARD=11 ^ |
| 88 | + -DBUILD_SHARED_LIBS=OFF ^ |
| 89 | + -DOJPH_BUILD_EXECUTABLES=OFF ^ |
| 90 | + -DCMAKE_INSTALL_PREFIX=%OTS_WASM%/openjph/%BUILD_TYPE% ^ |
| 91 | + -DCMAKE_POLICY_DEFAULT_CMP0091=NEW |
| 92 | + |
| 93 | +call emmake mingw32-make -j%NUMBER_OF_PROCESSORS% |
| 94 | +if errorlevel 1 (echo ERROR: OpenJPH make failed. & exit /b 1) |
| 95 | +call emmake mingw32-make install |
| 96 | +if errorlevel 1 (echo ERROR: OpenJPH install failed. & exit /b 1) |
| 97 | + |
| 98 | +REM ----- Main project (DCMTK-HTJ2K) WASM ----- |
| 99 | +if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%" |
| 100 | +if not exist "%BUILD_DIR_LIB%" mkdir "%BUILD_DIR_LIB%" |
| 101 | +cd /d "%BUILD_DIR%" |
| 102 | + |
| 103 | +call emcmake cmake .. -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=mingw32-make ^ |
| 104 | + -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^ |
| 105 | + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ^ |
| 106 | + -DCMAKE_CXX_STANDARD=11 ^ |
| 107 | + -DBUILD_SHARED_LIBS=OFF ^ |
| 108 | + -DBUILD_TESTING=OFF ^ |
| 109 | + -DCMAKE_PREFIX_PATH=%OTS_WASM%/dcmtk/%BUILD_TYPE% ^ |
| 110 | + -DDCMTK_DIR=%OTS_WASM%/dcmtk/%BUILD_TYPE%/lib/cmake/dcmtk ^ |
| 111 | + -DDCMTK_ROOT=%OTS_WASM%/dcmtk/%BUILD_TYPE% ^ |
| 112 | + -DOPENJPH_DIR=%OTS_WASM%/openjph/%BUILD_TYPE%/lib/cmake/openjph ^ |
| 113 | + -DDCMTKHTJ2K_ROOT=%OTS_WASM%/dcmtkhtj2k/%BUILD_TYPE% ^ |
| 114 | + -DCMAKE_INSTALL_PREFIX=%BUILD_DIR_LIB% ^ |
| 115 | + -DCMAKE_POLICY_DEFAULT_CMP0091=NEW |
| 116 | + |
| 117 | +call emmake mingw32-make -j%NUMBER_OF_PROCESSORS% |
| 118 | +if errorlevel 1 (echo ERROR: Main project make failed. & exit /b 1) |
| 119 | +call emmake mingw32-make install |
| 120 | +if errorlevel 1 (echo ERROR: Main project install failed. & exit /b 1) |
| 121 | + |
| 122 | +cd /d "%~dp0" |
| 123 | +echo. |
| 124 | +echo WASM build complete. Output in build_wasm\%BUILD_TYPE% |
| 125 | +endlocal |
0 commit comments