build.cmd 22.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
@echo off

setlocal enabledelayedexpansion
goto begin


:: Subroutines

:find_on_path out_variable file_name
set %1=%~f$PATH:2
goto :EOF


:get_dir_path out_variable file_path
set %1=%~dp2
goto :EOF


:get_full_path out_variable file_path
setlocal
set FULL_PATH=%~f2
if not exist "%FULL_PATH%" (
    set FULL_PATH=
) else (
    if exist "%FULL_PATH%\" (
        set FULL_PATH=
    )
)
endlocal & set "%1=%FULL_PATH%"
goto :EOF


:get_full_path_dir out_variable file_path
setlocal
set FULL_PATH=%~dp2
if not exist "%FULL_PATH%" (
    set FULL_PATH=
)
endlocal & set "%1=%FULL_PATH%"
goto :EOF


:prompt_for_string out_variable prompt
set /p %1=%~2^>
goto :EOF


:prompt_for_positive_integer out_variable prompt
setlocal
call :prompt_for_string USER_INPUT "%~2"
if "%USER_INPUT%" == "" set USER_INPUT=0
set /a RESULT=%USER_INPUT%
if not %RESULT% GTR 0 (
    set RESULT=
)
endlocal & set "%1=%RESULT%"
goto :EOF


:prompt_for_file out_variable prompt
setlocal
:prompt_for_file__retry
call :prompt_for_string USER_INPUT "%~2"
if "%USER_INPUT%" == "" (
    endlocal
    set %1=
    goto :EOF
)
call :get_full_path RESULT "%USER_INPUT%"
if "%RESULT%" == "" (
    echo Input does not point to valid file!
    set USER_INPUT=
    goto prompt_for_file__retry
)
endlocal & set "%1=%RESULT%"
goto :EOF


:prompt_for_dir out_variable prompt
setlocal
:prompt_for_dir__retry
call :prompt_for_string USER_INPUT "%~2"
if "%USER_INPUT%" == "" (
    endlocal
    set %1=
    goto :EOF
)
call :get_full_path_dir RESULT "%USER_INPUT%\"
if "%RESULT%" == "" (
    echo Input does not point to valid dir!
    set USER_INPUT=
    goto prompt_for_dir__retry
)
endlocal & set "%1=%RESULT%"
goto :EOF


:usage
echo Usage:
echo %~n0 [--no-interactive] [ OPTIONS ... ]
echo.
echo Basic options:
echo --no-interactive                Run without interactive prompts
echo                                 When not specified, the script will prompt
echo                                 for some of the parameters.
echo --jobs ^<count^>                  Set parallel jobs count when building
echo                                 Defaults to no. of logical cores
echo --skip-deps                     Skips (re)building of deps
echo --skip-krita                    Skips (re)building of Krita
echo.
echo Path options:
echo --src-dir ^<dir_path^>            Specify Krita source dir
echo                                 If unspecified, this will be determined from
echo                                 the script location.
echo --download-dir ^<dir_path^>       Specify deps download dir
echo                                 Can be omitted if --skip-deps is used
echo --deps-build-dir ^<dir_path^>     Specify deps build dir
echo                                 Can be omitted if --skip-deps is used
echo --deps-install-dir ^<dir_path^>   Specify deps install dir
echo --krita-build-dir ^<dir_path^>    Specify Krita build dir
echo                                 Can be omitted if --skip-krita is used
echo --krita-install-dir ^<dir_path^>  Specify Krita install dir
echo                                 Can be omitted if --skip-krita is used
echo.
goto :EOF
:usage_and_exit
call :usage
exit /b
:usage_and_fail
call :usage
exit /b 100


:: ----------------------------
:begin

echo Krita build script for Windows
echo.


