build.ps1 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. # Workaround for http://llvm.org/bugs/show_bug.cgi?id=28089
  15. Copy-Item 'C:\Program Files\LLVM' -destination C:\LLVM -recurse
  16. $env:Path = 'C:\LLVM\bin;' + $env:Path
  17. # Setup clang
  18. $env:CC = "clang --target=x86_64-w64-mingw32"
  19. $env:CXX = "clang++ --target=x86_64-w64-mingw32"
  20. clang --version
  21. } else {
  22. $vcpkg_toolchain = '-DCMAKE_TOOLCHAIN_FILE="C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake"'
  23. $vcpkg_triplet = '-DVCPKG_TARGET_TRIPLET="x86-windows-static"'
  24. # since https://github.com/Microsoft/vcpkg/commit/0334365f516c5f229ff4fcf038c7d0190979a38a#diff-464a170117fa96bf98b2f8d224bf503c
  25. # vcpkg need to have "C:\Tools\vcpkg\installed\x86-windows-static"
  26. New-Item -Force -ItemType directory -Path "C:\Tools\vcpkg\installed\x86-windows-static"
  27. }
  28. $make_cmd = "& $env:MAKE"
  29. # Collect files for .zip packing
  30. New-Item -ItemType directory -Path pack
  31. Copy-Item LICENSE pack
  32. Copy-Item AUTHORS pack
  33. Copy-Item README.md pack
  34. # Write-Host -ForegroundColor Green "`n###################################################################"
  35. # Write-Host -ForegroundColor Green "`n##### Building Documentation on $env:CC_NAME #####`n"
  36. # New-Item -ItemType directory -Path build
  37. # cd build
  38. # & cmake -DMIKTEX_BINARY_PATH=c:\miktex\texmfs\install\miktex\bin -DCMAKE_BUILD_TYPE=Release `
  39. # -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DUA_BUILD_EXAMPLES:BOOL=OFF -G"$env:GENERATOR" ..
  40. # & cmake --build . --target doc_latex
  41. # if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  42. # Write-Host -ForegroundColor Red "`n`n*** Make doc_latex. Exiting ... ***"
  43. # exit $LASTEXITCODE
  44. # }
  45. # & cmake --build . --target doc_pdf
  46. # if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  47. # Write-Host -ForegroundColor Red "`n`n*** Make doc_pdf. Exiting ... ***"
  48. # exit $LASTEXITCODE
  49. # }
  50. # cd ..
  51. # Move-Item -Path "build\doc_latex\open62541.pdf" -Destination pack\
  52. # Remove-Item -Path build -Recurse -Force
  53. Write-Host -ForegroundColor Green "`n###################################################################"
  54. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME #####`n"
  55. New-Item -ItemType directory -Path "build"
  56. cd build
  57. & cmake $vcpkg_toolchain $vcpkg_triplet -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX `
  58. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -G"$env:GENERATOR" ..
  59. Invoke-Expression $make_cmd
  60. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  61. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  62. exit $LASTEXITCODE
  63. }
  64. cd ..
  65. Remove-Item -Path build -Recurse -Force
  66. Write-Host -ForegroundColor Green "`n###################################################################"
  67. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with full NS0 #####`n"
  68. New-Item -ItemType directory -Path "build"
  69. cd build
  70. & 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" ..
  71. Invoke-Expression $make_cmd
  72. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  73. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  74. exit $LASTEXITCODE
  75. }
  76. cd ..
  77. Remove-Item -Path build -Recurse -Force
  78. Write-Host -ForegroundColor Green "`n###################################################################"
  79. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with PubSub #####`n"
  80. New-Item -ItemType directory -Path "build"
  81. cd build
  82. & cmake -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_PUBSUB:BOOL=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
  83. -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -G"$env:GENERATOR" ..
  84. Invoke-Expression $make_cmd
  85. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  86. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  87. exit $LASTEXITCODE
  88. }
  89. cd ..
  90. Remove-Item -Path build -Recurse -Force
  91. Write-Host -ForegroundColor Green "`n###################################################################"
  92. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
  93. New-Item -ItemType directory -Path "build"
  94. cd build
  95. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  96. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=OFF -G"$env:GENERATOR" ..
  97. Invoke-Expression $make_cmd
  98. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  99. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  100. exit $LASTEXITCODE
  101. }
  102. cd ..
  103. New-Item -ItemType directory -Path pack_tmp
  104. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  105. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  106. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server_ctt.exe" -Destination pack_tmp\
  107. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  108. if ($env:CC_SHORTNAME -eq "mingw" -or $env:CC_SHORTNAME -eq "clang-mingw") {
  109. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.a" -Destination pack_tmp\
  110. } else {
  111. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.lib" -Destination pack_tmp\
  112. }
  113. & 7z a -tzip open62541-$env:CC_SHORTNAME-static.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  114. Remove-Item -Path pack_tmp -Recurse -Force
  115. Remove-Item -Path build -Recurse -Force
  116. Write-Host -ForegroundColor Green "`n###################################################################"
  117. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation and .dll #####`n"
  118. New-Item -ItemType directory -Path "build"
  119. cd build
  120. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  121. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=ON -G"$env:GENERATOR" ..
  122. Invoke-Expression $make_cmd
  123. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  124. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  125. exit $LASTEXITCODE
  126. }
  127. cd ..
  128. New-Item -ItemType directory -Path pack_tmp
  129. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  130. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  131. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server_ctt.exe" -Destination pack_tmp\
  132. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  133. if ($env:CC_SHORTNAME -eq "mingw" -or $env:CC_SHORTNAME -eq "clang-mingw") {
  134. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll" -Destination pack_tmp\
  135. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll.a" -Destination pack_tmp\
  136. } else {
  137. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.dll" -Destination pack_tmp\
  138. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.pdb" -Destination pack_tmp\
  139. }
  140. & 7z a -tzip open62541-$env:CC_SHORTNAME-dynamic.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  141. Remove-Item -Path pack_tmp -Recurse -Force
  142. Remove-Item -Path build -Recurse -Force
  143. # Only execute unit tests on vs2015 to save compilation time
  144. if ($env:CC_SHORTNAME -eq "vs2015") {
  145. Write-Host -ForegroundColor Green "`n###################################################################"
  146. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
  147. New-Item -ItemType directory -Path "build"
  148. cd build
  149. & cmake $vcpkg_toolchain $vcpkg_triplet -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=OFF -DUA_ENABLE_DISCOVERY=ON `
  150. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -DUA_BUILD_UNIT_TESTS=ON `
  151. -DUA_ENABLE_PUBSUB:BOOL=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  152. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON -DCHECK_PREFIX=c:\check -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -G"$env:CC_NAME" ..
  153. Invoke-Expression $make_cmd
  154. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  155. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  156. exit $LASTEXITCODE
  157. }
  158. & cmake --build . --target test-verbose --config debug
  159. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  160. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  161. exit $LASTEXITCODE
  162. }
  163. }
  164. # # do not cache log
  165. # Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force
  166. } catch {
  167. # Print a detailed error message
  168. $FullException = ($_.Exception|format-list -force) | Out-String
  169. Write-Host -ForegroundColor Red "`n------------------ Exception ------------------`n$FullException`n"
  170. [Console]::Out.Flush()
  171. # Wait a bit to make sure appveyor shows the error message
  172. Start-Sleep 10
  173. throw
  174. }