build.ps1 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. try {
  2. cd $env:APPVEYOR_BUILD_FOLDER
  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") {
  13. } elseif ($env:CC_SHORTNAME -eq "clang-mingw") {
  14. # Setup clang
  15. $env:CC = "clang --target=x86_64-w64-mingw32"
  16. $env:CXX = "clang++ --target=x86_64-w64-mingw32"
  17. clang --version
  18. } else {
  19. $vcpkg_toolchain = '-DCMAKE_TOOLCHAIN_FILE="C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake"'
  20. $vcpkg_triplet = '-DVCPKG_TARGET_TRIPLET="x86-windows-static"'
  21. # since https://github.com/Microsoft/vcpkg/commit/0334365f516c5f229ff4fcf038c7d0190979a38a#diff-464a170117fa96bf98b2f8d224bf503c
  22. # vcpkg need to have "C:\Tools\vcpkg\installed\x86-windows-static"
  23. New-Item -Force -ItemType directory -Path "C:\Tools\vcpkg\installed\x86-windows-static"
  24. }
  25. # Collect files for .zip packing
  26. New-Item -ItemType directory -Path pack
  27. Copy-Item LICENSE pack
  28. Copy-Item AUTHORS pack
  29. Copy-Item README.md pack
  30. Write-Host -ForegroundColor Green "`n###################################################################"
  31. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
  32. New-Item -ItemType directory -Path "build"
  33. cd build
  34. & cmake $vcpkg_toolchain $vcpkg_triplet -DUA_BUILD_EXAMPLES:BOOL=OFF -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  35. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX `
  36. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -DCMAKE_BUILD_TYPE=RelWithDebInfo -G"$env:GENERATOR" ..
  37. & cmake --build . --config RelWithDebInfo
  38. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  39. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  40. exit $LASTEXITCODE
  41. }
  42. cd ..
  43. Remove-Item -Path build -Recurse -Force
  44. Write-Host -ForegroundColor Green "`n###################################################################"
  45. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with full NS0 #####`n"
  46. New-Item -ItemType directory -Path "build"
  47. cd build
  48. & cmake -DUA_ENABLE_SUBSCRIPTIONS_EVENTS:BOOL=ON -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_NAMESPACE_ZERO:STRING=FULL `
  49. -DUA_ENABLE_PUBSUB:BOOL=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  50. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DCMAKE_BUILD_TYPE=RelWithDebInfo -G"$env:GENERATOR" ..
  51. & cmake --build . --config RelWithDebInfo
  52. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  53. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  54. exit $LASTEXITCODE
  55. }
  56. cd ..
  57. Remove-Item -Path build -Recurse -Force
  58. Write-Host -ForegroundColor Green "`n###################################################################"
  59. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME without amalgamation #####`n"
  60. New-Item -ItemType directory -Path "build"
  61. cd build
  62. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=OFF `
  63. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  64. -G"$env:GENERATOR" `
  65. -DCMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-static" ..
  66. & cmake --build . --target install --config RelWithDebInfo
  67. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  68. {
  69. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  70. exit $LASTEXITCODE
  71. }
  72. cd ..
  73. & 7z a -tzip open62541-$env:CC_SHORTNAME-static.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-static\*"
  74. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  75. {
  76. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  77. exit $LASTEXITCODE
  78. }
  79. Remove-Item -Path build -Recurse -Force
  80. Write-Host -ForegroundColor Green "`n###################################################################"
  81. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME (.dll) #####`n"
  82. New-Item -ItemType directory -Path "build"
  83. cd build
  84. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=OFF `
  85. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  86. -G"$env:GENERATOR" `
  87. -DCMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-dynamic" ..
  88. & cmake --build . --target install --config RelWithDebInfo
  89. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  90. {
  91. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  92. exit $LASTEXITCODE
  93. }
  94. cd ..
  95. & 7z a -tzip open62541-$env:CC_SHORTNAME-dynamic.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-static\*"
  96. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  97. {
  98. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  99. exit $LASTEXITCODE
  100. }
  101. Remove-Item -Path build -Recurse -Force
  102. # Only execute unit tests on vs2017 to save compilation time
  103. if ($env:CC_SHORTNAME -eq "vs2017") {
  104. Write-Host -ForegroundColor Green "`n###################################################################"
  105. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
  106. New-Item -ItemType directory -Path "build"
  107. cd build
  108. & cmake $vcpkg_toolchain $vcpkg_triplet -DUA_BUILD_EXAMPLES=OFF -DUA_ENABLE_DISCOVERY=ON `
  109. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -DUA_BUILD_UNIT_TESTS=ON `
  110. -DUA_ENABLE_PUBSUB:BOOL=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  111. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON -DCHECK_PREFIX=c:\check -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX `
  112. -DCMAKE_BUILD_TYPE=Debug -G"$env:CC_NAME" ..
  113. & cmake --build . --config Debug
  114. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  115. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  116. exit $LASTEXITCODE
  117. }
  118. & cmake --build . --target test-verbose --config debug
  119. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  120. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  121. exit $LASTEXITCODE
  122. }
  123. }
  124. # # do not cache log
  125. # Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force
  126. } catch {
  127. # Print a detailed error message
  128. $FullException = ($_.Exception|format-list -force) | Out-String
  129. Write-Host -ForegroundColor Red "`n------------------ Exception ------------------`n$FullException`n"
  130. [Console]::Out.Flush()
  131. # Wait a bit to make sure appveyor shows the error message
  132. Start-Sleep 10
  133. throw
  134. }