:: command-line args parsing
set ARG_NO_INTERACTIVE=
set ARG_JOBS=
set ARG_SKIP_DEPS=
set ARG_SKIP_KRITA=
set ARG_SRC_DIR=
set ARG_DOWNLOAD_DIR=
set ARG_DEPS_BUILD_DIR=
set ARG_DEPS_INSTALL_DIR=
set ARG_KRITA_BUILD_DIR=
set ARG_KRITA_INSTALL_DIR=
:args_parsing_loop
set CURRENT_MATCHED=
if not "%1" == "" (
    if "%1" == "--no-interactive" (
        set ARG_NO_INTERACTIVE=1
        set CURRENT_MATCHED=1
    )
    if "%1" == "--jobs" (
        if not "%ARG_JOBS%" == "" (
            echo ERROR: Arg --jobs specified more than once 1>&2
            echo.
            goto usage_and_fail
        )
        set /a "ARG_JOBS=%2"
        if not !ARG_JOBS! GTR 0 (
            echo ERROR: Arg --jobs is not a positive integer 1>&2
            echo.
            goto usage_and_fail
        )
        shift /2
        set CURRENT_MATCHED=1
    )
    if "%1" == "--skip-deps" (
        set ARG_SKIP_DEPS=1
        set CURRENT_MATCHED=1
    )
    if "%1" == "--skip-krita" (
        set ARG_SKIP_KRITA=1
        set CURRENT_MATCHED=1
    )
    if "%1" == "--src-dir" (
        if not "%ARG_SRC_DIR%" == "" (
            echo ERROR: Arg --src-dir specified more than once 1>&2
            echo.
            goto usage_and_fail
        )
        if not exist "%~f2\" (
            echo ERROR: Arg --src-dir does not point to a directory 1>&2
            echo.
            goto usage_and_fail
        )
        call :get_dir_path ARG_SRC_DIR "%~f2\"
        shift /2
        set CURRENT_MATCHED=1
    )
    if "%1" == "--download-dir" (
        if not "%ARG_DOWNLOAD_DIR%" == "" (
            echo ERROR: Arg --download-dir specified more than once 1>&2
            echo.
            goto usage_and_fail
        )
        if "%~f2" == "" (
            echo ERROR: Arg --download-dir does not point to a valid path 1>&2
            echo.
            goto usage_and_fail
        )
        call :get_dir_path ARG_DOWNLOAD_DIR "%~f2\"
        shift /2
        set CURRENT_MATCHED=1
    )
    if "%1" == "--deps-build-dir" (
        if not "%ARG_DEPS_BUILD_DIR%" == "" (
            echo ERROR: Arg --deps-build-dir specified more than once 1>&2
            echo.
            goto usage_and_fail
        )
        if "%~f2" == "" (
            echo ERROR: Arg --deps-build-dir does not point to a valid path 1>&2
            echo.
            goto usage_and_fail
        )
        call :get_dir_path ARG_DEPS_BUILD_DIR "%~f2\"
        shift /2
        set CURRENT_MATCHED=1
    )
    if "%1" == "--deps-install-dir" (
        if not "%ARG_DEPS_INSTALL_DIR%" == "" (
            echo ERROR: Arg --deps-install-dir specified more than once 1>&2
            echo.
            goto usage_and_fail
        )
        if "%~f2" == "" (
            echo ERROR: Arg --deps-install-dir does not point to a valid path 1>&2
            echo.
            goto usage_and_fail
        )
        call :get_dir_path ARG_DEPS_INSTALL_DIR "%~f2\"
        shift /2
        set CURRENT_MATCHED=1
    )
    if "%1" == "--krita-build-dir" (
        if not "%ARG_KRITA_BUILD_DIR%" == "" (
            echo ERROR: Arg --krita-build-dir specified more than once 1>&2
            echo.
            goto usage_and_fail
        )
        if "%~f2" == "" (
            echo ERROR: Arg --krita-build-dir does not point to a valid path 1>&2
            echo.
            goto usage_and_fail
        )
        call :get_dir_path ARG_KRITA_BUILD_DIR "%~f2\"
        shift /2
        set CURRENT_MATCHED=1
    )
    if "%1" == "--krita-install-dir" (
        if not "%ARG_KRITA_INSTALL_DIR%" == "" (
            echo ERROR: Arg --krita-install-dir specified more than once 1>&2
            echo.
            goto usage_and_fail
        )
        if "%~f2" == "" (
            echo ERROR: Arg --krita-install-dir does not point to a valid path 1>&2
            echo.
            goto usage_and_fail
        )
        call :get_dir_path ARG_KRITA_INSTALL_DIR "%~f2\"
        shift /2
        set CURRENT_MATCHED=1
    )
    if "%1" == "--help" (
        goto usage_and_exit
    )
    if not "!CURRENT_MATCHED!" == "1" (
        echo ERROR: Unknown option %1 1>&2
        echo.
        goto usage_and_fail
    )
    shift /1
    goto args_parsing_loop
)

