install.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #!/usr/bin/env bash
  2. set -e
  3. function command_exists {
  4. hash "$1" 2>/dev/null ;
  5. }
  6. function cmake_install {
  7. if [[ `uname -s` == "Darwin" ]]; then
  8. homebrew_cmake_install
  9. else
  10. linux_cmake_install
  11. fi
  12. }
  13. function homebrew_cmake_install {
  14. if command_exists brew; then
  15. brew install cmake
  16. else
  17. echo "Homebrew was not found installed in your system."
  18. echo "Go to http://mxcl.github.com/homebrew/ and follow the instructions."
  19. echo "Or install CMake somehow and retry."
  20. exit 1
  21. fi
  22. }
  23. function python_finder {
  24. python_library="-DPYTHON_LIBRARY="
  25. python_include="-DPYTHON_INCLUDE_DIR="
  26. # The CMake 'FindPythonLibs' Module does not work properly.
  27. # So we are forced to do its job for it.
  28. python_prefix=$(python-config --prefix | sed 's/^[ \t]*//')
  29. if [ -f "${python_prefix}/Python" ]; then
  30. python_library+="${python_prefix}/Python"
  31. python_include+="${python_prefix}/Headers"
  32. else
  33. which_python=$(python -c 'import sys;print(sys.version)' | sed 's/^[ \t]*//')
  34. which_python="python${which_python:0:3}"
  35. lib_python="${python_prefix}/lib/lib${which_python}"
  36. if [ -f "${lib_python}.a" ]; then
  37. python_library+="${lib_python}.a"
  38. # This check is for for CYGWIN
  39. elif [ -f "${lib_python}.dll.a" ]; then
  40. python_library+="${lib_python}.dll.a"
  41. else
  42. python_library+="${lib_python}.dylib"
  43. fi
  44. python_include+="${python_prefix}/include/${which_python}"
  45. fi
  46. echo "${python_library} ${python_include}"
  47. }
  48. function num_cores {
  49. if command_exists nproc; then
  50. num_cpus=$(nproc)
  51. else
  52. num_cpus=1
  53. if [[ `uname -s` == "Linux" ]]; then
  54. num_cpus=$(grep -c ^processor /proc/cpuinfo)
  55. else
  56. # Works on Mac and FreeBSD
  57. num_cpus=$(sysctl -n hw.ncpu)
  58. fi
  59. fi
  60. echo $num_cpus
  61. }
  62. function install {
  63. ycm_dir=`pwd`
  64. build_dir=`mktemp -d -t ycm_build.XXXXXX`
  65. pushd $build_dir
  66. if [[ `uname -s` == "Darwin" ]]; then
  67. cmake -G "Unix Makefiles" $(python_finder) "$@" . $ycm_dir/cpp
  68. else
  69. cmake -G "Unix Makefiles" "$@" . $ycm_dir/cpp
  70. fi
  71. make -j $(num_cores) ycm_support_libs
  72. popd
  73. rm -rf $build_dir
  74. }
  75. function testrun {
  76. ycm_dir=`pwd`
  77. build_dir=`mktemp -d -t ycm_build.XXXXXX`
  78. pushd $build_dir
  79. cmake -G "Unix Makefiles" "$@" . $ycm_dir/cpp
  80. make -j $(num_cores) ycm_core_tests
  81. cd ycm/tests
  82. LD_LIBRARY_PATH=$ycm_dir/python ./ycm_core_tests
  83. popd
  84. rm -rf $build_dir
  85. }
  86. function linux_cmake_install {
  87. echo "Please install CMake using your package manager and retry."
  88. exit 1
  89. }
  90. function usage {
  91. echo "Usage: $0 [--clang-completer [--system-libclang]] [--omnisharp-completer]"
  92. exit 0
  93. }
  94. function check_third_party_libs {
  95. libs_present=true
  96. for folder in third_party/*; do
  97. num_files_in_folder=$(find $folder -maxdepth 1 -mindepth 1 | wc -l)
  98. if [[ $num_files_in_folder -eq 0 ]]; then
  99. libs_present=false
  100. fi
  101. done
  102. if ! $libs_present; then
  103. echo "Some folders in ./third_party are empty; you probably forgot to run:"
  104. printf "\n\tgit submodule update --init --recursive\n\n"
  105. exit 1
  106. fi
  107. }
  108. cmake_args=""
  109. omnisharp_completer=false
  110. for flag in $@; do
  111. case "$flag" in
  112. --clang-completer)
  113. cmake_args="-DUSE_CLANG_COMPLETER=ON"
  114. ;;
  115. --system-libclang)
  116. cmake_args="$cmake_args -DUSE_SYSTEM_LIBCLANG=ON"
  117. ;;
  118. --omnisharp-completer)
  119. omnisharp_completer=true
  120. ;;
  121. *)
  122. usage
  123. ;;
  124. esac
  125. done
  126. if [[ $cmake_args == *-DUSE_SYSTEM_LIBCLANG=ON* ]] && \
  127. [[ $cmake_args != *-DUSE_CLANG_COMPLETER=ON* ]]; then
  128. usage
  129. fi
  130. check_third_party_libs
  131. if ! command_exists cmake; then
  132. echo "CMake is required to build YouCompleteMe."
  133. cmake_install
  134. fi
  135. if [ -z "$YCM_TESTRUN" ]; then
  136. install $cmake_args $EXTRA_CMAKE_ARGS
  137. else
  138. testrun $cmake_args $EXTRA_CMAKE_ARGS
  139. fi
  140. if $omnisharp_completer; then
  141. buildcommand="msbuild"
  142. if ! command_exists msbuild; then
  143. buildcommand="msbuild.exe"
  144. if ! command_exists msbuild.exe; then
  145. buildcommand="xbuild"
  146. if ! command_exists xbuild; then
  147. echo "msbuild or xbuild is required to build Omnisharp"
  148. exit 1
  149. fi
  150. fi
  151. fi
  152. ycm_dir=`pwd`
  153. build_dir=$ycm_dir"/third_party/OmniSharpServer"
  154. cd $build_dir
  155. $buildcommand
  156. cd $ycm_dir
  157. fi