build.ps1 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. $make_cmd = "& $env:MAKE"
  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 #####`n"
  33. New-Item -ItemType directory -Path "build"
  34. cd build
  35. & cmake $vcpkg_toolchain $vcpkg_triplet -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX `
  36. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -G"$env:GENERATOR" ..
  37. Invoke-Expression $make_cmd
  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 -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -G"$env:GENERATOR" ..
  49. Invoke-Expression $make_cmd
  50. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  51. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  52. exit $LASTEXITCODE
  53. }
  54. cd ..
  55. Remove-Item -Path build -Recurse -Force
  56. Write-Host -ForegroundColor Green "`n###################################################################"
  57. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with PubSub #####`n"
  58. New-Item -ItemType directory -Path "build"
  59. cd build
  60. & cmake -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_PUBSUB:BOOL=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
  61. -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -G"$env:GENERATOR" ..
  62. Invoke-Expression $make_cmd
  63. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  64. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  65. exit $LASTEXITCODE
  66. }
  67. cd ..
  68. Remove-Item -Path build -Recurse -Force
  69. Write-Host -ForegroundColor Green "`n###################################################################"
  70. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
  71. New-Item -ItemType directory -Path "build"
  72. cd build
  73. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  74. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=OFF -G"$env:GENERATOR" ..
  75. Invoke-Expression $make_cmd
  76. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  77. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  78. exit $LASTEXITCODE
  79. }
  80. cd ..
  81. New-Item -ItemType directory -Path pack_tmp
  82. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  83. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  84. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server_ctt.exe" -Destination pack_tmp\
  85. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  86. if ($env:CC_SHORTNAME -eq "mingw" -or $env:CC_SHORTNAME -eq "clang-mingw") {
  87. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.a" -Destination pack_tmp\
  88. } else {
  89. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.lib" -Destination pack_tmp\
  90. }
  91. & 7z a -tzip open62541-$env:CC_SHORTNAME-static.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  92. Remove-Item -Path pack_tmp -Recurse -Force
  93. Remove-Item -Path build -Recurse -Force
  94. Write-Host -ForegroundColor Green "`n###################################################################"
  95. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation and .dll #####`n"
  96. New-Item -ItemType directory -Path "build"
  97. cd build
  98. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  99. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=ON -G"$env:GENERATOR" ..
  100. Invoke-Expression $make_cmd
  101. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  102. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  103. exit $LASTEXITCODE
  104. }
  105. cd ..
  106. New-Item -ItemType directory -Path pack_tmp
  107. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  108. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  109. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server_ctt.exe" -Destination pack_tmp\
  110. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  111. if ($env:CC_SHORTNAME -eq "mingw" -or $env:CC_SHORTNAME -eq "clang-mingw") {
  112. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll" -Destination pack_tmp\
  113. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll.a" -Destination pack_tmp\
  114. } else {
  115. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.dll" -Destination pack_tmp\
  116. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.pdb" -Destination pack_tmp\
  117. }
  118. & 7z a -tzip open62541-$env:CC_SHORTNAME-dynamic.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  119. Remove-Item -Path pack_tmp -Recurse -Force
  120. Remove-Item -Path build -Recurse -Force
  121. # Only execute unit tests on vs2017 to save compilation time
  122. if ($env:CC_SHORTNAME -eq "vs2017") {
  123. Write-Host -ForegroundColor Green "`n###################################################################"
  124. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
  125. New-Item -ItemType directory -Path "build"
  126. cd build
  127. & cmake $vcpkg_toolchain $vcpkg_triplet -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=OFF -DUA_ENABLE_DISCOVERY=ON `
  128. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -DUA_BUILD_UNIT_TESTS=ON `
  129. -DUA_ENABLE_PUBSUB:BOOL=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  130. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON -DCHECK_PREFIX=c:\check -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -G"$env:CC_NAME" ..
  131. Invoke-Expression $make_cmd
  132. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  133. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  134. exit $LASTEXITCODE
  135. }
  136. & cmake --build . --target test-verbose --config debug
  137. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  138. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  139. exit $LASTEXITCODE
  140. }
  141. }
  142. # # do not cache log
  143. # Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force
  144. } catch {
  145. # Print a detailed error message
  146. $FullException = ($_.Exception|format-list -force) | Out-String
  147. Write-Host -ForegroundColor Red "`n------------------ Exception ------------------`n$FullException`n"
  148. [Console]::Out.Flush()
  149. # Wait a bit to make sure appveyor shows the error message
  150. Start-Sleep 10
  151. throw
  152. }