Eclipses 如何支持CMake Project

来源:互联网 发布:spring boot 执行sql 编辑:程序博客网 时间:2024/06/06 07:46

eclipse目前版本(至少时Luna以后的版本)对Cmake有着特殊的支持。如果不用该支持,会导致index不完全,很多地方出现红线无法解析的问题。本文阐述实战中如何对MySQL(AliSQL)进行导入。


MySQL(AliSQL)的版本已经是Cmake。git clone后,进入文件夹:

发现里面有一个build.sh脚本,我们做相应的动作


mkdir bu

./build.sh

之后会在bu下生成一堆目录和文件,里面的.cproject就是cmake为我们生成的eclipse工程文件。之后eclipse打开已有项目文件即可。


让我们看一下build.sh做了什么。下面是build.sh的内内容:

#!/bin/bash## Script for Dev's daily work.  It is a good idea to use the exact same# build options as the released version.get_key_value(){  echo "$1" | sed 's/^--[a-zA-Z_-]*=//'}usage(){cat <<EOFUsage: $0 [-t debug|release] [-d <dest_dir>] [-s <server_suffix>]       Or       $0 [-h | --help]  -t                      Select the build type.  -d                      Set the destination directory.  -s                      Set the server suffix.  -h, --help              Show this help message.Note: this script is intended for internal use by MySQL developers.EOF}parse_options(){  while test $# -gt 0  do    case "$1" in    -t=*)      build_type=`get_key_value "$1"`;;    -t)      shift      build_type=`get_key_value "$1"`;;    -d=*)      dest_dir=`get_key_value "$1"`;;    -d)      shift      dest_dir=`get_key_value "$1"`;;    -s=*)      server_suffix=`get_key_value "$1"`;;    -s)      shift      server_suffix=`get_key_value "$1"`;;    -h | --help)      usage      exit 0;;    *)      echo "Unknown option '$1'"      exit 1;;    esac    shift  done}dump_options(){  echo "Dumping the options used by $0 ..."  echo "build_type=$build_type"  echo "dest_dir=$dest_dir"  echo "server_suffix=$server_suffix"}if test ! -f sql/mysqld.ccthen  echo "You must run this script from the MySQL top-level directory"  exit 1fibuild_type="debug"dest_dir="/home/michael/install"server_suffix="tb2016"parse_options "$@"dump_options# valgrid is always 0, turn it on when needed.# unit_tests is always 1, if gmock is not found, it will be disabled.if [ x"$build_type" = x"debug" ]; then  build_type="Debug"  debug=1  debug_sync=1  unit_tests=1  valgrid=0elif [ x"$build_type" = x"release" ]; then  build_type="Release"  debug=0  debug_sync=0  unit_tests=1  valgrid=0else  echo "Invalid build type, it must be \"debug\" or \"release\"."  exit 1figmock="./source_downloads/gmock-1.6.0.zip"if [ x"$unit_tests" = x"1" ]; then  if [ -f "$gmock" ]; then    export WITH_GMOCK=`readlink -f "$gmock"`  fifiserver_suffix="-""$server_suffix"# http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html#       #option_cmake_build_config# http://dev.mysql.com/doc/refman/5.6/en/compilation-problems.html## From the following two files, we can get the table of CMAKE_BUILD_TYPE# and CFLAGS/CXXFLAGS.# 1. CMakeCache.txt# 2. cmake/build_configurations/compiler_options.cmake## CMAKE_BUILD_TYPE  CFLAGS & CXXFLAGS#  Debug            -g#  RelWithDebInfo   -O3 -g#  MinSizeRel       -Os -DNDEBUG#  Release          -O3 -DNDEBUG#if [ x"$build_type" = x"Release" ]; then  # Alibaba use -fno-exceptions -static-libgcc for 5.5, keep it anyway.  COMMON_FLAGS="-O3 -g -fexceptions -static-libgcc \-fno-omit-frame-pointer -fno-strict-aliasing"  CFLAGS="$COMMON_FLAGS"  export CFLAGS  # Alibaba use -fno-rtti for 5.5, but unittest/ cannot build in 5.6.  CXXFLAGS="$COMMON_FLAGS"  export CXXFLAGS  # Use gcc instead of g++ or c++ to avoid dependency on libstdc++.so and  # libgcc_s.so.  # But utilities under extra/ will not build, this is introduced by MySQL  # 5.6.   # See extra/CMakeList.txt and keyword LINKER_LANGUAGE.  #  # CXX=gcc  # export CXX  CC=/opt/rh/devtoolset-2/root/usr/bin/gcc  CXX=/opt/rh/devtoolset-2/root/usr/bin/g++  export CC CXXfirm -rf CMakeCache.txt# MyISAM, MERGE, MEMORY, and CSV engines are mandatory, and need not be# installed explicitly.#rm -rf bu#mkdir bu && cd bucd bucmake .. \    -G"Eclipse CDT4 - Unix Makefiles" -DDOWNLOAD_BOOST=0     \    -DWITH_BOOST="../boost"                                  \    -DCMAKE_BUILD_TYPE="$build_type"                         \    -DSYSCONFDIR="$dest_dir"                                 \    -DCMAKE_INSTALL_PREFIX="$dest_dir"                       \    -DMYSQL_DATADIR="$dest_dir/data"                         \    -DWITH_DEBUG=$debug                                      \    -DWITH_DEBUG_SYNC=$debug_sync                            \    -DWITH_UNIT_TESTS=$unit_tests                            \    -DWITH_VALGRIND=$valgrid                                 \    -DENABLED_PROFILING=1                                    \    -DWITH_EXTRA_CHARSETS=all                                \    -DDEFAULT_CHARSET=utf8                                   \    -DDEFAULT_COLLATION=utf8_general_ci                      \    -DWITH_SSL=bundled                                       \    -DWITH_ZLIB=bundled                                      \    -DWITH_PARTITION_STORAGE_ENGINE=1                        \    -DWITH_INNOBASE_STORAGE_ENGINE=1                         \    -DWITH_ARCHIVE_STORAGE_ENGINE=1                          \    -DWITH_BLACKHOLE_STORAGE_ENGINE=1                        \    -DWITH_PERFSCHEMA_STORAGE_ENGINE=1                       \    -DENABLED_LOCAL_INFILE=1                                 \    -DWITH_EMBEDDED_SERVER=0                                 \    -DINSTALL_LAYOUT=STANDALONE                              \    -DWITH_INNODB_MEMCACHED=ON                               \    -DMYSQL_SERVER_SUFFIX="$server_suffix"# end of file


看到了吧。使用cmake的一般方式就是这样,先创建一个build文件夹(这里简写为bu),然后进入该文件夹,之后使用cmake .. 来进行compile。


注意,cmake的参数第一行,我添加的是-G"Eclipse CDT4 - Unix Makefiles",目的就是生成.cproject文件。


进入到eclipse里(我用的时neon版本),加入本工程文件后,eclipse自动完成index,不用任何辅助设置。完美!