if "%ARG_NO_INTERACTIVE%" == "1" (
    echo Non-interactive mode
) else (
    echo Interactive mode
    :: Trick to pause on exit
    call :real_begin
    pause
    exit /b !ERRORLEVEL!
)
:real_begin
echo.


if "%ARG_SKIP_DEPS%" == "1" (
    if "%ARG_SKIP_KRITA%" == "1" (
        echo ERROR: You cannot skip both deps and Krita 1>&2
        echo.
        exit /b 102
    )
    echo Building of deps will be skipped.
) else (
    if "%ARG_SKIP_KRITA%" == "1" (
        echo Building of Krita will be skipped.
    ) else (
        echo Both deps and Krita will be built.
    )
)


:: Check environment config

if "%CMAKE_EXE%" == "" (
    call :find_on_path CMAKE_EXE cmake.exe
    if "!CMAKE_EXE!" == "" (
        if not "%ARG_NO_INTERACTIVE%" == "1" (
            call :prompt_for_file CMAKE_EXE "Provide path to cmake.exe"
        )
        if "!CMAKE_EXE!" == "" (
            echo ERROR: CMake not found! 1>&2
            exit /b 102
        )
    ) else (
        echo Found CMake on PATH: !CMAKE_EXE!
        if not "%ARG_NO_INTERACTIVE%" == "1" (
            choice /c ny /n /m "Is this correct? [y/n] "
            if errorlevel 3 exit 255
            if not errorlevel 2 (
                call :prompt_for_file CMAKE_EXE "Provide path to cmake.exe"
                if "!CMAKE_EXE!" == "" (
                    echo ERROR: CMake not found! 1>&2
                    exit /b 102
                )
            )
        )
    )
)
echo CMake: %CMAKE_EXE%

if "%SEVENZIP_EXE%" == "" (
    call :find_on_path SEVENZIP_EXE 7z.exe
    if "!SEVENZIP_EXE!" == "" (
        set "SEVENZIP_EXE=%ProgramFiles%\7-Zip\7z.exe"
        if "!SEVENZIP_EXE!" == "" (
            set "SEVENZIP_EXE=%ProgramFiles(x86)%\7-Zip\7z.exe"
        )
        if "!SEVENZIP_EXE!" == "" (
            echo 7-Zip not found
        )
    )
)
if "%SEVENZIP_EXE%" == "" (
    echo 7-Zip: %SEVENZIP_EXE%
)

if "%MINGW_BIN_DIR%" == "" (
    call :find_on_path MINGW_BIN_DIR_MAKE_EXE mingw32-make.exe
    if "!MINGW_BIN_DIR_MAKE_EXE!" == "" (
        if not "%ARG_NO_INTERACTIVE%" == "1" (
            call :prompt_for_file MINGW_BIN_DIR_MAKE_EXE "Provide path to mingw32-make.exe of mingw-w64"
        )
        if "!MINGW_BIN_DIR_MAKE_EXE!" == "" (
            echo ERROR: mingw-w64 not found! 1>&2
            exit /b 102
        )
        call :get_dir_path MINGW_BIN_DIR "!MINGW_BIN_DIR_MAKE_EXE!"
    ) else (
        call :get_dir_path MINGW_BIN_DIR "!MINGW_BIN_DIR_MAKE_EXE!"
        echo Found mingw on PATH: !MINGW_BIN_DIR!
        if not "%ARG_NO_INTERACTIVE%" == "1" (
            choice /c ny /n /m "Is this correct? [y/n] "
            if errorlevel 3 exit 255
            if not errorlevel 2 (
                call :prompt_for_file MINGW_BIN_DIR_MAKE_EXE "Provide path to mingw32-make.exe of mingw-w64"
                if "!MINGW_BIN_DIR_MAKE_EXE!" == "" (
                    echo ERROR: mingw-w64 not found! 1>&2
                    exit /b 102
                )
                call :get_dir_path MINGW_BIN_DIR "!MINGW_BIN_DIR_MAKE_EXE!"
            )
        )
    )
)
echo mingw-w64: %MINGW_BIN_DIR%

