vongosling closed pull request #17: Update build script to "green" build,
libraries will be built and saved only in rocketmq-client-cpp Instead of system
path
URL: https://github.com/apache/rocketmq-client-cpp/pull/17
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cb747f26..9bdd510f 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,43 +42,67 @@ option(BUILD_ROCKETMQ_STATIC "build rocketmq-client static
library" ON)
option(BUILD_ROCKETMQ_SHARED "build rocketmq-client shared library" ON)
#Find dependency
-set(BOOST_INCLUDEDIR /usr/local/include/)
-#set(BOOST_INCLUDEDIR C:/boost_1_56_0/)
option(Boost_USE_STATIC_LIBS "only find boost static libs" ON) # only
find static libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
if(WIN32)
find_package(Boost 1.56 REQUIRED COMPONENTS atomic thread system chrono
date_time
log log_setup regex serialization filesystem locale iostreams zlib)
+ if(Boost_FOUND)
+ message(status "** Boost Include dir: ${Boost_INCLUDE_DIR}")
+ message(status "** Boost Libraries dir: ${Boost_LIBRARY_DIRS}")
+ message(status "** Boost Libraries: ${Boost_LIBRARIES}")
+ include_directories(${Boost_INCLUDE_DIRS})
+ endif()
else()
- find_package(Boost 1.56 REQUIRED COMPONENTS atomic thread system chrono
date_time log log_setup regex serialization filesystem locale iostreams)
-endif()
-
-if(Boost_FOUND)
- message(status "** Boost Include dir: ${Boost_INCLUDE_DIR}")
- message(status "** Boost Libraries dir: ${Boost_LIBRARY_DIRS}")
- message(status "** Boost Libraries: ${Boost_LIBRARIES}")
+ #find_package(Boost 1.56 REQUIRED COMPONENTS atomic thread system chrono
date_time log log_setup regex serialization filesystem locale iostreams)
+ set(Boost_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/bin/include)
+ set(Boost_LIBRARY_DIRS ${PROJECT_SOURCE_DIR}/bin/lib)
+ set(Boost_LIBRARIES
${Boost_LIBRARY_DIRS}/libboost_atomic.a;${Boost_LIBRARY_DIRS}/libboost_thread.a;${Boost_LIBRARY_DIRS}/libboost_system.a;${Boost_LIBRARY_DIRS}/libboost_chrono.a;
+
${Boost_LIBRARY_DIRS}/libboost_date_time.a;${Boost_LIBRARY_DIRS}/libboost_log.a;${Boost_LIBRARY_DIRS}/libboost_log_setup.a;
+
${Boost_LIBRARY_DIRS}/libboost_regex.a;${Boost_LIBRARY_DIRS}/libboost_serialization.a;${Boost_LIBRARY_DIRS}/libboost_filesystem.a;
+
${Boost_LIBRARY_DIRS}/libboost_locale.a;${Boost_LIBRARY_DIRS}/libboost_iostreams.a)
include_directories(${Boost_INCLUDE_DIRS})
endif()
-#set(LIBEVENT_INCLUDE_DIR /usr/local/include/)
-option(Libevent_USE_STATIC_LIBS "only find libevent static libs" ON) # only
find static libs
-#set(Libevent_DIR /usr/local/lib/) # only find static libs
-find_package(Libevent 2.0.22 REQUIRED COMPONENTS)
+message(status "** Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}")
+message(status "** Boost_LIBRARIES: ${Boost_LIBRARIES}")
-if(LIBEVENT_FOUND)
+option(Libevent_USE_STATIC_LIBS "only find libevent static libs" ON) # only
find static libs
+if(WIN32)
+ find_package(Libevent 2.0.22 REQUIRED COMPONENTS)
+ if(LIBEVENT_FOUND)
+ include_directories(${LIBEVENT_INCLUDE_DIRS})
+ message(status "** libevent Include dir: ${LIBEVENT_INCLUDE_DIR}")
+ message(status "** libevent Libraries: ${LIBEVENT_LIBRARIES}")
+ endif()
+else()
+ #find_package(Libevent 2.0.22 REQUIRED COMPONENTS)
+ set(LIBEVENT_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/bin/include)
+ set(LIBEVENT_LIBRARIES_DIR ${PROJECT_SOURCE_DIR}/bin/lib)
+ set(LIBEVENT_LIBRARIES
${LIBEVENT_LIBRARIES_DIR}/libevent.a;${LIBEVENT_LIBRARIES_DIR}/libevent_core.a;${LIBEVENT_LIBRARIES_DIR}/libevent_extra.a;${LIBEVENT_LIBRARIES_DIR}/libevent_pthreads.a)
include_directories(${LIBEVENT_INCLUDE_DIRS})
- message(status "** libevent Include dir: ${LIBEVENT_INCLUDE_DIR}")
- message(status "** libevent Libraries: ${LIBEVENT_LIBRARIES}")
endif()
-#set(JSONCPP_INCLUDE_DIRS C:/jsoncpp-0.10.6/include)
+message(status "** LIBEVENT_INCLUDE_DIR: ${LIBEVENT_INCLUDE_DIR}")
+message(status "** LIBEVENT_LIBRARIES: ${LIBEVENT_LIBRARIES}")
+
option(JSONCPP_USE_STATIC_LIBS "only find jsoncpp static libs" ON) # only
find static libs
-find_package(Jsoncpp 0.10.6)
-if(JSONCPP_FOUND)
- include_directories(${JSONCPP_INCLUDE_DIRS})
+if(WIN32)
+ find_package(Jsoncpp 0.10.6)
+ if(JSONCPP_FOUND)
+ include_directories(${JSONCPP_INCLUDE_DIRS})
+ endif()
+else()
+ set(JSONCPP_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/bin/include/jsoncpp)
+ set(JSONCPP_LIBRARIES_DIR ${PROJECT_SOURCE_DIR}/bin/lib)
+ set(JSONCPP_LIBRARIES ${JSONCPP_LIBRARIES_DIR}/libjsoncpp.a)
+ include_directories(${JSONCPP_INCLUDE_DIRS})
endif()
+message(status "** JSONCPP_INCLUDE_DIRS: ${JSONCPP_INCLUDE_DIRS}")
+message(status "** JSONCPP_LIBRARIES: ${JSONCPP_LIBRARIES}")
+
# put binaries in a different dir to make them easier to find.
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
@@ -107,7 +131,6 @@ set(C_FLAGS
)
set(CXX_FLAGS
#-g
- -O2
-Wall
-Wno-deprecated
-fPIC
diff --git a/README.md b/README.md
index 9ddda488..b8806dfc 100644
--- a/README.md
+++ b/README.md
@@ -41,20 +41,21 @@ doc/rocketmq-cpp_manaual_zh.docx
- gcc-c++ 4.8.2: c++ compiler while need support C++11
- cmake 2.8.0: build jsoncpp require it
- automake 1.11.1: build libevent require it
+ - autoconf 2.65: build libevent require it
- libtool 2.2.6: build libevent require it
- libraries:
- bzip2-devel 1.0.6: boost depend it
-build.sh script will automatic build the dependency libraries include libevent
json and boost, then it will build rocketmq-client static and shared library.
+build.sh script will automatic download and build the dependency libraries
include libevent json and boost, the libraries will be saved under
rocketmq-client-cpp folder, and then it will build both rocketmq-client static
and shared libraries.
if you can't get to internet to download three library source files by
build.sh script, you can copy three library source files
(release-2.0.22-stable.zip 0.10.6.zip and boost_1_58_0.tar.gz) to
rocketmq-client-cpp root dir, then build.sh will auto use these three library
source files to build rocketmq-client-cpp.
sudo sh build.sh
-then there are both librocketmq.a and librocketmq.so in /usr/local/lib. when
use them to build application or library you should link with following
libraries: -lrocketmq -lpthread -lz -ldl -lrt.
+Finally, both librocketmq.a and librocketmq.so are saved in
rocketmq-client-cpp/bin. when use them to build application or library, besides
rocketmq you also should link with following libraries -lpthread -lz -ldl -lrt.
- g++ -o consumer_example consumer_example.cpp -L. -lrocketmq -lpthread -lz
-ldl -lrt
+ g++ -o consumer_example consumer_example.cpp -lrocketmq -lpthread -lz -ldl
-lrt
### Windows platform: ###
**note**: *make sure the following compile tools or libraries with them
minimum version number have been installed before run the build script
win32_build.bat*
diff --git a/build.sh b/build.sh
index b35927d0..0aa28027 100644
--- a/build.sh
+++ b/build.sh
@@ -3,8 +3,7 @@ basepath=$(cd `dirname $0`; pwd)
down_dir="${basepath}/tmp_down_dir"
build_dir="${basepath}/tmp_build_dir"
packet_dir="${basepath}/tmp_packet_dir"
-sys_lib_dir="/usr/local/lib"
-bin_dir="${basepath}/bin"
+install_lib_dir="${basepath}/bin"
fname_libevent="libevent*.zip"
fname_jsoncpp="jsoncpp*.zip"
fname_boost="boost*.tar.gz"
@@ -77,8 +76,8 @@ function Prepare()
if [ -e ${down_dir} ]
then
echo "${down_dir} is exist"
- cd ${down_dir}
- ls |grep -v ${fname_libevent} |grep -v ${fname_jsoncpp} | grep -v
${fname_boost} |xargs sudo rm -rf
+ #cd ${down_dir}
+ #ls |grep -v ${fname_libevent} |grep -v ${fname_jsoncpp} | grep -v
${fname_boost} |xargs rm -rf
else
mkdir -p ${down_dir}
fi
@@ -102,7 +101,7 @@ function Prepare()
if [ -e ${build_dir} ]
then
echo "${build_dir} is exist"
- sudo rm -rf ${build_dir}/*
+ #rm -rf ${build_dir}/*
else
mkdir -p ${build_dir}
fi
@@ -110,10 +109,17 @@ function Prepare()
if [ -e ${packet_dir} ]
then
echo "${packet_dir} is exist"
- sudo rm -rf ${packet_dir}/*
+ #rm -rf ${packet_dir}/*
else
mkdir -p ${packet_dir}
fi
+
+ if [ -e ${install_lib_dir} ]
+ then
+ echo "${install_lib_dir} is exist"
+ else
+ mkdir -p ${install_lib_dir}
+ fi
}
function BuildLibevent()
@@ -136,7 +142,6 @@ function BuildLibevent()
fi
libevent_dir=`ls | grep libevent | grep .*[^zip]$`
- echo ${libevent_dir}
cd ${libevent_dir}
if [ $? -ne 0 ];then
exit 1
@@ -145,8 +150,8 @@ function BuildLibevent()
if [ $? -ne 0 ];then
exit 1
fi
- echo "build libevent static #####################"
- ./configure --disable-openssl --enable-static=yes --enable-shared=no
CFLAGS=-fPIC CPPFLAGS=-fPIC
+ echo "build libevent static #####################"
+ ./configure --disable-openssl --enable-static=yes --enable-shared=no
CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir}
if [ $? -ne 0 ];then
exit 1
fi
@@ -154,7 +159,7 @@ function BuildLibevent()
if [ $? -ne 0 ];then
exit 1
fi
- sudo make install
+ make install
}
@@ -183,8 +188,8 @@ function BuildJsonCPP()
exit 1
fi
mkdir build; cd build
- echo "build jsoncpp static #####################"
- cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF
+ echo "build jsoncpp static #####################"
+ cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir}
if [ $? -ne 0 ];then
exit 1
fi
@@ -192,7 +197,7 @@ function BuildJsonCPP()
if [ $? -ne 0 ];then
exit 1
fi
- sudo make install
+ make install
}
function BuildBoost()
@@ -220,7 +225,7 @@ function BuildBoost()
exit 1
fi
echo "build boost static #####################"
- sudo ./b2 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 runtime-link=static release install
+ ./b2 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
runtime-link=static release install --prefix=${install_lib_dir}
if [ $? -ne 0 ];then
exit 1
fi
@@ -234,19 +239,16 @@ function BuildRocketMQClient()
if [ $? -ne 0 ];then
exit 1
fi
- sudo make install
-
+ #sudo make install
PackageRocketMQStatic
}
function PackageRocketMQStatic()
{
#packet libevent,jsoncpp,boost,rocketmq,Signature to one librocketmq.a
+ cp -f ${basepath}/libs/signature/lib/libSignature.a ${install_lib_dir}/lib
ar -M < ${basepath}/package_rocketmq.mri
- sudo rm -rf ${sys_lib_dir}/librocketmq.a
- sudo rm -rf ${sys_lib_dir}/libSignature.a
- cp -f librocketmq.a ${bin_dir}
- sudo cp -f librocketmq.a ${sys_lib_dir}/
+ cp -f librocketmq.a ${install_lib_dir}
}
PrintParams
diff --git a/cmake/FindJsoncpp.cmake b/cmake/FindJsoncpp.cmake
index 76b7185a..96321181 100755
--- a/cmake/FindJsoncpp.cmake
+++ b/cmake/FindJsoncpp.cmake
@@ -51,8 +51,7 @@ NAMES
json.h
json/json.h
PATHS
- /usr/include
- /usr/local/include
+ ${CMAKE_SOURCE_DIR}/bin/include
C:/jsoncpp/include
${CMAKE_SOURCE_DIR}/win32-deps/include
C:/jsoncpp-0.10.6/include
@@ -61,7 +60,7 @@ PATH_SUFFIXES jsoncpp
find_library(JSONCPP_LIBRARIES
NAMES jsoncpp
- PATHS /usr/lib /usr/local/lib C:/jsoncpp/lib
${CMAKE_SOURCE_DIR}/win32-deps/lib C:/jsoncpp-0.10.6/
+ PATHS ${CMAKE_SOURCE_DIR}/bin/lib C:/jsoncpp/lib
${CMAKE_SOURCE_DIR}/win32-deps/lib C:/jsoncpp-0.10.6/
)
IF (JSONCPP_LIBRARIES AND JSONCPP_INCLUDE_DIRS)
SET(JSONCPP_LIBRARIES ${JSONCPP_LIBRARIES})
diff --git a/cmake/FindLibevent.cmake b/cmake/FindLibevent.cmake
index 1b0f247b..c013d498 100755
--- a/cmake/FindLibevent.cmake
+++ b/cmake/FindLibevent.cmake
@@ -62,7 +62,7 @@ find_path(LIBEVENT_INCLUDE_DIR
WIN32-Code/event2/event-config.h
event2/event-config.h
event-config.h
- PATHS /usr/include /usr/local/include C:/libevent/include
${CMAKE_SOURCE_DIR}/win32-deps/include
+ PATHS ${CMAKE_SOURCE_DIR}/bin/include C:/libevent/include
${CMAKE_SOURCE_DIR}/win32-deps/include
HINTS
${PC_LIBEVENT_INCLUDE_DIRS}
)
@@ -114,7 +114,7 @@ foreach(COMPONENT ${Libevent_FIND_COMPONENTS})
message(status "** ${_LIBEVENT_LIBNAME}")
find_library(LIBEVENT_${COMPONENT_UPPER}_LIBRARY
NAMES ${_LIBEVENT_LIBNAME}
- PATHS C:/libevent-2.0.22-stable C:/libevent-2.0.22-stable/lib
C:/libevent/lib ${CMAKE_SOURCE_DIR}/win32-deps/lib /usr/lib /usr/local/lib
+ PATHS ${CMAKE_SOURCE_DIR}/bin/lib C:/libevent-2.0.22-stable
C:/libevent-2.0.22-stable/lib C:/libevent/lib ${CMAKE_SOURCE_DIR}/win32-deps/lib
HINTS ${PC_LIBEVENT_LIBRARY_DIRS}
)
if(LIBEVENT_${COMPONENT_UPPER}_LIBRARY)
diff --git a/include/MQMessageExt.h b/include/MQMessageExt.h
index 0ec1998e..d2119c71 100755
--- a/include/MQMessageExt.h
+++ b/include/MQMessageExt.h
@@ -61,6 +61,9 @@ class ROCKETMQCLIENT_API MQMessageExt : public MQMessage {
const std::string& getMsgId() const;
void setMsgId(const std::string& msgId);
+ const std::string& getOffsetMsgId() const;
+ void setOffsetMsgId(const std::string& offsetMsgId);
+
int getSysFlag() const;
void setSysFlag(int sysFlag);
@@ -111,6 +114,7 @@ class ROCKETMQCLIENT_API MQMessageExt : public MQMessage {
sockaddr m_bornHost;
sockaddr m_storeHost;
std::string m_msgId;
+ std::string m_offsetMsgId;
};
//<!***************************************************************************
} //<!end namespace;
diff --git a/package_rocketmq.mri b/package_rocketmq.mri
index a233b5a5..fc5f6900 100644
--- a/package_rocketmq.mri
+++ b/package_rocketmq.mri
@@ -1,22 +1,22 @@
create librocketmq.a
-addlib /usr/local/lib/libboost_chrono.a
-addlib /usr/local/lib/libboost_date_time.a
-addlib /usr/local/lib/libboost_filesystem.a
-addlib /usr/local/lib/libboost_iostreams.a
-addlib /usr/local/lib/libboost_locale.a
-addlib /usr/local/lib/libboost_log.a
-addlib /usr/local/lib/libboost_log_setup.a
-addlib /usr/local/lib/libboost_regex.a
-addlib /usr/local/lib/libboost_serialization.a
-addlib /usr/local/lib/libboost_system.a
-addlib /usr/local/lib/libboost_thread.a
-addlib /usr/local/lib/libboost_wserialization.a
-addlib /usr/local/lib/libevent.a
-addlib /usr/local/lib/libevent_core.a
-addlib /usr/local/lib/libevent_extra.a
-addlib /usr/local/lib/libevent_pthreads.a
-addlib /usr/local/lib/libjsoncpp.a
-addlib /usr/local/lib/librocketmq.a
-addlib /usr/local/lib/libSignature.a
+addlib ../bin/lib/libboost_chrono.a
+addlib ../bin/lib/libboost_date_time.a
+addlib ../bin/lib/libboost_filesystem.a
+addlib ../bin/lib/libboost_iostreams.a
+addlib ../bin/lib/libboost_locale.a
+addlib ../bin/lib/libboost_log.a
+addlib ../bin/lib/libboost_log_setup.a
+addlib ../bin/lib/libboost_regex.a
+addlib ../bin/lib/libboost_serialization.a
+addlib ../bin/lib/libboost_system.a
+addlib ../bin/lib/libboost_thread.a
+addlib ../bin/lib/libboost_wserialization.a
+addlib ../bin/lib/libevent.a
+addlib ../bin/lib/libevent_core.a
+addlib ../bin/lib/libevent_extra.a
+addlib ../bin/lib/libevent_pthreads.a
+addlib ../bin/lib/libjsoncpp.a
+addlib ../bin/lib/libSignature.a
+addlib ../bin/librocketmq.a
save
end
diff --git a/project/CMakeLists.txt b/project/CMakeLists.txt
index 7921b9c2..83ec6cfd 100755
--- a/project/CMakeLists.txt
+++ b/project/CMakeLists.txt
@@ -58,7 +58,7 @@ if(BUILD_ROCKETMQ_SHARED)
add_dependencies(rocketmq_shared Signature)
target_link_libraries(rocketmq_shared ${deplibs})
target_link_libraries(rocketmq_shared Signature)
- target_link_libraries(rocketmq_shared jsoncpp)
+ target_link_libraries(rocketmq_shared ${JSONCPP_LIBRARIES})
target_link_libraries(rocketmq_shared ${LIBEVENT_LIBRARIES})
target_link_libraries(rocketmq_shared ${Boost_LIBRARIES})
endif()
diff --git a/src/message/MQDecoder.cpp b/src/message/MQDecoder.cpp
index 4dde1f54..489cd805 100755
--- a/src/message/MQDecoder.cpp
+++ b/src/message/MQDecoder.cpp
@@ -196,8 +196,15 @@ MQMessageExt* MQDecoder::decode(MemoryInputStream&
byteBuffer, bool readBody) {
}
// 18 msg ID
- string msgId = createMessageId(msgExt->getStoreHost(),
+ string offsetMsgId = createMessageId(msgExt->getStoreHost(),
(int64)msgExt->getCommitLogOffset());
+ msgExt->setOffsetMsgId(offsetMsgId);
+
+ string msgId =
msgExt->getProperty(MQMessage::PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX);
+ if (msgId.empty())
+ {
+ msgId = offsetMsgId;
+ }
msgExt->setMsgId(msgId);
// LOG_INFO("get msgExt from remote server, its contents
diff --git a/src/message/MQMessageExt.cpp b/src/message/MQMessageExt.cpp
index bfba42d1..3f2eae83 100755
--- a/src/message/MQMessageExt.cpp
+++ b/src/message/MQMessageExt.cpp
@@ -97,6 +97,10 @@ const string& MQMessageExt::getMsgId() const { return
m_msgId; }
void MQMessageExt::setMsgId(const string& msgId) { m_msgId = msgId; }
+const string& MQMessageExt::getOffsetMsgId() const { return m_offsetMsgId; }
+
+void MQMessageExt::setOffsetMsgId(const string& offsetMsgId) { m_offsetMsgId =
offsetMsgId; }
+
int MQMessageExt::getSysFlag() const { return m_sysFlag; }
void MQMessageExt::setSysFlag(int sysFlag) { m_sysFlag = sysFlag; }
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services