build.ps1 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. } else {
  14. $vcpkg_toolchain = '-DCMAKE_TOOLCHAIN_FILE="C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake"'
  15. $vcpkg_triplet = '-DVCPKG_TARGET_TRIPLET="x86-windows-static"'
  16. # since https://github.com/Microsoft/vcpkg/commit/0334365f516c5f229ff4fcf038c7d0190979a38a#diff-464a170117fa96bf98b2f8d224bf503c
  17. # vcpkg need to have "C:\Tools\vcpkg\installed\x86-windows-static"
  18. New-Item -Force -ItemType directory -Path "C:\Tools\vcpkg\installed\x86-windows-static"
  19. }
  20. $make_cmd = "& $env:MAKE"
  21. # Collect files for .zip packing
  22. New-Item -ItemType directory -Path pack
  23. Copy-Item LICENSE pack
  24. Copy-Item AUTHORS pack
  25. Copy-Item README.md pack
  26. Write-Host -ForegroundColor Green "`n###################################################################"
  27. Write-Host -ForegroundColor Green "`n##### Building Documentation on $env:CC_NAME #####`n"
  28. New-Item -ItemType directory -Path build
  29. cd build
  30. & cmake -DMIKTEX_BINARY_PATH=c:\miktex\texmfs\install\miktex\bin -DCMAKE_BUILD_TYPE=Release `
  31. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DUA_BUILD_EXAMPLES:BOOL=OFF -G"$env:CC_NAME" ..
  32. & cmake --build . --target doc_latex
  33. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  34. Write-Host -ForegroundColor Red "`n`n*** Make doc_latex. Exiting ... ***"
  35. exit $LASTEXITCODE
  36. }
  37. & cmake --build . --target doc_pdf
  38. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  39. Write-Host -ForegroundColor Red "`n`n*** Make doc_pdf. Exiting ... ***"
  40. exit $LASTEXITCODE
  41. }
  42. cd ..
  43. Move-Item -Path "build\doc_latex\open62541.pdf" -Destination pack\
  44. Remove-Item -Path build -Recurse -Force
  45. Write-Host -ForegroundColor Green "`n###################################################################"
  46. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME #####`n"
  47. New-Item -ItemType directory -Path "build"
  48. cd build
  49. & cmake $vcpkg_toolchain $vcpkg_triplet -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX `
  50. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -G"$env:CC_NAME" ..
  51. Invoke-Expression $make_cmd
  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 with full NS0 #####`n"
  60. New-Item -ItemType directory -Path "build"
  61. cd build
  62. & 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:CC_NAME" ..
  63. Invoke-Expression $make_cmd
  64. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  65. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  66. exit $LASTEXITCODE
  67. }
  68. cd ..
  69. Remove-Item -Path build -Recurse -Force
  70. Write-Host -ForegroundColor Green "`n###################################################################"
  71. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
  72. New-Item -ItemType directory -Path "build"
  73. cd build
  74. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  75. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=OFF -G"$env:CC_NAME" ..
  76. Invoke-Expression $make_cmd
  77. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  78. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  79. exit $LASTEXITCODE
  80. }
  81. cd ..
  82. New-Item -ItemType directory -Path pack_tmp
  83. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  84. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  85. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server_ctt.exe" -Destination pack_tmp\
  86. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  87. if ($env:CC_SHORTNAME -eq "mingw") {
  88. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.a" -Destination pack_tmp\
  89. } else {
  90. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.lib" -Destination pack_tmp\
  91. }
  92. & 7z a -tzip open62541-$env:CC_SHORTNAME-static.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  93. Remove-Item -Path pack_tmp -Recurse -Force
  94. Remove-Item -Path build -Recurse -Force
  95. Write-Host -ForegroundColor Green "`n###################################################################"
  96. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation and .dll #####`n"
  97. New-Item -ItemType directory -Path "build"
  98. cd build
  99. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  100. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=ON -G"$env:CC_NAME" ..
  101. Invoke-Expression $make_cmd
  102. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  103. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  104. exit $LASTEXITCODE
  105. }
  106. cd ..
  107. New-Item -ItemType directory -Path pack_tmp
  108. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  109. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  110. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server_ctt.exe" -Destination pack_tmp\
  111. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  112. if ($env:CC_SHORTNAME -eq "mingw") {
  113. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll" -Destination pack_tmp\
  114. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll.a" -Destination pack_tmp\
  115. } else {
  116. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.dll" -Destination pack_tmp\
  117. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.pdb" -Destination pack_tmp\
  118. }
  119. & 7z a -tzip open62541-$env:CC_SHORTNAME-dynamic.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  120. Remove-Item -Path pack_tmp -Recurse -Force
  121. Remove-Item -Path build -Recurse -Force
  122. # Only execute unit tests on vs2015 to save compilation time
  123. if ($env:CC_SHORTNAME -eq "vs2015") {
  124. Write-Host -ForegroundColor Green "`n###################################################################"
  125. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
  126. New-Item -ItemType directory -Path "build"
  127. cd build
  128. & cmake $vcpkg_toolchain $vcpkg_triplet -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=OFF -DUA_ENABLE_DISCOVERY=ON `
  129. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -DUA_BUILD_UNIT_TESTS=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. }