You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unix-build 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #!/bin/bash
  2. # This is the build script to configure and build OpenViBE on
  3. # unix-based platform.
  4. # Functions definition
  5. function usage()
  6. {
  7. echo "usage: ./unix-build [options]"
  8. echo ""
  9. echo "-h | --help : usage"
  10. echo "-v | --verbose : verbose output at building step"
  11. echo "--build-type <Debug|Release|RelWithDebInfo> : build type"
  12. echo "--build-dir <dirname> : build directory"
  13. echo "--install-dir <dirname> : binaries deployment directory"
  14. echo "--dependencies-dir <dirname> : directory where dependencies are located"
  15. echo "--test-data-dir <dirname> : test data directory"
  16. echo "--make-package : a package will be created in build directory"
  17. echo "--hide-error-location : do not display complete error locations"
  18. echo "--userdata-subdir <dirname> name of the userdata sub directory"
  19. echo "--brand-name <brand-name> name of the brand to prefix titles and documentation"
  20. echo "--build-unit : if set, unit tests will be built"
  21. echo "--build-validation : if set, validation tests will be builts"
  22. echo "--gtest-lib-dir <dirname> : gtest libraries directory (default: \$\{dependencies_dir\}/libgtest)"
  23. echo "--gtest-include-dir <dirname> : gtest include directory (default: /usr/src/gtest/src)"
  24. echo "--test-output-dir <dirname> : test output files directory"
  25. echo "--python-exec <path> : path to python executable to use"
  26. }
  27. # Script starting point
  28. # As options are not mandatory, set some default values for each target
  29. # variables
  30. ov_script_dir="$(readlink -m $(dirname $0))"
  31. ov_build_type=Release
  32. verbose=0
  33. package_option="FALSE"
  34. display_error_location="ON"
  35. BrandName=OpenViBE
  36. ov_build_unit=0
  37. ov_build_validation=0
  38. gtest_include_dir="/usr/src/gtest/src"
  39. # Parse arguments
  40. while [[ $# -gt 0 ]]; do
  41. key="$1"
  42. case $key in
  43. -h | --help)
  44. usage
  45. exit
  46. ;;
  47. -v | --verbose)
  48. verbose=1
  49. ;;
  50. --build-type)
  51. ov_build_type="$2"
  52. shift
  53. ;;
  54. --build-dir)
  55. ov_build_dir="$2"
  56. shift
  57. ;;
  58. --install-dir)
  59. ov_install_dir="$2"
  60. shift
  61. ;;
  62. --dependencies-dir)
  63. dependencies_dir_token="-DOV_CUSTOM_DEPENDENCIES_PATH=$2"
  64. dependencies_dir=$2
  65. shift
  66. ;;
  67. --test-data-dir)
  68. ov_test_data_dir_token="-DOVT_TEST_DATA_DIR=$2"
  69. shift
  70. ;;
  71. --make-package)
  72. package_option="TRUE"
  73. display_error_location="OFF"
  74. ;;
  75. --hide-error-location)
  76. display_error_location=OFF
  77. ;;
  78. --userdata-subdir)
  79. UserDataSubdir="-DOV_CONFIG_SUBDIR=$2"
  80. shift
  81. ;;
  82. --brand-name)
  83. BrandName="$2"
  84. shift
  85. ;;
  86. --build-unit)
  87. ov_build_unit=1
  88. ;;
  89. --build-validation)
  90. ov_build_validation=1
  91. ;;
  92. --gtest-lib-dir)
  93. gtest_lib_dir_token="-DGTEST_LIBRARY=$2/libgtest.a"
  94. gtest_mainlib_dir_token="-DGTEST_MAIN_LIBRARY=$2/libgtest_main.a"
  95. shift
  96. ;;
  97. --gtest-include-dir)
  98. gtest_include_dir="$2"
  99. shift
  100. ;;
  101. --test-output-dir)
  102. ov_cmake_test_output="$2"
  103. shift
  104. ;;
  105. --python-exec)
  106. python_exec="-DPYTHON_EXECUTABLE=$2"
  107. shift;;
  108. *)
  109. echo "ERROR: Unknown parameter $key"
  110. exit 1
  111. ;;
  112. esac
  113. shift # past argument or value
  114. done
  115. # Check parameters validity
  116. if [[ ${ov_build_type} != "Debug" ]] \
  117. && [[ ${ov_build_type} != "Release" ]] \
  118. && [[ ${ov_build_type} != "RelWithDebInfo" ]]
  119. then
  120. echo "ERROR: ${ov_build_type} not handled as build type"
  121. exit 1
  122. fi
  123. # Update directories only if they point to the default one
  124. if [[ ! -v ov_build_dir ]]; then
  125. ov_build_dir="${ov_script_dir}/../../openvibe-sdk-build/build-${ov_build_type}"
  126. fi
  127. if [[ ! -v ov_install_dir ]]; then
  128. ov_install_dir="${ov_script_dir}/../../openvibe-sdk-build/dist-${ov_build_type}"
  129. fi
  130. if [[ ! -v ov_cmake_test_output ]]; then
  131. ov_cmake_test_output="${ov_build_dir}/validation-test-output/"
  132. fi
  133. echo "**************************************"
  134. echo "Build with parameters:"
  135. echo "[build-type] = ${ov_build_type}"
  136. echo "[build-dir] = ${ov_build_dir}"
  137. echo "[dependencies-dir token] = ${dependencies_dir_token}"
  138. echo "[install-dir] = ${ov_install_dir}"
  139. echo "[test data directory token] = ${ov_test_data_dir_token}"
  140. echo "[test output files directory] = ${ov_cmake_test_output}"
  141. echo "[build unit] = ${ov_build_unit}"
  142. echo "[build validation] = ${ov_build_validation}"
  143. echo "[brand name] = ${BrandName}"
  144. echo "[user data subdirectory] = ${UserDataSubdir}"
  145. echo "[display-error-location] = ${display_error_location}"
  146. echo "**************************************"
  147. echo ""
  148. echo ""
  149. # Special configuration for MacOS
  150. uname_string=$(uname)
  151. if [[ "$uname_string" == 'Darwin' ]]; then
  152. export PKG_CONFIG_PATH="/opt/X11/lib/pkgconfig:$PKG_CONFIG_PATH"
  153. fi
  154. # Create necessary directories
  155. mkdir -p "${ov_build_dir}" &> /dev/null
  156. # Change directory to build directory as cmake has to be run from build
  157. # directory
  158. pushd "${ov_build_dir}" &> /dev/null
  159. echo "Generating build system files with cmake..."
  160. cmake ${ov_script_dir}/.. \
  161. -G Ninja \
  162. -DCMAKE_BUILD_TYPE=${ov_build_type} \
  163. -DCMAKE_INSTALL_PREFIX=${ov_install_dir} \
  164. ${ov_test_data_dir_token} \
  165. ${dependencies_dir_token} \
  166. -DOV_PACKAGE=${package_option} \
  167. -DOV_DISPLAY_ERROR_LOCATION=${display_error_location} \
  168. -DBUILD_UNIT_TEST=${ov_build_unit} \
  169. -DBUILD_VALIDATION_TEST=${ov_build_validation} \
  170. -DGTEST_INCLUDE_DIR=${gtest_include_dir} \
  171. ${gtest_lib_dir_token} \
  172. ${gtest_mainlib_dir_token} \
  173. -DOVT_VALIDATION_TEST_OUTPUT_DIR=${ov_cmake_test_output} \
  174. ${UserDataSubdir} \
  175. -DBRAND_NAME=${BrandName} \
  176. ${python_exec}
  177. if [[ $? == 0 ]]; then
  178. echo "Generation succeeded!"
  179. else
  180. echo "ERROR: Generation failed"
  181. exit 1
  182. fi
  183. echo "Building project..."
  184. if [[ $verbose == 1 ]]; then
  185. ninja -v install
  186. else
  187. ninja install
  188. fi
  189. if [[ $? == 0 ]]; then
  190. echo "Build succeeded!"
  191. else
  192. echo "ERROR: Build failed"
  193. exit 1
  194. fi
  195. if [[ ${package_option} == "TRUE" ]]; then
  196. cmake --build . --target package
  197. if [[ $? == 0 ]]; then
  198. echo "Package succeeded!"
  199. else
  200. echo "ERROR: Package failed"
  201. exit 1
  202. fi
  203. fi
  204. popd &> /dev/null
  205. exit