if "%PYTHON_BIN_DIR%" == "" (
    call :find_on_path PYTHON_BIN_DIR_PYTHON_EXE python.exe
    if "!PYTHON_BIN_DIR_PYTHON_EXE!" == "" (
        if not "%ARG_NO_INTERACTIVE%" == "1" (
            call :prompt_for_file PYTHON_BIN_DIR_PYTHON_EXE "Provide path to python.exe of Python 3.6.2"
        )
        if "!PYTHON_BIN_DIR_PYTHON_EXE!" == "" (
            echo ERROR: Python not found! 1>&2
            exit /b 102
        )
        call :get_dir_path PYTHON_BIN_DIR "!PYTHON_BIN_DIR_PYTHON_EXE!"
    ) else (
        call :get_dir_path PYTHON_BIN_DIR "!PYTHON_BIN_DIR_PYTHON_EXE!"
        echo Found Python on PATH: !PYTHON_BIN_DIR!
        if not "%ARG_NO_INTERACTIVE%" == "1" (
            choice /c ny /n /m "Is this correct? [y/n] "
            if errorlevel 3 exit 255
            if not errorlevel 2 (
                call :prompt_for_file PYTHON_BIN_DIR_PYTHON_EXE "Provide path to python.exe of Python 3.6.2"
                if "!PYTHON_BIN_DIR_PYTHON_EXE!" == "" (
                    echo ERROR: Python not found! 1>&2
                    exit /b 102
                )
                call :get_dir_path PYTHON_BIN_DIR "!PYTHON_BIN_DIR_PYTHON_EXE!"
            )
        )
    )
)
echo Python: %PYTHON_BIN_DIR%

if "%ARG_SKIP_DEPS%" == "1" goto skip_windows_sdk_dir_check

if "%WindowsSdkDir%" == "" if not "%ProgramFiles(x86)%" == "" set "WindowsSdkDir=%ProgramFiles(x86)%\Windows Kits\10"
if "%WindowsSdkDir%" == "" set "WindowsSdkDir=%ProgramFiles(x86)%\Windows Kits\10"
if exist "%WindowsSdkDir%\" (
    pushd "%WindowsSdkDir%"
    if exist "bin\x64\fxc.exe" (
        set HAVE_FXC_EXE=1
Dmitry Kazakov's avatar
Dmitry Kazakov committed
426
        if "%WindowsSdkVerBinPath%" == "" set "WindowsSdkVerBinPath=%WindowsSdkDir%"
427 428 429 430
    ) else (
        for /f "delims=" %%a in ('dir /a:d /b "bin\10.*"') do (
            if exist "bin\%%a\x64\fxc.exe" (
                set HAVE_FXC_EXE=1
Dmitry Kazakov's avatar
Dmitry Kazakov committed
431
                if "%WindowsSdkVerBinPath%" == "" set "WindowsSdkVerBinPath=%WindowsSdkDir%\bin\%%a\"
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
            )
        )
    )
    popd
)
set QT_ENABLE_DYNAMIC_OPENGL=ON
if not "%HAVE_FXC_EXE%" == "1" (
    set WindowsSdkDir=
    echo Windows SDK 10 with fxc.exe not found
    echo Qt will *not* be built with ANGLE ^(dynamic OpenGL^) support.
    if not "%ARG_NO_INTERACTIVE%" == "1" (
        choice /c ny /n /m "Is this ok? [y/n] "
        if errorlevel 3 exit 255
        if not errorlevel 2 (
            exit /b 102
        )
    )
    set QT_ENABLE_DYNAMIC_OPENGL=OFF
) else echo Windows SDK 10 with fxc.exe found on %WindowsSdkDir%

