build.ps1 5.6 KB

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