Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ ELSE ()
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}")
string(REPLACE ";" " " CMAKE_C_FLAGS "${C_FLAGS}")

option(ENABLE_ASAN "Enable asan reporting" OFF)
if (ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -static-libasan")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer -static-libasan")
message(STATUS "** ENABLE_ASAN: ${ENABLE_ASAN} Enable asan reporting")
endif ()

option(ENABLE_LSAN "Enable lsan reporting" OFF)
if (ENABLE_LSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak -fno-omit-frame-pointer -static-liblsan")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak -fno-omit-frame-pointer -static-liblsan")
message(STATUS "** ENABLE_LSAN: ${ENABLE_LSAN} Enable lsan reporting")
endif ()

set(CMAKE_CXX_FLAGS_DEBUG "-O0 -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")

Expand Down
104 changes: 65 additions & 39 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ basepath=$(
cd $(dirname $0)
pwd
)
down_dir="${basepath}/tmp_down_dir"
build_dir="${basepath}/tmp_build_dir"
packet_dir="${basepath}/tmp_packet_dir"
install_lib_dir="${basepath}/bin"
fname_libevent="libevent*.zip"
fname_jsoncpp="jsoncpp*.zip"
fname_boost="boost*.tar.gz"
fname_libevent_down="release-2.1.11-stable.zip"
fname_jsoncpp_down="0.10.7.zip"
fname_boost_down="1.58.0/boost_1_58_0.tar.gz"
declare down_dir="${basepath}/tmp_down_dir"
declare build_dir="${basepath}/tmp_build_dir"
declare packet_dir="${basepath}/tmp_packet_dir"
declare install_lib_dir="${basepath}/bin"
declare fname_libevent="libevent*.zip"
declare fname_jsoncpp="jsoncpp*.zip"
declare fname_boost="boost*.tar.gz"
declare fname_libevent_down="release-2.1.11-stable.zip"
declare fname_jsoncpp_down="0.10.7.zip"
declare fname_boost_down="1.58.0/boost_1_58_0.tar.gz"