:skip_windows_sdk_dir_check

if not "%ARG_JOBS%" == "" (
    set "PARALLEL_JOBS=%ARG_JOBS%"
)
if "%PARALLEL_JOBS%" == "" (
    echo Number of logical CPU cores detected: %NUMBER_OF_PROCESSORS%
    echo Enabling %NUMBER_OF_PROCESSORS% parallel jobs
    set PARALLEL_JOBS=%NUMBER_OF_PROCESSORS%
    if not "%ARG_NO_INTERACTIVE%" == "1" (
        choice /c ny /n /m "Is this correct? [y/n] "
        if errorlevel 3 exit 255
        if not errorlevel 2 (
            call :prompt_for_positive_integer PARALLEL_JOBS "Provide no. of parallel jobs"
            if "!PARALLEL_JOBS!" == "" (
                echo ERROR: Invalid job count! 1>&2
                exit /b 102
            )
        )
    )
)
echo Parallel jobs count: %PARALLEL_JOBS%

if not "%ARG_SRC_DIR%" == "" (
    set "KRITA_SRC_DIR=%ARG_SRC_DIR%"
)
if "%KRITA_SRC_DIR%" == "" (
    :: Check whether this looks like to be in the source tree
	set "_temp=%~dp0"
	if "!_temp:~-21!" == "\build-tools\windows\" (
        if exist "!_temp:~0,-21!\CMakeLists.txt" (
            if exist "!_temp:~0,-21!\3rdparty\CMakeLists.txt" (
                set "KRITA_SRC_DIR=!_temp:~0,-21!\"
                echo Script is running inside Krita src dir
            )
        )
    )
)
if "%KRITA_SRC_DIR%" == "" (
    if not "%ARG_NO_INTERACTIVE%" == "1" (
        call :prompt_for_dir KRITA_SRC_DIR "Provide path of Krita src dir"
    )
    if "!KRITA_SRC_DIR!" == "" (
        echo ERROR: Krita src dir not found! 1>&2
        exit /b 102
    )
)
echo Krita src: %KRITA_SRC_DIR%

if "%ARG_SKIP_DEPS%" == "1" goto skip_deps_args_check

if not "%ARG_DOWNLOAD_DIR%" == "" (
    set "DEPS_DOWNLOAD_DIR=%ARG_DOWNLOAD_DIR%"
)
if "%DEPS_DOWNLOAD_DIR%" == "" (
    set DEPS_DOWNLOAD_DIR=%CD%\d\
    echo Using default deps download dir: !DEPS_DOWNLOAD_DIR!
    if not "%ARG_NO_INTERACTIVE%" == "1" (
        choice /c ny /n /m "Is this ok? [y/n] "
        if errorlevel 3 exit 255
        if not errorlevel 2 (
            call :prompt_for_dir DEPS_DOWNLOAD_DIR "Provide path of depps download dir"
        )
    )
    if "!DEPS_DOWNLOAD_DIR!" == "" (
        echo ERROR: Deps download dir not set! 1>&2
        exit /b 102
    )
)
echo Deps download dir: %DEPS_DOWNLOAD_DIR%

if not "%ARG_DEPS_BUILD_DIR%" == "" (
    set "DEPS_BUILD_DIR=%ARG_DEPS_BUILD_DIR%"
)
if "%DEPS_BUILD_DIR%" == "" (
    set DEPS_BUILD_DIR=%CD%\b_deps\
    echo Using default deps build dir: !DEPS_BUILD_DIR!
    if not "%ARG_NO_INTERACTIVE%" == "1" (
        choice /c ny /n /m "Is this ok? [y/n] "
        if errorlevel 3 exit 255
        if not errorlevel 2 (
            call :prompt_for_dir DEPS_BUILD_DIR "Provide path of deps build dir"
        )
    )
    if "!DEPS_BUILD_DIR!" == "" (
        echo ERROR: Deps build dir not set! 1>&2
        exit /b 102
    )
)
echo Deps build dir: %DEPS_BUILD_DIR%

