build.ps1 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. try {
  2. Write-Host -ForegroundColor Green "`n## Build Path $env:Build_Repository_LocalPath #####`n"
  3. $vcpkg_toolchain = ""
  4. $vcpkg_triplet = ""
  5. if ($env:CC_SHORTNAME -eq "vs2008" -or $env:CC_SHORTNAME -eq "vs2013") {
  6. # on VS2008 mbedtls can not be built since it includes stdint.h which is not available there
  7. $build_encryption = "OFF"
  8. Write-Host -ForegroundColor Green "`n## Building without encryption on VS2008 or VS2013 #####`n"
  9. } else {
  10. $build_encryption = "ON"
  11. }
  12. if ($env:CC_SHORTNAME -eq "mingw" -or $env:CC_SHORTNAME -eq "clang-mingw") {
  13. # Workaround for CMake not wanting sh.exe on PATH for MinGW (necessary for CMake 3.12.2)
  14. $env:PATH = ($env:PATH.Split(';') | Where-Object { $_ -ne 'C:\Program Files\Git\bin' }) -join ';'
  15. $env:PATH = ($env:PATH.Split(';') | Where-Object { $_ -ne 'C:\Program Files\Git\usr\bin' }) -join ';'
  16. # Add mingw to path so that CMake finds e.g. clang
  17. $env:PATH = "$env:MSYS2_ROOT\mingw64\bin;$env:PATH"
  18. [System.Environment]::SetEnvironmentVariable('Path', $path, 'Machine')
  19. }
  20. if ($env:CC_SHORTNAME -eq "mingw") {
  21. } elseif ($env:CC_SHORTNAME -eq "clang-mingw") {
  22. # Setup clang
  23. $env:CC = "clang --target=x86_64-w64-mingw32"
  24. $env:CXX = "clang++ --target=x86_64-w64-mingw32"
  25. clang --version
  26. } else {
  27. $vcpkg_toolchain = '-DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake"'
  28. $vcpkg_triplet = '-DVCPKG_TARGET_TRIPLET="x86-windows-static"'
  29. # since https://github.com/Microsoft/vcpkg/commit/0334365f516c5f229ff4fcf038c7d0190979a38a#diff-464a170117fa96bf98b2f8d224bf503c
  30. # vcpkg need to have "C:\Tools\vcpkg\installed\x86-windows-static"
  31. New-Item -Force -ItemType directory -Path "C:/vcpkg/installed/x86-windows-static"
  32. }
  33. $cmake_cnf="$vcpkg_toolchain", "$vcpkg_triplet", "-G`"$env:GENERATOR`"", "-DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX"
  34. # Collect files for .zip packing
  35. New-Item -ItemType directory -Path pack
  36. Copy-Item LICENSE pack
  37. Copy-Item AUTHORS pack
  38. Copy-Item README.md pack
  39. Write-Host -ForegroundColor Green "`n###################################################################"
  40. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
  41. New-Item -ItemType directory -Path "build"
  42. cd build
  43. & cmake $cmake_cnf `
  44. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  45. -DUA_BUILD_EXAMPLES:BOOL=OFF `
  46. -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  47. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption ..
  48. & cmake --build . --config RelWithDebInfo
  49. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  50. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  51. exit $LASTEXITCODE
  52. }
  53. cd ..
  54. Remove-Item -Path build -Recurse -Force
  55. Write-Host -ForegroundColor Green "`n###################################################################"
  56. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with full NS0 #####`n"
  57. New-Item -ItemType directory -Path "build"
  58. cd build
  59. # Use build type Debug here, to force `-Werror`
  60. & cmake $cmake_cnf `
  61. -DCMAKE_BUILD_TYPE=Debug `
  62. -DUA_BUILD_EXAMPLES:BOOL=ON `
  63. -DUA_ENABLE_DA:BOOL=ON `
  64. -DUA_ENABLE_JSON_ENCODING:BOOL=ON `
  65. -DUA_ENABLE_PUBSUB:BOOL=ON `
  66. -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  67. -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
  68. -DUA_ENABLE_SUBSCRIPTIONS_EVENTS:BOOL=ON `
  69. -DUA_NAMESPACE_ZERO:STRING=FULL ..
  70. & cmake --build . --config RelWithDebInfo
  71. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  72. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  73. exit $LASTEXITCODE
  74. }
  75. cd ..
  76. Remove-Item -Path build -Recurse -Force
  77. Write-Host -ForegroundColor Green "`n###################################################################"
  78. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME without amalgamation #####`n"
  79. New-Item -ItemType directory -Path "build"
  80. cd build
  81. & cmake $cmake_cnf `
  82. -DBUILD_SHARED_LIBS:BOOL=OFF `
  83. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  84. -DCMAKE_INSTALL_PREFIX="$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-static" `
  85. -DUA_BUILD_EXAMPLES:BOOL=ON `
  86. -DUA_ENABLE_AMALGAMATION:BOOL=OFF ..
  87. & cmake --build . --target install --config RelWithDebInfo
  88. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  89. {
  90. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  91. exit $LASTEXITCODE
  92. }
  93. cd ..
  94. & 7z a -tzip "$env:Build_ArtifactStagingDirectory/open62541-$env:CC_SHORTNAME-static.zip" "$env:Build_Repository_LocalPath\pack\*" "$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-static\*"
  95. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  96. {
  97. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  98. exit $LASTEXITCODE
  99. }
  100. Remove-Item -Path build -Recurse -Force
  101. Write-Host -ForegroundColor Green "`n###################################################################"
  102. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME (.dll) #####`n"
  103. New-Item -ItemType directory -Path "build"
  104. cd build
  105. & cmake $cmake_cnf `
  106. -DBUILD_SHARED_LIBS:BOOL=ON `
  107. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  108. -DCMAKE_INSTALL_PREFIX="$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-dynamic" `
  109. -DUA_BUILD_EXAMPLES:BOOL=ON `
  110. -DUA_ENABLE_AMALGAMATION:BOOL=OFF ..
  111. & cmake --build . --target install --config RelWithDebInfo
  112. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  113. {
  114. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  115. exit $LASTEXITCODE
  116. }
  117. cd ..
  118. & 7z a -tzip "$env:Build_ArtifactStagingDirectory/open62541-$env:CC_SHORTNAME-dynamic.zip" "$env:Build_Repository_LocalPath\pack\*" "$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-static\*"
  119. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  120. {
  121. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  122. exit $LASTEXITCODE
  123. }
  124. Remove-Item -Path build -Recurse -Force
  125. # Only execute unit tests on vs2017 to save compilation time
  126. if ($env:CC_SHORTNAME -eq "vs2017") {
  127. Write-Host -ForegroundColor Green "`n###################################################################"
  128. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
  129. New-Item -ItemType directory -Path "build"
  130. cd build
  131. & cmake $cmake_cnf `
  132. -DBUILD_SHARED_LIBS:BOOL=OFF `
  133. -DCMAKE_BUILD_TYPE=Debug `
  134. -DUA_BUILD_EXAMPLES=OFF `
  135. -DUA_BUILD_UNIT_TESTS=ON `
  136. -DUA_ENABLE_DA=ON `
  137. -DUA_ENABLE_DISCOVERY=ON `
  138. -DUA_ENABLE_DISCOVERY_MULTICAST=ON `
  139. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption `
  140. -DUA_ENABLE_JSON_ENCODING:BOOL=ON `
  141. -DUA_ENABLE_PUBSUB:BOOL=ON `
  142. -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  143. -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
  144. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON ..
  145. & cmake --build . --config Debug
  146. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  147. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  148. exit $LASTEXITCODE
  149. }
  150. & cmake --build . --target test-verbose --config Debug
  151. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  152. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  153. exit $LASTEXITCODE
  154. }
  155. }
  156. # # do not cache log
  157. # Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force
  158. } catch {
  159. # Print a detailed error message
  160. $FullException = ($_.Exception|format-list -force) | Out-String
  161. Write-Host -ForegroundColor Red "`n------------------ Exception ------------------`n$FullException`n"
  162. [Console]::Out.Flush()
  163. # Wait a bit to make sure appveyor shows the error message
  164. Start-Sleep 10
  165. throw
  166. }