build.ps1 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. $ErrorActionPreference = "Stop"
  2. try {
  3. cd $env:APPVEYOR_BUILD_FOLDER
  4. $vcpkg_toolchain = ""
  5. $vcpkg_triplet = ""
  6. if ($env:CC_SHORTNAME -eq "vs2008" -or $env:CC_SHORTNAME -eq "vs2013") {
  7. # on VS2008 mbedtls can not be built since it includes stdint.h which is not available there
  8. $build_encryption = "OFF"
  9. Write-Host -ForegroundColor Green "`n## Building without encryption on VS2008 or VS2013 #####`n"
  10. } else {
  11. $build_encryption = "ON"
  12. }
  13. if ($env:CC_SHORTNAME -eq "mingw") {
  14. } else {
  15. $vcpkg_toolchain = '-DCMAKE_TOOLCHAIN_FILE="C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake"'
  16. $vcpkg_triplet = '-DVCPKG_TARGET_TRIPLET="x86-windows-static"'
  17. # since https://github.com/Microsoft/vcpkg/commit/0334365f516c5f229ff4fcf038c7d0190979a38a#diff-464a170117fa96bf98b2f8d224bf503c
  18. # vcpkg need to have "C:\Tools\vcpkg\installed\x86-windows-static"
  19. New-Item -Force -ItemType directory -Path "C:\Tools\vcpkg\installed\x86-windows-static"
  20. }
  21. $make_cmd = "& $env:MAKE"
  22. # Collect files for .zip packing
  23. New-Item -ItemType directory -Path pack
  24. Copy-Item LICENSE pack
  25. Copy-Item AUTHORS pack
  26. Copy-Item README.md pack
  27. Write-Host -ForegroundColor Green "`n###################################################################"
  28. Write-Host -ForegroundColor Green "`n##### Building Documentation on $env:CC_NAME #####`n"
  29. New-Item -ItemType directory -Path build
  30. cd build
  31. & cmake -DMIKTEX_BINARY_PATH=c:\miktex\texmfs\install\miktex\bin -DCMAKE_BUILD_TYPE=Release `
  32. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DUA_BUILD_EXAMPLES:BOOL=OFF -G"$env:CC_NAME" ..
  33. & cmake --build . --target doc_latex
  34. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  35. Write-Host -ForegroundColor Red "`n`n*** Make doc_latex. Exiting ... ***"
  36. exit $LASTEXITCODE
  37. }
  38. & cmake --build . --target doc_pdf
  39. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  40. Write-Host -ForegroundColor Red "`n`n*** Make doc_pdf. Exiting ... ***"
  41. exit $LASTEXITCODE
  42. }
  43. cd ..
  44. Move-Item -Path "build\doc_latex\open62541.pdf" -Destination pack\
  45. Remove-Item -Path build -Recurse -Force
  46. Write-Host -ForegroundColor Green "`n###################################################################"
  47. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME #####`n"
  48. New-Item -ItemType directory -Path "build"
  49. cd build
  50. & cmake $vcpkg_toolchain $vcpkg_triplet -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX `
  51. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -G"$env:CC_NAME" ..
  52. Invoke-Expression $make_cmd
  53. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  54. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  55. exit $LASTEXITCODE
  56. }
  57. cd ..
  58. Remove-Item -Path build -Recurse -Force
  59. Write-Host -ForegroundColor Green "`n###################################################################"
  60. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with full NS0 #####`n"
  61. New-Item -ItemType directory -Path "build"
  62. cd build
  63. & cmake -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_FULL_NS0:BOOL=ON -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -G"$env:CC_NAME" ..
  64. Invoke-Expression $make_cmd
  65. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  66. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  67. exit $LASTEXITCODE
  68. }
  69. cd ..
  70. Remove-Item -Path build -Recurse -Force
  71. Write-Host -ForegroundColor Green "`n###################################################################"
  72. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
  73. New-Item -ItemType directory -Path "build"
  74. cd build
  75. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  76. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=OFF -G"$env:CC_NAME" ..
  77. Invoke-Expression $make_cmd
  78. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  79. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  80. exit $LASTEXITCODE
  81. }
  82. cd ..
  83. New-Item -ItemType directory -Path pack_tmp
  84. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  85. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  86. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server_ctt.exe" -Destination pack_tmp\
  87. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  88. if ($env:CC_SHORTNAME -eq "mingw") {
  89. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.a" -Destination pack_tmp\
  90. } else {
  91. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.lib" -Destination pack_tmp\
  92. }
  93. & 7z a -tzip open62541-$env:CC_SHORTNAME-static.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  94. Remove-Item -Path pack_tmp -Recurse -Force
  95. Remove-Item -Path build -Recurse -Force
  96. Write-Host -ForegroundColor Green "`n###################################################################"
  97. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation and .dll #####`n"
  98. New-Item -ItemType directory -Path "build"
  99. cd build
  100. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  101. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=ON -G"$env:CC_NAME" ..
  102. Invoke-Expression $make_cmd
  103. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  104. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  105. exit $LASTEXITCODE
  106. }
  107. cd ..
  108. New-Item -ItemType directory -Path pack_tmp
  109. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  110. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  111. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server_ctt.exe" -Destination pack_tmp\
  112. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  113. if ($env:CC_SHORTNAME -eq "mingw") {
  114. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll" -Destination pack_tmp\
  115. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll.a" -Destination pack_tmp\
  116. } else {
  117. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.dll" -Destination pack_tmp\
  118. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.pdb" -Destination pack_tmp\
  119. }
  120. & 7z a -tzip open62541-$env:CC_SHORTNAME-dynamic.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  121. Remove-Item -Path pack_tmp -Recurse -Force
  122. Remove-Item -Path build -Recurse -Force
  123. # Only execute unit tests on vs2015 to save compilation time
  124. if ($env:CC_SHORTNAME -eq "vs2015") {
  125. Write-Host -ForegroundColor Green "`n###################################################################"
  126. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
  127. New-Item -ItemType directory -Path "build"
  128. cd build
  129. & cmake $vcpkg_toolchain $vcpkg_triplet -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=OFF -DUA_ENABLE_DISCOVERY=ON `
  130. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -DUA_BUILD_UNIT_TESTS=ON `
  131. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON -DCHECK_PREFIX=c:\check -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -G"$env:CC_NAME" ..
  132. Invoke-Expression $make_cmd
  133. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  134. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  135. exit $LASTEXITCODE
  136. }
  137. & cmake --build . --target test-verbose --config debug
  138. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  139. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  140. exit $LASTEXITCODE
  141. }
  142. }
  143. # do not cache log
  144. Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force
  145. } catch {
  146. # Print a detailed error message
  147. $FullException = ($_.Exception|format-list -force) | Out-String
  148. Write-Host -ForegroundColor Red "`n------------------ Exception ------------------`n$FullException`n"
  149. [Console]::Out.Flush()
  150. # Wait a bit to make sure appveyor shows the error message
  151. Start-Sleep 10
  152. throw
  153. }