:skip_deps_args_check

if not "%ARG_DEPS_INSTALL_DIR%" == "" (
    set "DEPS_INSTALL_DIR=%ARG_DEPS_INSTALL_DIR%"
)
if "%DEPS_INSTALL_DIR%" == "" (
    set DEPS_INSTALL_DIR=%CD%\i_deps\
    echo Using default deps install dir: !DEPS_INSTALL_DIR!
    if not "%ARG_NO_INTERACTIVE%" == "1" (
        choice /c ny /n /m "Is this ok? [y/n] "
        if errorlevel 3 exit 255
        if not errorlevel 2 (
            call :prompt_for_dir DEPS_INSTALL_DIR "Provide path of deps install dir"
        )
    )
    if "!DEPS_INSTALL_DIR!" == "" (
        echo ERROR: Deps install dir not set! 1>&2
        exit /b 102
    )
)
echo Deps install dir: %DEPS_INSTALL_DIR%

if "%ARG_SKIP_KRITA%" == "1" goto skip_krita_args_check

if not "%ARG_KRITA_BUILD_DIR%" == "" (
    set "KRITA_BUILD_DIR=%ARG_KRITA_BUILD_DIR%"
)
if "%KRITA_BUILD_DIR%" == "" (
    set KRITA_BUILD_DIR=%CD%\b\
    echo Using default Krita build dir: !KRITA_BUILD_DIR!
    if not "%ARG_NO_INTERACTIVE%" == "1" (
        choice /c ny /n /m "Is this ok? [y/n] "
        if errorlevel 3 exit 255
        if not errorlevel 2 (
            call :prompt_for_dir KRITA_BUILD_DIR "Provide path of Krita build dir"
        )
    )
    if "!KRITA_BUILD_DIR!" == "" (
        echo ERROR: Krita build dir not set! 1>&2
        exit /b 102
    )
)
echo Krita build dir: %KRITA_BUILD_DIR%

if not "%ARG_KRITA_INSTALL_DIR%" == "" (
    set "KRITA_INSTALL_DIR=%ARG_KRITA_INSTALL_DIR%"
)
if "%KRITA_INSTALL_DIR%" == "" (
    set KRITA_INSTALL_DIR=%CD%\i\
    echo Using default Krita install dir: !KRITA_INSTALL_DIR!
    if not "%ARG_NO_INTERACTIVE%" == "1" (
        choice /c ny /n /m "Is this ok? [y/n] "
        if errorlevel 3 exit 255
        if not errorlevel 2 (
            call :prompt_for_dir KRITA_INSTALL_DIR "Provide path of Krita install dir"
        )
    )
    if "!KRITA_INSTALL_DIR!" == "" (
        echo ERROR: Krita install dir not set! 1>&2
        exit /b 102
    )
)
echo Krita install dir: %KRITA_INSTALL_DIR%

:skip_krita_args_check

echo.


if not "%ARG_NO_INTERACTIVE%" == "1" (
    choice /c ny /n /m "Is the above ok? [y/n] "
    if errorlevel 3 exit 255
    if not errorlevel 2 (
        exit /b 1
    )
    echo.
)

:: Initialize clean PATH
set PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
set PATH=%MINGW_BIN_DIR%;%PYTHON_BIN_DIR%;%PATH%

