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