build.ps1 7.4 KB

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