echo Creating dirs...
if NOT "%ARG_SKIP_DEPS%" == "1" (
    mkdir %DEPS_DOWNLOAD_DIR%
    if errorlevel 1 (
        if not exist "%DEPS_DOWNLOAD_DIR%\" (
            echo ERROR: Cannot create deps download dir! 1>&2
            exit /b 103
        )
    )
    mkdir %DEPS_BUILD_DIR%
    if errorlevel 1 (
        if not exist "%DEPS_BUILD_DIR%\" (
            echo ERROR: Cannot create deps build dir! 1>&2
            exit /b 103
        )
    )
    mkdir %DEPS_INSTALL_DIR%
    if errorlevel 1 (
        if not exist "%DEPS_INSTALL_DIR%\" (
            echo ERROR: Cannot create deps install dir! 1>&2
            exit /b 103
        )
    )
)
if NOT "%ARG_SKIP_KRITA%" == "1" (
    mkdir %KRITA_BUILD_DIR%
    if errorlevel 1 (
        if not exist "%KRITA_BUILD_DIR%\" (
            echo ERROR: Cannot create Krita build dir! 1>&2
            exit /b 103
        )
    )
    mkdir %KRITA_INSTALL_DIR%
    if errorlevel 1 (
        if not exist "%KRITA_INSTALL_DIR%\" (
            echo ERROR: Cannot create Krita install dir! 1>&2
            exit /b 103
        )
    )
)

echo.


set CMAKE_BUILD_TYPE=RelWithDebInfo
set QT_ENABLE_DEBUG_INFO=OFF

:: Paths for CMake
set "BUILDDIR_DOWNLOAD_CMAKE=%DEPS_DOWNLOAD_DIR:\=/%"
set "BUILDDIR_DOWNLOAD_CMAKE=%BUILDDIR_DOWNLOAD_CMAKE: =\ %"
set "BUILDDIR_DEPS_INSTALL_CMAKE=%DEPS_INSTALL_DIR:\=/%"
set "BUILDDIR_DEPS_INSTALL_CMAKE=%BUILDDIR_DEPS_INSTALL_CMAKE: =\ %"
set "BUILDDIR_KRITA_INSTALL_CMAKE=%KRITA_INSTALL_DIR:\=/%"
set "BUILDDIR_KRITA_INSTALL_CMAKE=%BUILDDIR_KRITA_INSTALL_CMAKE: =\ %"

set PATH=%DEPS_INSTALL_DIR%\bin;%PATH%

682
if not "%GETTEXT_SEARCH_PATH%" == "" (
683
    set PATH=!PATH!;!GETTEXT_SEARCH_PATH!
684 685
)

686 687 688 689 690 691 692 693 694
if "%ARG_SKIP_DEPS%" == "1" goto skip_build_deps

pushd %DEPS_BUILD_DIR%
if errorlevel 1 (
    echo ERROR: Cannot enter deps build dir! 1>&2
    exit /b 104
)

echo Running CMake for deps...
695 696 697 698 699 700 701 702 703 704
echo "%CMAKE_EXE%" "%KRITA_SRC_DIR%\3rdparty" ^
    -DSUBMAKE_JOBS=%PARALLEL_JOBS% ^
    -DQT_ENABLE_DEBUG_INFO=%QT_ENABLE_DEBUG_INFO% ^
    -DQT_ENABLE_DYNAMIC_OPENGL=%QT_ENABLE_DYNAMIC_OPENGL% ^
    -DEXTERNALS_DOWNLOAD_DIR=%BUILDDIR_DOWNLOAD_CMAKE% ^
    -DINSTALL_ROOT=%BUILDDIR_DEPS_INSTALL_CMAKE% ^
    -G "MinGW Makefiles" ^
    -DUSE_QT_TABLET_WINDOWS=ON ^
    -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%
    
705 706 707 708 709 710 711
"%CMAKE_EXE%" "%KRITA_SRC_DIR%\3rdparty" ^
    -DSUBMAKE_JOBS=%PARALLEL_JOBS% ^
    -DQT_ENABLE_DEBUG_INFO=%QT_ENABLE_DEBUG_INFO% ^
    -DQT_ENABLE_DYNAMIC_OPENGL=%QT_ENABLE_DYNAMIC_OPENGL% ^
    -DEXTERNALS_DOWNLOAD_DIR=%BUILDDIR_DOWNLOAD_CMAKE% ^
    -DINSTALL_ROOT=%BUILDDIR_DEPS_INSTALL_CMAKE% ^
    -G "MinGW Makefiles" ^
712
    -DUSE_QT_TABLET_WINDOWS=ON ^
713 714 715 716 717 718 719
    -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%
