From 5ef8294f3f440be81d9d9e466517d8a7dce2b26d Mon Sep 17 00:00:00 2001 From: Artem Dyomin Date: Wed, 16 Nov 2022 19:39:32 +0100 Subject: Enable llvm-mingw ffmpeg windows build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added build of ffmpeg for llvm-mingw - Improved build errors handling - Refactoring: decompose script into a few functions Build example: https://testresults.qt.io/coin/integration/qt/qt5/tasks/web_qt_qt5_1668780311363 See tests for LLVM-x64, they passed Pick-to: 6.4 Change-Id: I59fe28ba6eb8e65ef5c4c3d08343ff72f349bd21 Reviewed-by: Lars Knoll Reviewed-by: Simo Fält --- coin/platform_configs/cmake_platforms.yaml | 4 +- .../provisioning/common/windows/install-ffmpeg.ps1 | 122 +++++++++++++-------- 2 files changed, 80 insertions(+), 46 deletions(-) diff --git a/coin/platform_configs/cmake_platforms.yaml b/coin/platform_configs/cmake_platforms.yaml index 19be7fdc..5e77beca 100644 --- a/coin/platform_configs/cmake_platforms.yaml +++ b/coin/platform_configs/cmake_platforms.yaml @@ -186,7 +186,7 @@ Configurations: Environment variables: [ 'Path=C:\llvm-mingw\bin;{{.Env.Path}}', 'CMAKE_ARGS=-DOPENSSL_ROOT_DIR={{.Env.OPENSSL_INCLUDE_x64}}\.. -DPostgreSQL_ROOT={{.Env.POSTGRESQL_LIB_x64}}\..', - 'NON_QTBASE_CMAKE_ARGS=-DFEATURE_system_tiff=OFF', + 'NON_QTBASE_CMAKE_ARGS=-DFEATURE_system_tiff=OFF -DFFMPEG_DIR={{.Env.FFMPEG_DIR_LLVM_MINGW}}', 'LLVM_INSTALL_DIR=C:\llvm-mingw', 'Protobuf_ROOT={{.Env.Protobuf_ROOT_llvm_mingw}}' ] @@ -199,7 +199,7 @@ Configurations: Environment variables: [ 'Path=C:\llvm-mingw\bin;{{.Env.Path}}', 'CMAKE_ARGS=-DOPENSSL_ROOT_DIR={{.Env.OPENSSL_INCLUDE_x64}}\.. -DPostgreSQL_ROOT={{.Env.POSTGRESQL_LIB_x64}}\..', - 'NON_QTBASE_CMAKE_ARGS=-DFEATURE_system_tiff=OFF', + 'NON_QTBASE_CMAKE_ARGS=-DFEATURE_system_tiff=OFF -DFFMPEG_DIR={{.Env.FFMPEG_DIR_LLVM_MINGW}}', 'LLVM_INSTALL_DIR=C:\llvm-mingw', 'Protobuf_ROOT={{.Env.Protobuf_ROOT_llvm_mingw}}' ] diff --git a/coin/provisioning/common/windows/install-ffmpeg.ps1 b/coin/provisioning/common/windows/install-ffmpeg.ps1 index 73b7444f..4953c774 100644 --- a/coin/provisioning/common/windows/install-ffmpeg.ps1 +++ b/coin/provisioning/common/windows/install-ffmpeg.ps1 @@ -58,62 +58,96 @@ Verify-Checksum $download_location $sha1 Extract-7Zip $download_location $unzip_location Remove $download_location -function CheckExitCode { - param ($p) - - if ($p.ExitCode) { - Write-host "Process failed with exit code: $($p.ExitCode)" - exit 1 - } -} - $config = Get-Content "$PSScriptRoot\..\shared\ffmpeg_config_options.txt" Write-Host "FFmpeg configuration $config" -Write-Host "Configure and compile ffmpeg for MINGW" -$mingw = [System.Environment]::GetEnvironmentVariable("MINGW1120", [System.EnvironmentVariableTarget]::Machine) -$env:PATH += ";$mingw\bin" -$env:MSYS2_PATH_TYPE = "inherit" -$env:MSYSTEM = "MINGW" -$cmd = "cd /c/$ffmpeg_name" -$cmd += "&& mkdir -p build/mingw && cd build/mingw" -$cmd += "&& ../../configure --prefix=installed $config" -$cmd += "&& make install -j" +function InstallFfmpeg { + Param ( + [string]$buildSystem, + [string]$msystem, + [string]$additionalPath, + [string]$ffmpegDirEnvVar, + [string]$toolchain + ) + + Write-Host "Configure and compile ffmpeg for $buildSystem" -$build = Start-Process -NoNewWindow -Wait -PassThru -ErrorAction Stop -FilePath "$msys" -ArgumentList ("-lc", "`"$cmd`"") -CheckExitCode $build + $oldPath = $env:PATH -Set-EnvironmentVariable "FFMPEG_DIR_MINGW" "C:\$ffmpeg_name\build\mingw\installed" + if ($additionalPath) { $env:PATH = "$additionalPath;$env:PATH" } + $env:MSYS2_PATH_TYPE = "inherit" + $env:MSYSTEM = $msystem + $cmd = "cd /c/$ffmpeg_name" + $cmd += " && mkdir -p build/$buildSystem && cd build/$buildSystem" + $cmd += " && ../../configure --prefix=installed $config" + if ($toolchain) { $cmd += " --toolchain=$toolchain" } + $cmd += " && make install -j" -Write-Host "Enter VisualStudio developer shell" -$vsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional" -try { - Import-Module "$vsPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" - Enter-VsDevShell -VsInstallPath $vsPath -DevCmdArguments "-arch=x64 -no_logo" -} catch { - Write-host "Failed to enter VisualStudio DevShell" - exit 1 + Write-Host "MSYS cmd:" + Write-Host $cmd + $buildResult = Start-Process -NoNewWindow -Wait -PassThru -ErrorAction Stop -FilePath "$msys" -ArgumentList ("-lc", "`"$cmd`"") + + $env:PATH = $oldPath + + if ($buildResult.ExitCode) { + Write-Host "Failed to build ffmpeg for $buildSystem" + return $false + } + + Set-EnvironmentVariable $ffmpegDirEnvVar "C:\$ffmpeg_name\build\$buildSystem\installed" + return $true } -Write-Host "Configure and compile ffmpeg for MSVC" -$env:MSYSTEM = "MSYS" -$env:MSYS2_PATH_TYPE = "inherit" +function InstallMingwFfmpeg { + $mingwPath = [System.Environment]::GetEnvironmentVariable("MINGW1120", [System.EnvironmentVariableTarget]::Machine) + return InstallFfmpeg -buildSystem "mingw" -msystem "MINGW" -additionalPath "$mingwPath\bin" -ffmpegDirEnvVar "FFMPEG_DIR_MINGW" +} -$cmd = "CC=cl;" -$cmd += "cd /c/$ffmpeg_name" -$cmd += "&& mkdir -p build/msvc && cd build/msvc" -$cmd += "&& ../../configure --toolchain=msvc --prefix=installed $config" -$cmd += "&& make install -j" -$build = Start-Process -NoNewWindow -Wait -PassThru -ErrorAction Stop -FilePath "$msys" -ArgumentList ("-lc", "`"$cmd`"") -CheckExitCode $build +function InstallMsvcFfmpeg { + $vsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional" + #$vsPath = "C:\Program Files\Microsoft Visual Studio\2022\Professional" + + Write-Host "Enter VisualStudio developer shell" + try { + Import-Module "$vsPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath $vsPath -DevCmdArguments "-arch=x64 -no_logo" + } catch { + Write-Host "Failed to enter VisualStudio DevShell" + return $false + } + + $result = InstallFfmpeg -buildSystem "msvc" -msystem "MSYS" -toolchain "msvc" -ffmpegDirEnvVar "FFMPEG_DIR_MSVC" + + if ($result) { + # As ffmpeg build system creates lib*.a file we have to rename them to *.lib files to be recognized by WIN32 + Write-Host "Rename libraries lib*.a -> *.lib" + try { + $msvcDir = [System.Environment]::GetEnvironmentVariable("FFMPEG_DIR_MSVC", [System.EnvironmentVariableTarget]::Machine) + Get-ChildItem "$msvcDir\lib\lib*.a" | Rename-Item -NewName { $_.Name -replace 'lib(\w+).a$', '$1.lib' } + } catch { + Write-Host "Failed to rename libraries lib*.a -> *.lib" + return $false + } + } + + return $result +} + + +function InstallLlvmMingwFfmpeg { + return InstallFfmpeg -buildSystem "llvm-mingw" -msystem "CLANG64" -ffmpegDirEnvVar "FFMPEG_DIR_LLVM_MINGW" -additionalPath "C:\llvm-mingw\bin" +} -$ffmpeg_mscv_install = "C:\$ffmpeg_name\build\msvc\installed" +$mingwRes = InstallMingwFfmpeg +$msvcRes = InstallMsvcFfmpeg +$llvmMingwRes = InstallLlvmMingwFfmpeg -# As ffmpeg build system creates lib*.a file we have to rename them to *.lib files to be recognized by WIN32 -Write-Host "Rename libraries lib*.a -> *.lib" -Get-ChildItem "$ffmpeg_mscv_install\lib\lib*.a" | Rename-Item -NewName { $_.Name -replace 'lib(\w+).a$', '$1.lib' } +Write-Host "Ffmpeg installation results:" +Write-Host " mingw:" $(if ($mingwRes) { "OK" } else { "FAIL" }) +Write-Host " msvc:" $(if ($msvcRes) { "OK" } else { "FAIL" }) +Write-Host " llvm-mingw:" $(if ($llvmMingwRes) { "OK" } else { "FAIL" }) -Set-EnvironmentVariable "FFMPEG_DIR_MSVC" $ffmpeg_mscv_install +exit $(if ($mingwRes -and $msvcRes -and $llvmMingwRes) { 0 } else { 1 }) -- cgit v1.2.3