build.ps1 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. try {
  2. Write-Host -ForegroundColor Green "`n## Build Path $env:Build_Repository_LocalPath #####`n"
  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" -or $env:CC_SHORTNAME -eq "clang-mingw") {
  13. # Workaround for CMake not wanting sh.exe on PATH for MinGW (necessary for CMake 3.12.2)
  14. $env:PATH = ($env:PATH.Split(';') | Where-Object { $_ -ne 'C:\Program Files\Git\bin' }) -join ';'
  15. $env:PATH = ($env:PATH.Split(';') | Where-Object { $_ -ne 'C:\Program Files\Git\usr\bin' }) -join ';'
  16. # Add mingw to path so that CMake finds e.g. clang
  17. $env:PATH = "$env:MSYS2_ROOT\mingw64\bin;$env:PATH"
  18. [System.Environment]::SetEnvironmentVariable('Path', $path, 'Machine')
  19. }
  20. if ($env:CC_SHORTNAME -eq "mingw") {
  21. } elseif ($env:CC_SHORTNAME -eq "clang-mingw") {
  22. # Setup clang
  23. $env:CC = "clang --target=x86_64-w64-mingw32"
  24. $env:CXX = "clang++ --target=x86_64-w64-mingw32"
  25. clang --version
  26. } else {
  27. $vcpkg_toolchain = '-DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake"'
  28. $vcpkg_triplet = '-DVCPKG_TARGET_TRIPLET="x86-windows-static"'
  29. # since https://github.com/Microsoft/vcpkg/commit/0334365f516c5f229ff4fcf038c7d0190979a38a#diff-464a170117fa96bf98b2f8d224bf503c
  30. # vcpkg need to have "C:\Tools\vcpkg\installed\x86-windows-static"
  31. New-Item -Force -ItemType directory -Path "C:/vcpkg/installed/x86-windows-static"
  32. }
  33. $cmake_cnf="$vcpkg_toolchain", "$vcpkg_triplet", "-G`"$env:GENERATOR`"", "-DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX"
  34. # Collect files for .zip packing
  35. New-Item -ItemType directory -Path pack
  36. Copy-Item LICENSE pack
  37. Copy-Item AUTHORS pack
  38. Copy-Item README.md pack
  39. Write-Host -ForegroundColor Green "`n###################################################################"
  40. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
  41. New-Item -ItemType directory -Path "build"
  42. cd build
  43. & cmake $cmake_cnf `
  44. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  45. -DUA_BUILD_EXAMPLES:BOOL=OFF `
  46. -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  47. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption ..
  48. & cmake --build . --config RelWithDebInfo
  49. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  50. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  51. exit $LASTEXITCODE
  52. }
  53. cd ..
  54. Remove-Item -Path build -Recurse -Force
  55. Write-Host -ForegroundColor Green "`n###################################################################"
  56. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with full NS0 #####`n"
  57. New-Item -ItemType directory -Path "build"
  58. cd build
  59. & cmake $cmake_cnf `
  60. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  61. -DUA_BUILD_EXAMPLES:BOOL=ON `
  62. -DUA_ENABLE_DA:BOOL=ON `
  63. -DUA_ENABLE_JSON_ENCODING:BOOL=ON `
  64. -DUA_ENABLE_PUBSUB:BOOL=ON `
  65. -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  66. -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
  67. -DUA_ENABLE_SUBSCRIPTIONS_EVENTS:BOOL=ON `
  68. -DUA_NAMESPACE_ZERO:STRING=FULL ..
  69. & cmake --build . --config RelWithDebInfo
  70. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  71. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  72. exit $LASTEXITCODE
  73. }
  74. cd ..
  75. Remove-Item -Path build -Recurse -Force
  76. Write-Host -ForegroundColor Green "`n###################################################################"
  77. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME without amalgamation #####`n"
  78. New-Item -ItemType directory -Path "build"
  79. cd build
  80. & cmake $cmake_cnf `
  81. -DBUILD_SHARED_LIBS:BOOL=OFF `
  82. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  83. -DCMAKE_INSTALL_PREFIX="$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-static" `
  84. -DUA_BUILD_EXAMPLES:BOOL=ON `
  85. -DUA_ENABLE_AMALGAMATION:BOOL=OFF ..
  86. & cmake --build . --target install --config RelWithDebInfo
  87. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  88. {
  89. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  90. exit $LASTEXITCODE
  91. }
  92. cd ..
  93. & 7z a -tzip "$env:Build_ArtifactStagingDirectory/open62541-$env:CC_SHORTNAME-static.zip" "$env:Build_Repository_LocalPath\pack\*" "$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-static\*"
  94. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  95. {
  96. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  97. exit $LASTEXITCODE
  98. }
  99. Remove-Item -Path build -Recurse -Force
  100. Write-Host -ForegroundColor Green "`n###################################################################"
  101. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME (.dll) #####`n"
  102. New-Item -ItemType directory -Path "build"
  103. cd build
  104. & cmake $cmake_cnf `
  105. -DBUILD_SHARED_LIBS:BOOL=ON `
  106. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  107. -DCMAKE_INSTALL_PREFIX="$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-dynamic" `
  108. -DUA_BUILD_EXAMPLES:BOOL=ON `
  109. -DUA_ENABLE_AMALGAMATION:BOOL=OFF ..
  110. & cmake --build . --target install --config RelWithDebInfo
  111. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  112. {
  113. Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
  114. exit $LASTEXITCODE
  115. }
  116. cd ..
  117. & 7z a -tzip "$env:Build_ArtifactStagingDirectory/open62541-$env:CC_SHORTNAME-dynamic.zip" "$env:Build_Repository_LocalPath\pack\*" "$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-static\*"
  118. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
  119. {
  120. Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
  121. exit $LASTEXITCODE
  122. }
  123. Remove-Item -Path build -Recurse -Force
  124. # Only execute unit tests on vs2017 to save compilation time
  125. if ($env:CC_SHORTNAME -eq "vs2017") {
  126. Write-Host -ForegroundColor Green "`n###################################################################"
  127. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
  128. New-Item -ItemType directory -Path "build"
  129. cd build
  130. & cmake $cmake_cnf `
  131. -DBUILD_SHARED_LIBS:BOOL=OFF `
  132. -DCMAKE_BUILD_TYPE=Debug `
  133. -DUA_BUILD_EXAMPLES=OFF `
  134. -DUA_BUILD_UNIT_TESTS=ON `
  135. -DUA_ENABLE_DA=ON `
  136. -DUA_ENABLE_DISCOVERY=ON `
  137. -DUA_ENABLE_DISCOVERY_MULTICAST=ON `
  138. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption `
  139. -DUA_ENABLE_JSON_ENCODING:BOOL=ON `
  140. -DUA_ENABLE_PUBSUB:BOOL=ON `
  141. -DUA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON `
  142. -DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
  143. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON ..
  144. & cmake --build . --config Debug
  145. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  146. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  147. exit $LASTEXITCODE
  148. }
  149. & cmake --build . --target test-verbose --config Debug
  150. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  151. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  152. exit $LASTEXITCODE
  153. }
  154. }
  155. # # do not cache log
  156. # Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force
  157. } catch {
  158. # Print a detailed error message
  159. $FullException = ($_.Exception|format-list -force) | Out-String
  160. Write-Host -ForegroundColor Red "`n------------------ Exception ------------------`n$FullException`n"
  161. [Console]::Out.Flush()
  162. # Wait a bit to make sure appveyor shows the error message
  163. Start-Sleep 10
  164. throw
  165. }