if errorlevel 1 (
    echo ERROR: CMake configure failed! 1>&2
    exit /b 104
)
echo.

720 721
set EXT_TARGETS=patch png2ico zlib lzma gettext openssl qt boost eigen3 exiv2 fftw3
set EXT_TARGETS=%EXT_TARGETS% ilmbase jpeg lcms2 ocio openexr png tiff gsl vc libraw
722
set EXT_TARGETS=%EXT_TARGETS% giflib freetype poppler kwindowsystem drmingw gmic
723
set EXT_TARGETS=%EXT_TARGETS% python sip pyqt
724
set EXT_TARGETS=%EXT_TARGETS% quazip
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749

for %%a in (%EXT_TARGETS%) do (
    echo Building ext_%%a...
    "%CMAKE_EXE%" --build . --config %CMAKE_BUILD_TYPE% --target ext_%%a
    if errorlevel 1 (
        echo ERROR: Building of ext_%%a failed! 1>&2
        exit /b 105
    )
)
echo.

echo ******** Built deps ********
popd

:skip_build_deps

if "%ARG_SKIP_KRITA%" == "1" goto skip_build_krita

pushd %KRITA_BUILD_DIR%
if errorlevel 1 (
    echo ERROR: Cannot enter Krita build dir! 1>&2
    exit /b 104
)

echo Running CMake for Krita...
750 751 752 753 754 755 756 757 758 759
echo "%CMAKE_EXE%" "%KRITA_SRC_DIR%\." ^
    -DBoost_DEBUG=OFF ^
    -DBOOST_INCLUDEDIR=%BUILDDIR_DEPS_INSTALL_CMAKE%/include ^
    -DBOOST_ROOT=%BUILDDIR_DEPS_INSTALL_CMAKE% ^
    -DBOOST_LIBRARYDIR=%BUILDDIR_DEPS_INSTALL_CMAKE%/lib ^
    -DCMAKE_PREFIX_PATH=%BUILDDIR_DEPS_INSTALL_CMAKE% ^
    -DCMAKE_INSTALL_PREFIX=%BUILDDIR_KRITA_INSTALL_CMAKE% ^
    -DBUILD_TESTING=OFF ^
    -DHAVE_MEMORY_LEAK_TRACKER=OFF ^
    -DFOUNDATION_BUILD=ON ^
760
    -DUSE_QT_TABLET_WINDOWS=ON ^
761 762 763 764
    -Wno-dev ^
    -G "MinGW Makefiles" ^
    -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%

765 766 767 768 769 770 771 772 773
"%CMAKE_EXE%" "%KRITA_SRC_DIR%\." ^
    -DBoost_DEBUG=OFF ^
    -DBOOST_INCLUDEDIR=%BUILDDIR_DEPS_INSTALL_CMAKE%/include ^
    -DBOOST_ROOT=%BUILDDIR_DEPS_INSTALL_CMAKE% ^
    -DBOOST_LIBRARYDIR=%BUILDDIR_DEPS_INSTALL_CMAKE%/lib ^
    -DCMAKE_PREFIX_PATH=%BUILDDIR_DEPS_INSTALL_CMAKE% ^
    -DCMAKE_INSTALL_PREFIX=%BUILDDIR_KRITA_INSTALL_CMAKE% ^
    -DBUILD_TESTING=OFF ^
    -DHAVE_MEMORY_LEAK_TRACKER=OFF ^
774
    -DFOUNDATION_BUILD=ON ^
775
    -DUSE_QT_TABLET_WINDOWS=ON ^
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
    -Wno-dev ^
    -G "MinGW Makefiles" ^
    -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%
if errorlevel 1 (
    echo ERROR: CMake configure failed! 1>&2
    exit /b 104
)
echo.

echo Building Krita...
"%CMAKE_EXE%" --build . --config %CMAKE_BUILD_TYPE% --target install -- -j%PARALLEL_JOBS%
if errorlevel 1 (
    echo ERROR: Building of Krita failed! 1>&2
    exit /b 105
)
echo.

echo ******** Built Krita ********
popd

:skip_build_krita

echo Krita build completed!