build.ps1 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. $cmake_cnf="$vcpkg_toolchain", "$vcpkg_triplet", "-G`"$env:GENERATOR`"", "-DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX"
  26. # Collect files for .zip packing
  27. New-Item -ItemType directory -Path pack
  28. Copy-Item LICENSE pack
  29. Copy-Item AUTHORS pack
  30. Copy-Item README.md pack
  31. Write-Host -ForegroundColor Green "`n###################################################################"
  32. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
  33. New-Item -ItemType directory -Path "build"
  34. cd build
  35. & cmake $cmake_cnf `
  36. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  37. -DUA_BUILD_EXAMPLES:BOOL=OFF `
  38. -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  39. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption ..
  40. & cmake --build . --config RelWithDebInfo
  41. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  42. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  43. exit $LASTEXITCODE
  44. }
  45. cd ..
  46. Remove-Item -Path build -Recurse -Force
  47. Write-Host -ForegroundColor Green "`n###################################################################"
  48. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with full NS0 #####`n"
  49. New-Item -ItemType directory -Path "build"
  50. cd build
  51. & cmake $cmake_cnf `
  52. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  53. -DUA_BUILD_EXAMPLES:BOOL=ON `
  54. -DUA_ENABLE_DA:BOOL=ON `
  55. -DUA_ENABLE_JSON_ENCODING:BOOL=ON `
  56. -DUA_ENABLE_PUBSUB:BOOL=ON `
  57. -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  58. -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
  59. -DUA_ENABLE_SUBSCRIPTIONS_EVENTS:BOOL=ON `
  60. -DUA_NAMESPACE_ZERO:STRING=FULL ..
  61. & cmake --build . --config RelWithDebInfo
  62. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  63. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  64. exit $LASTEXITCODE
  65. }
  66. cd ..
  67. Remove-Item -Path build -Recurse -Force
  68. Write-Host -ForegroundColor Green "`n###################################################################"
  69. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME without amalgamation #####`n"
  70. New-Item -ItemType directory -Path "build"
  71. cd build
  72. & cmake $cmake_cnf `
  73. -DBUILD_SHARED_LIBS:BOOL=OFF `
  74. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  75. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  76. -DCMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-static" `
  77. -DUA_BUILD_EXAMPLES:BOOL=ON `
  78. -DUA_ENABLE_AMALGAMATION:BOOL=OFF ..
  79. & cmake --build . --target install --config RelWithDebInfo
  80. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  81. {
  82. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  83. exit $LASTEXITCODE
  84. }
  85. cd ..
  86. & 7z a -tzip open62541-$env:CC_SHORTNAME-static.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-static\*"
  87. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  88. {
  89. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  90. exit $LASTEXITCODE
  91. }
  92. Remove-Item -Path build -Recurse -Force
  93. Write-Host -ForegroundColor Green "`n###################################################################"
  94. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME (.dll) #####`n"
  95. New-Item -ItemType directory -Path "build"
  96. cd build
  97. & cmake $cmake_cnf `
  98. -DBUILD_SHARED_LIBS:BOOL=ON `
  99. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  100. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  101. -DCMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-dynamic" `
  102. -DUA_BUILD_EXAMPLES:BOOL=ON `
  103. -DUA_ENABLE_AMALGAMATION:BOOL=OFF ..
  104. & cmake --build . --target install --config RelWithDebInfo
  105. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  106. {
  107. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  108. exit $LASTEXITCODE
  109. }
  110. cd ..
  111. & 7z a -tzip open62541-$env:CC_SHORTNAME-dynamic.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER-$env:CC_SHORTNAME-static\*"
  112. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  113. {
  114. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  115. exit $LASTEXITCODE
  116. }
  117. Remove-Item -Path build -Recurse -Force
  118. # Only execute unit tests on vs2017 to save compilation time
  119. if ($env:CC_SHORTNAME -eq "vs2017") {
  120. Write-Host -ForegroundColor Green "`n###################################################################"
  121. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
  122. New-Item -ItemType directory -Path "build"
  123. cd build
  124. & cmake $cmake_cnf `
  125. -DCHECK_PREFIX=c:\check `
  126. -DCMAKE_BUILD_TYPE=Debug `
  127. -DUA_BUILD_EXAMPLES=OFF `
  128. -DUA_BUILD_UNIT_TESTS=ON `
  129. -DUA_ENABLE_DA=ON `
  130. -DUA_ENABLE_DISCOVERY=ON `
  131. -DUA_ENABLE_DISCOVERY_MULTICAST=ON `
  132. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption `
  133. -DUA_ENABLE_JSON_ENCODING:BOOL=ON `
  134. -DUA_ENABLE_PUBSUB:BOOL=ON `
  135. -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  136. -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
  137. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON ..
  138. & cmake --build . --config Debug
  139. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  140. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  141. exit $LASTEXITCODE
  142. }
  143. & cmake --build . --target test-verbose --config debug
  144. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  145. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  146. exit $LASTEXITCODE
  147. }
  148. }
  149. # # do not cache log
  150. # Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force
  151. } catch {
  152. # Print a detailed error message
  153. $FullException = ($_.Exception|format-list -force) | Out-String
  154. Write-Host -ForegroundColor Red "`n------------------ Exception ------------------`n$FullException`n"
  155. [Console]::Out.Flush()
  156. # Wait a bit to make sure appveyor shows the error message
  157. Start-Sleep 10
  158. throw
  159. }