install.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. else
  39. python_library+="${lib_python}.dylib"
  40. fi
  41. python_include+="${python_prefix}/include/${which_python}"
  42. fi
  43. echo "${python_library} ${python_include}"
  44. }
  45. function num_cores {
  46. if command_exists nproc; then
  47. num_cpus=$(nproc)
  48. else
  49. num_cpus=1
  50. if [[ `uname -s` == "Linux" ]]; then
  51. num_cpus=$(grep -c ^processor /proc/cpuinfo)
  52. else
  53. # Works on Mac and FreeBSD
  54. num_cpus=$(sysctl -n hw.ncpu)
  55. fi
  56. fi
  57. echo $num_cpus
  58. }
  59. function install {
  60. ycm_dir=`pwd`
  61. build_dir=`mktemp -d -t ycm_build.XXXXXX`
  62. pushd $build_dir
  63. if [[ `uname -s` == "Darwin" ]]; then
  64. cmake -G "Unix Makefiles" $(python_finder) "$@" . $ycm_dir/cpp
  65. else
  66. cmake -G "Unix Makefiles" "$@" . $ycm_dir/cpp
  67. fi
  68. make -j $(num_cores) ycm_core
  69. popd
  70. rm -rf $build_dir
  71. }
  72. function testrun {
  73. ycm_dir=`pwd`
  74. build_dir=`mktemp -d -t ycm_build.XXXXXX`
  75. pushd $build_dir
  76. cmake -G "Unix Makefiles" "$@" . $ycm_dir/cpp
  77. make -j $(num_cores) ycm_core_tests
  78. cd ycm/tests
  79. LD_LIBRARY_PATH=$ycm_dir/python ./ycm_core_tests
  80. popd
  81. rm -rf $build_dir
  82. }
  83. function linux_cmake_install {
  84. echo "Please install CMake using your package manager and retry."
  85. exit 1
  86. }
  87. function usage {
  88. echo "Usage: $0 [--clang-completer [--system-libclang]] [--omnisharp-completer]"
  89. exit 0
  90. }
  91. cmake_args=""
  92. omnisharp_completer=false
  93. for flag in $@; do
  94. case "$flag" in
  95. --clang-completer)
  96. cmake_args="-DUSE_CLANG_COMPLETER=ON"
  97. ;;
  98. --system-libclang)
  99. cmake_args="$cmake_args -DUSE_SYSTEM_LIBCLANG=ON"
  100. ;;
  101. --omnisharp-completer)
  102. omnisharp_completer=true
  103. ;;
  104. *)
  105. usage
  106. ;;
  107. esac
  108. done
  109. if [[ $cmake_args == *-DUSE_SYSTEM_LIBCLANG=ON* ]] && \
  110. [[ $cmake_args != *-DUSE_CLANG_COMPLETER=ON* ]]; then
  111. usage
  112. fi
  113. if ! command_exists cmake; then
  114. echo "CMake is required to build YouCompleteMe."
  115. cmake_install
  116. fi
  117. if [ -z "$YCM_TESTRUN" ]; then
  118. install $cmake_args $EXTRA_CMAKE_ARGS
  119. else
  120. testrun $cmake_args -DUSE_DEV_FLAGS=ON $EXTRA_CMAKE_ARGS
  121. fi
  122. if $omnisharp_completer; then
  123. buildcommand="msbuild"
  124. if ! command_exists msbuild; then
  125. buildcommand="xbuild"
  126. if ! command_exists xbuild; then
  127. echo "msbuild or xbuild is required to build Omnisharp"
  128. exit 1
  129. fi
  130. fi
  131. ycm_dir=`pwd`
  132. build_dir=$ycm_dir"/python/ycm/completers/cs/OmniSharpServer"
  133. cd $build_dir
  134. $buildcommand
  135. cd $ycm_dir
  136. fi