PrintParams() {
echo "=========================================one key build help============================================"
Expand All @@ -38,13 +38,15 @@ PrintParams() {
echo ""
}

need_build_jsoncpp=1
need_build_libevent=1
need_build_boost=1
test=0
verbose=1
codecov=0
cpu_num=4
declare need_build_jsoncpp=1
declare need_build_libevent=1
declare need_build_boost=1
declare enable_asan=0
declare enable_lsan=0
declare verbose=1
declare codecov=0
declare cpu_num=4
declare test=0

pasres_arguments() {
for var in "$@"; do
Expand All @@ -58,6 +60,12 @@ pasres_arguments() {
noBoost)
need_build_boost=0
;;
asan)
enable_asan=1
;;
lsan)
enable_lsan=1
;;
noVerbose)
verbose=0
;;
Expand All @@ -80,18 +88,26 @@ PrintParams() {
else
echo "need build libevent lib"
fi

if [ $need_build_jsoncpp -eq 0 ]; then
echo "no need build jsoncpp lib"
else
echo "need build jsoncpp lib"
fi

if [ $need_build_boost -eq 0 ]; then
echo "no need build boost lib"
else
echo "need build boost lib"
fi
if [ $enable_asan -eq 1 ]; then
echo "enable asan reporting"
else
echo "disable asan reporting"
fi
if [ $enable_lsan -eq 1 ]; then
echo "enable lsan reporting"
else
echo "disable lsan reporting"
fi
if [ $test -eq 1 ]; then
echo "build unit tests"
else
Expand Down Expand Up @@ -165,7 +181,7 @@ BuildLibevent() {
else
wget https://github.com/libevent/libevent/archive/${fname_libevent_down} -O libevent-${fname_libevent_down}
fi
unzip -o ${fname_libevent} >unziplibevent.txt 2>&1
unzip -o ${fname_libevent} &> unziplibevent.txt
if [ $? -ne 0 ]; then
exit 1
fi
Expand All @@ -181,7 +197,7 @@ BuildLibevent() {
fi
echo "build libevent static #####################"
if [ $verbose -eq 0 ]; then
./configure --disable-openssl --enable-static=yes --enable-shared=no CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir} >libeventconfig.txt 2>&1
./configure --disable-openssl --enable-static=yes --enable-shared=no CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir} &> libeventconfig.txt
else
./configure --disable-openssl --enable-static=yes --enable-shared=no CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir}
fi
Expand All @@ -190,7 +206,7 @@ BuildLibevent() {
fi
if [ $verbose -eq 0 ]; then
echo "build libevent without detail log."
make -j $cpu_num >libeventbuild.txt 2>&1
make -j $cpu_num &> libeventbuild.txt
else
make -j $cpu_num
fi
Expand All @@ -214,7 +230,7 @@ BuildJsonCPP() {
else
wget https://github.com/open-source-parsers/jsoncpp/archive/${fname_jsoncpp_down} -O jsoncpp-${fname_jsoncpp_down}
fi
unzip -o ${fname_jsoncpp} >unzipjsoncpp.txt 2>&1
unzip -o ${fname_jsoncpp} &> unzipjsoncpp.txt
if [ $? -ne 0 ]; then
exit 1
fi
Expand All @@ -228,15 +244,15 @@ BuildJsonCPP() {
echo "build jsoncpp static ######################"
if [ $verbose -eq 0 ]; then
echo "build jsoncpp without detail log."
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} >jsoncppbuild.txt 2>&1
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} &> jsoncppbuild.txt
else
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir}
fi
if [ $? -ne 0 ]; then
exit 1
fi
if [ $verbose -eq 0 ]; then
make -j $cpu_num >jsoncppbuild.txt 2>&1
make -j $cpu_num &> jsoncppbuild.txt
else
make -j $cpu_num
fi
Expand All @@ -263,7 +279,7 @@ BuildBoost() {
else
wget http://sourceforge.net/projects/boost/files/boost/${fname_boost_down}
fi
tar -zxvf ${fname_boost} >unzipboost.txt 2>&1
tar -zxvf ${fname_boost} &> unzipboost.txt
boost_dir=$(ls | grep ^boost | grep .*[^gz]$)
cd ${boost_dir}
if [ $? -ne 0 ]; then
Expand All @@ -277,7 +293,7 @@ BuildBoost() {
pwd
if [ $verbose -eq 0 ]; then
echo "build boost without detail log."
./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir} >boostbuild.txt 2>&1
./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir} &> boostbuild.txt
else
./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir}
fi
Expand All @@ -289,18 +305,30 @@ BuildBoost() {
BuildRocketMQClient() {
cd ${build_dir}
echo "============start to build rocketmq client cpp.========="
if [ $test -eq 0 ]; then
cmake ..
else
local ROCKETMQ_CMAKE_FLAG=""
if [ $test -eq 1 ]; then
if [ $codecov -eq 1 ]; then
cmake .. -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=ON
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=ON"
else
cmake .. -DRUN_UNIT_TEST=ON
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=OFF"
fi
else
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DRUN_UNIT_TEST=OFF -DCODE_COVERAGE=OFF"
fi
if [ $enable_asan -eq 1 ]; then
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_ASAN=ON"
else
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_ASAN=OFF"
fi
if [ $enable_lsan -eq 1 ]; then
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_LSAN=ON"
else
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_LSAN=OFF"
fi
cmake .. $ROCKETMQ_CMAKE_FLAG
if [ $verbose -eq 0 ]; then
echo "build rocketmq without detail log."
make -j $cpu_num >buildclient.txt 2>&1
make -j $cpu_num &> buildclient.txt
else
make -j $cpu_num
fi
Expand All @@ -317,36 +345,34 @@ BuildGoogleTest() {
echo "no need build google test lib"
return 0
fi

if [ -f ./bin/lib/libgtest.a ]; then
echo "libgteest already exist no need build test"
return 0
fi

cd ${down_dir}
if [ -e release-1.8.1.tar.gz ]; then
echo "${fname_boost} is exist"
else
wget https://github.com/abseil/googletest/archive/release-1.8.1.tar.gz
fi
if [ ! -d "googletest-release-1.8.1" ]; then
tar -zxvf release-1.8.1.tar.gz >googletest.txt 2>&1
tar -zxvf release-1.8.1.tar.gz &> googletest.txt
fi
cd googletest-release-1.8.1
mkdir build
mkdir -p build
cd build
echo "build googletest static #####################"
if [ $verbose -eq 0 ]; then
echo "build googletest without detail log."
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} >googletestbuild.txt 2>&1
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} &> googletestbuild.txt
else
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir}
fi
if [ $? -ne 0 ]; then
exit 1
fi
if [ $verbose -eq 0 ]; then
make -j $cpu_num >gtestbuild.txt 2>&1
make -j $cpu_num &> gtestbuild.txt
else
make -j $cpu_num
fi
Expand Down
2 changes: 1 addition & 1 deletion distribution/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cp -rf ${CWD_DIR}/../README.md ${DEPLOY_BUILD_HOME}/
cp -rf ${CWD_DIR}/../LICENSE ${DEPLOY_BUILD_HOME}/LICENSE
cp -rf ${CWD_DIR}/../NOTICE ${DEPLOY_BUILD_HOME}/NOTICE

cd ${CWD_DIR} && tar -cvzf ./${PKG_NAME}-${VERSION}-bin-release.tar.gz ./${PKG_NAME} >/dev/null 2>&1
cd ${CWD_DIR} && tar -cvzf ./${PKG_NAME}-${VERSION}-bin-release.tar.gz ./${PKG_NAME} &> /dev/null
rm -rf ${DEPLOY_BUILD_HOME}
# # ##====================================================================
#make clean
2 changes: 1 addition & 1 deletion format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Usage
}

#Setp1 check clang-format support
if ! which clang-format &>/dev/null; then
if ! which clang-format &> /dev/null; then
echo -e "\033[32m !!!!!!please install clang-format \033[0m"
exit 1
fi
Expand Down