build.ps1 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_NAMESPACE_ZERO:STRING=FULL ..
  53. & cmake --build . --config RelWithDebInfo
  54. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  55. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  56. exit $LASTEXITCODE
  57. }
  58. cd ..
  59. Remove-Item -Path build -Recurse -Force
  60. Write-Host -ForegroundColor Green "`n###################################################################"
  61. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME without amalgamation #####`n"
  62. New-Item -ItemType directory -Path "build"
  63. cd build
  64. & cmake $cmake_cnf `
  65. -DBUILD_SHARED_LIBS:BOOL=OFF `
  66. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  67. -DCMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-static" `
  68. -DUA_BUILD_EXAMPLES:BOOL=ON `
  69. -DUA_ENABLE_AMALGAMATION:BOOL=OFF ..
  70. & cmake --build . --target install --config RelWithDebInfo
  71. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  72. {
  73. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  74. exit $LASTEXITCODE
  75. }
  76. cd ..
  77. & 7z a -tzip open62541-$env:CC_SHORTNAME-static.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-static\*"
  78. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  79. {
  80. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  81. exit $LASTEXITCODE
  82. }
  83. Remove-Item -Path build -Recurse -Force
  84. Write-Host -ForegroundColor Green "`n###################################################################"
  85. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME (.dll) #####`n"
  86. New-Item -ItemType directory -Path "build"
  87. cd build
  88. & cmake $cmake_cnf `
  89. -DBUILD_SHARED_LIBS:BOOL=ON `
  90. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  91. -DCMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-dynamic" `
  92. -DUA_BUILD_EXAMPLES:BOOL=ON `
  93. -DUA_ENABLE_AMALGAMATION:BOOL=OFF ..
  94. & cmake --build . --target install --config RelWithDebInfo
  95. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  96. {
  97. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  98. exit $LASTEXITCODE
  99. }
  100. cd ..
  101. & 7z a -tzip open62541-$env:CC_SHORTNAME-dynamic.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-static\*"
  102. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  103. {
  104. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  105. exit $LASTEXITCODE
  106. }
  107. Remove-Item -Path build -Recurse -Force
  108. # # do not cache log
  109. # Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force
  110. } catch {
  111. # Print a detailed error message
  112. $FullException = ($_.Exception|format-list -force) | Out-String
  113. Write-Host -ForegroundColor Red "`n------------------ Exception ------------------`n$FullException`n"
  114. [Console]::Out.Flush()
  115. # Wait a bit to make sure appveyor shows the error message
  116. Start-Sleep 10
  117. throw
  118. }