build.ps1 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. $ErrorActionPreference = "Stop"
  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. }
  17. $make_cmd = "& $env:MAKE"
  18. # Collect files for .zip packing
  19. New-Item -ItemType directory -Path pack
  20. Copy-Item LICENSE pack
  21. Copy-Item AUTHORS pack
  22. Copy-Item README.md pack
  23. Write-Host -ForegroundColor Green "`n###################################################################"
  24. Write-Host -ForegroundColor Green "`n##### Building Documentation on $env:CC_NAME #####`n"
  25. New-Item -ItemType directory -Path build
  26. cd build
  27. & cmake -DMIKTEX_BINARY_PATH=c:\miktex\texmfs\install\miktex\bin -DCMAKE_BUILD_TYPE=Release `
  28. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DUA_BUILD_EXAMPLES:BOOL=OFF -G"$env:CC_NAME" ..
  29. & cmake --build . --target doc_latex
  30. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  31. Write-Host -ForegroundColor Red "`n`n*** Make doc_latex. Exiting ... ***"
  32. exit $LASTEXITCODE
  33. }
  34. & cmake --build . --target doc_pdf
  35. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  36. Write-Host -ForegroundColor Red "`n`n*** Make doc_pdf. Exiting ... ***"
  37. exit $LASTEXITCODE
  38. }
  39. cd ..
  40. Move-Item -Path "build\doc_latex\open62541.pdf" -Destination pack\
  41. Remove-Item -Path build -Recurse -Force
  42. Write-Host -ForegroundColor Green "`n###################################################################"
  43. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME #####`n"
  44. New-Item -ItemType directory -Path "build"
  45. cd build
  46. & cmake $vcpkg_toolchain $vcpkg_triplet -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX `
  47. -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -G"$env:CC_NAME" ..
  48. Invoke-Expression $make_cmd
  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 -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_FULL_NS0:BOOL=ON -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -G"$env:CC_NAME" ..
  60. Invoke-Expression $make_cmd
  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 with amalgamation #####`n"
  69. New-Item -ItemType directory -Path "build"
  70. cd build
  71. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  72. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=OFF -G"$env:CC_NAME" ..
  73. Invoke-Expression $make_cmd
  74. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  75. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  76. exit $LASTEXITCODE
  77. }
  78. cd ..
  79. New-Item -ItemType directory -Path pack_tmp
  80. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  81. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  82. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server.exe" -Destination pack_tmp\
  83. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  84. if ($env:CC_SHORTNAME -eq "mingw") {
  85. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.a" -Destination pack_tmp\
  86. } else {
  87. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.lib" -Destination pack_tmp\
  88. }
  89. & 7z a -tzip open62541-$env:CC_SHORTNAME-static.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  90. Remove-Item -Path pack_tmp -Recurse -Force
  91. Remove-Item -Path build -Recurse -Force
  92. Write-Host -ForegroundColor Green "`n###################################################################"
  93. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation and .dll #####`n"
  94. New-Item -ItemType directory -Path "build"
  95. cd build
  96. & cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES:BOOL=ON -DUA_ENABLE_AMALGAMATION:BOOL=ON `
  97. -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -DBUILD_SHARED_LIBS:BOOL=ON -G"$env:CC_NAME" ..
  98. Invoke-Expression $make_cmd
  99. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  100. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  101. exit $LASTEXITCODE
  102. }
  103. cd ..
  104. New-Item -ItemType directory -Path pack_tmp
  105. Move-Item -Path "build\open62541.c" -Destination pack_tmp\
  106. Move-Item -Path "build\open62541.h" -Destination pack_tmp\
  107. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\server.exe" -Destination pack_tmp\
  108. Move-Item -Path "build\$env:OUT_DIR_EXAMPLES\client.exe" -Destination pack_tmp\
  109. if ($env:CC_SHORTNAME -eq "mingw") {
  110. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll" -Destination pack_tmp\
  111. Move-Item -Path "build\$env:OUT_DIR_LIB\libopen62541.dll.a" -Destination pack_tmp\
  112. } else {
  113. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.dll" -Destination pack_tmp\
  114. Move-Item -Path "build\$env:OUT_DIR_LIB\open62541.pdb" -Destination pack_tmp\
  115. }
  116. & 7z a -tzip open62541-$env:CC_SHORTNAME-dynamic.zip "$env:APPVEYOR_BUILD_FOLDER\pack\*" "$env:APPVEYOR_BUILD_FOLDER\pack_tmp\*"
  117. Remove-Item -Path pack_tmp -Recurse -Force
  118. Remove-Item -Path build -Recurse -Force
  119. # Only execute unit tests on vs2015 to save compilation time
  120. if ($env:CC_SHORTNAME -eq "vs2015") {
  121. Write-Host -ForegroundColor Green "`n###################################################################"
  122. Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
  123. New-Item -ItemType directory -Path "build"
  124. cd build
  125. & cmake $vcpkg_toolchain $vcpkg_triplet -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=OFF -DUA_ENABLE_DISCOVERY=ON `
  126. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_ENABLE_ENCRYPTION:BOOL=$build_encryption -DUA_BUILD_UNIT_TESTS=ON `
  127. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON -DCHECK_PREFIX=c:\check -DUA_COMPILE_AS_CXX:BOOL=$env:FORCE_CXX -G"$env:CC_NAME" ..
  128. Invoke-Expression $make_cmd
  129. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  130. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  131. exit $LASTEXITCODE
  132. }
  133. & cmake --build . --target test-verbose --config debug
  134. if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
  135. Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
  136. exit $LASTEXITCODE
  137. }
  138. }
  139. # do not cache log
  140. Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force