2013-02-06 11:16:49 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2013-04-09 21:36:59 -04:00
|
|
|
function command_exists {
|
|
|
|
hash "$1" 2>/dev/null ;
|
|
|
|
}
|
|
|
|
|
2013-02-06 11:16:49 -05:00
|
|
|
function cmake_install {
|
|
|
|
if [[ `uname -s` == "Darwin" ]]; then
|
|
|
|
homebrew_cmake_install
|
|
|
|
else
|
|
|
|
linux_cmake_install
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function homebrew_cmake_install {
|
2013-05-26 20:38:47 -04:00
|
|
|
if command_exists brew; then
|
2013-02-06 11:16:49 -05:00
|
|
|
brew install cmake
|
|
|
|
else
|
2013-02-07 21:12:42 -05:00
|
|
|
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."
|
2013-02-06 11:16:49 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-02-17 12:01:54 -05:00
|
|
|
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
|
2013-02-17 13:39:17 -05:00
|
|
|
which_python=$(python -c 'import sys;print(sys.version)' | sed 's/^[ \t]*//')
|
|
|
|
which_python="python${which_python:0:3}"
|
2013-02-17 13:47:14 -05:00
|
|
|
lib_python="${python_prefix}/lib/lib${which_python}"
|
2013-02-17 12:01:54 -05:00
|
|
|
if [ -f "${lib_python}.a" ]; then
|
|
|
|
python_library+="${lib_python}.a"
|
|
|
|
else
|
|
|
|
python_library+="${lib_python}.dylib"
|
|
|
|
fi
|
|
|
|
python_include+="${python_prefix}/include/${which_python}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${python_library} ${python_include}"
|
|
|
|
}
|
|
|
|
|
2013-02-23 13:30:33 -05:00
|
|
|
function num_cores {
|
2013-04-10 02:40:04 -04:00
|
|
|
if command_exists nproc; then
|
2013-04-09 16:34:46 -04:00
|
|
|
num_cpus=$(nproc)
|
2013-02-23 13:30:33 -05:00
|
|
|
else
|
2013-04-09 16:34:46 -04:00
|
|
|
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
|
2013-02-23 13:30:33 -05:00
|
|
|
fi
|
|
|
|
echo $num_cpus
|
|
|
|
}
|
|
|
|
|
2013-04-09 16:34:46 -04:00
|
|
|
|
2013-02-06 11:16:49 -05:00
|
|
|
function install {
|
|
|
|
ycm_dir=`pwd`
|
2013-03-01 21:07:39 -05:00
|
|
|
build_dir=`mktemp -d -t ycm_build.XXXXXX`
|
2013-02-06 11:16:49 -05:00
|
|
|
pushd $build_dir
|
2013-02-17 14:01:31 -05:00
|
|
|
|
|
|
|
if [[ `uname -s` == "Darwin" ]]; then
|
2013-05-08 14:31:12 -04:00
|
|
|
cmake -G "Unix Makefiles" $(python_finder) "$@" . $ycm_dir/cpp
|
2013-02-17 14:01:31 -05:00
|
|
|
else
|
2013-05-08 14:31:12 -04:00
|
|
|
cmake -G "Unix Makefiles" "$@" . $ycm_dir/cpp
|
2013-02-17 14:01:31 -05:00
|
|
|
fi
|
|
|
|
|
2013-10-16 12:55:40 -04:00
|
|
|
make -j $(num_cores) ycm_support_libs
|
2013-02-06 11:16:49 -05:00
|
|
|
popd
|
2013-02-22 07:17:09 -05:00
|
|
|
rm -rf $build_dir
|
2013-02-06 11:16:49 -05:00
|
|
|
}
|
|
|
|
|
2013-04-19 00:26:06 -04:00
|
|
|
function testrun {
|
|
|
|
ycm_dir=`pwd`
|
|
|
|
build_dir=`mktemp -d -t ycm_build.XXXXXX`
|
|
|
|
pushd $build_dir
|
|
|
|
|
2013-05-08 14:31:12 -04:00
|
|
|
cmake -G "Unix Makefiles" "$@" . $ycm_dir/cpp
|
2013-04-19 00:26:06 -04:00
|
|
|
make -j $(num_cores) ycm_core_tests
|
|
|
|
cd ycm/tests
|
|
|
|
LD_LIBRARY_PATH=$ycm_dir/python ./ycm_core_tests
|
|
|
|
|
|
|
|
popd
|
|
|
|
rm -rf $build_dir
|
|
|
|
}
|
|
|
|
|
2013-02-06 11:16:49 -05:00
|
|
|
function linux_cmake_install {
|
2013-02-07 21:12:42 -05:00
|
|
|
echo "Please install CMake using your package manager and retry."
|
2013-02-06 11:16:49 -05:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2013-02-07 21:24:25 -05:00
|
|
|
function usage {
|
2013-07-16 14:59:26 -04:00
|
|
|
echo "Usage: $0 [--clang-completer [--system-libclang]] [--omnisharp-completer]"
|
2013-02-07 21:12:42 -05:00
|
|
|
exit 0
|
2013-02-07 21:24:25 -05:00
|
|
|
}
|
|
|
|
|
2013-10-24 14:16:36 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-07-16 14:59:26 -04:00
|
|
|
cmake_args=""
|
2013-07-16 11:17:57 -04:00
|
|
|
omnisharp_completer=false
|
|
|
|
for flag in $@; do
|
|
|
|
case "$flag" in
|
|
|
|
--clang-completer)
|
2013-07-16 14:59:26 -04:00
|
|
|
cmake_args="-DUSE_CLANG_COMPLETER=ON"
|
2013-07-08 15:19:49 -04:00
|
|
|
;;
|
|
|
|
--system-libclang)
|
|
|
|
cmake_args="$cmake_args -DUSE_SYSTEM_LIBCLANG=ON"
|
2013-07-16 11:17:57 -04:00
|
|
|
;;
|
|
|
|
--omnisharp-completer)
|
|
|
|
omnisharp_completer=true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2013-02-07 21:12:42 -05:00
|
|
|
|
2013-07-08 15:19:49 -04:00
|
|
|
if [[ $cmake_args == *-DUSE_SYSTEM_LIBCLANG=ON* ]] && \
|
|
|
|
[[ $cmake_args != *-DUSE_CLANG_COMPLETER=ON* ]]; then
|
2013-02-07 21:24:25 -05:00
|
|
|
usage
|
2013-02-07 21:12:42 -05:00
|
|
|
fi
|
|
|
|
|
2013-10-24 14:16:36 -04:00
|
|
|
check_third_party_libs
|
|
|
|
|
2013-04-09 21:36:59 -04:00
|
|
|
if ! command_exists cmake; then
|
2013-02-07 21:12:42 -05:00
|
|
|
echo "CMake is required to build YouCompleteMe."
|
2013-02-06 11:16:49 -05:00
|
|
|
cmake_install
|
|
|
|
fi
|
2013-04-19 00:26:06 -04:00
|
|
|
|
|
|
|
if [ -z "$YCM_TESTRUN" ]; then
|
|
|
|
install $cmake_args $EXTRA_CMAKE_ARGS
|
|
|
|
else
|
2013-10-04 18:21:30 -04:00
|
|
|
testrun $cmake_args $EXTRA_CMAKE_ARGS
|
2013-04-19 00:26:06 -04:00
|
|
|
fi
|
|
|
|
|
2013-07-16 11:17:57 -04:00
|
|
|
if $omnisharp_completer; then
|
|
|
|
buildcommand="msbuild"
|
|
|
|
if ! command_exists msbuild; then
|
|
|
|
buildcommand="xbuild"
|
|
|
|
if ! command_exists xbuild; then
|
|
|
|
echo "msbuild or xbuild is required to build Omnisharp"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
ycm_dir=`pwd`
|
|
|
|
build_dir=$ycm_dir"/python/ycm/completers/cs/OmniSharpServer"
|
2013-08-12 23:33:46 -04:00
|
|
|
|
2013-07-16 11:17:57 -04:00
|
|
|
cd $build_dir
|
|
|
|
$buildcommand
|
|
|
|
cd $ycm_dir
|
|
|
|
fi
|