build.ps1 9.0 KB

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