Skip to content

Commit 1f6a2e1

Browse files
committed
fix : update mqttclient framework structure
1 parent 35fae52 commit 1f6a2e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1759
-271
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
.vscode/
22
build/
33
libmqttclient/
4+
mqtt-client/
5+
*.deb
6+
*.bak
7+
*.zip
8+
*.tar
9+
*.db
10+
~/

CMakeLists.txt

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,60 @@ cmake_minimum_required(VERSION 2.8)
33
project(mqtt-client)
44

55
set(TARGETS "mqtt-client")
6-
set(SUBDIRS "mqtt" "test" "platform" "network" "common" "mqttclient")
7-
set(INCDIRS "mqtt" "platform/linux" "common" "common/log" "network" "network/mbedtls/include" "mqttclient" "test")
8-
set(OUTDIRS "build")
9-
set(LIBNAMES "mqtt" "platform" "network" "common" "salof" "mbedtls" "mqttclient")
10-
set(PROJECT_ROOT_PATH "${PROJECT_SOURCE_DIR}")
11-
set(LIBRARY_OUTPUT_PATH "${PROJECT_ROOT_PATH}/${OUTDIRS}/lib/")
12-
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_ROOT_PATH}/${OUTDIRS}/bin/")
6+
set(SUBDIRS "common" "mqtt" "platform" "network" "mqttclient")
137

14-
set(CMAKE_BUILD_TYPE "Release") # Debug Release
15-
set(CMAKE_LIB_TYPE "STATIC") # SHARED STATIC
8+
# 库文件前缀
9+
set(LIBRARY_PREFIX "mc")
10+
11+
# 设置版本信息
12+
set(PROJECT_MAJOR_VERSION 1) # 架版本信息
13+
set(PROJECT_MINOR_VERSION 2) # 主版本信息
14+
set(PROJECT_PATCH_VERSION 0) # 次版本信息
15+
set(PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION})
16+
17+
set(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
18+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_ROOT_DIR}/build/bin) #设置可执行文件的输出目录
19+
set(LIBRARY_OUTPUT_PATH ${PROJECT_ROOT_DIR}/build/lib) #设置库文件的输出目录
20+
link_directories(${LIBRARY_OUTPUT_PATH})
1621

17-
# set(CMAKE_C_COMPILER "gcc")
18-
# set(CMAKE_CXX_COMPILER "g++" )
1922

2023
set(CMAKE_C_FLAGS "-Wall")
2124
set(CMAKE_C_FLAGS "-lpthread")
22-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -O0 -g -ggdb")
25+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -O0 -g -no-pie -ggdb")
2326
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3 -DNDEBUG")
2427

2528
if(CMAKE_COMPILER_IS_GNUCXX)
2629
set(CMAKE_CXX_FLAGS "-std=c++11")
2730
set(CMAKE_CXX_FLAGS "-lpthread")
2831
set(CMAKE_CXX_FLAGS "-Wall")
29-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g -ggdb")
32+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g -no-pie -ggdb")
3033
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
3134
endif(CMAKE_COMPILER_IS_GNUCXX)
3235

33-
foreach(incdir ${INCDIRS})
34-
include_directories(${incdir})
35-
endforeach()
36+
37+
#########################################
38+
## load cmake config and load 3rdparty ##
39+
#########################################
40+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/color.cmake)
41+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/module.cmake)
42+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake)
43+
44+
# foreach(incdir ${INCDIRS})
45+
# include_directories(${incdir})
46+
# endforeach()
47+
48+
include_directories(${PROJECT_ROOT_DIR}/config)
3649

3750
foreach(subdir ${SUBDIRS})
38-
add_subdirectory(${PROJECT_ROOT_PATH}/${subdir})
51+
add_subdirectory(${PROJECT_ROOT_DIR}/${subdir})
3952
endforeach()
4053

41-
link_directories(${LIBRARY_OUTPUT_PATH})
4254

55+
get_module_info()
56+
show_module_info()
57+
install_project()
58+
59+
60+
if(BUILD_EXAMPLES)
61+
add_subdirectory(example)
62+
endif()

build.sh

Lines changed: 240 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,249 @@
11
#!/bin/bash
22

3-
mkdir -p build build/bin build/lib
4-
cd build
5-
6-
if [ " $1" == " " ]; then
7-
compiler="gcc"
8-
elif [ $1 == "--help" -o $1 == "-help" -o $1 == "--h" -o $1 == "-h" ]; then
9-
echo "usage: $0 [compiler] [compiler path]"
10-
echo " compiler: specify the compiler you are using, default: gcc"
11-
echo " compiler path: specify the compiler path you are using"
3+
compiler=""
4+
compiler_path=""
5+
install=""
6+
install_path="/usr/local/mqttclient"
7+
build_type="Release"
8+
build_shared="OFF"
9+
build_example="OFF"
10+
cmake_arg=""
11+
toolchanin=""
12+
cpu_core="1"
13+
14+
fun_do_config() {
15+
processor=$(cat /proc/cpuinfo | grep "processor" | wc -l)
16+
cpu_core=$(expr ${processor} / 2)
17+
current_pwd=$(
18+
cd "$(dirname "$0")"
19+
pwd
20+
)
21+
mkdir -p $current_pwd/build $current_pwd/build/bin $current_pwd/build/lib
22+
cd $current_pwd/build
23+
}
24+
25+
fun_do_clean() {
26+
if [ -d "$current_pwd/build" ]; then
27+
rm -rdf $current_pwd/build
28+
fi
29+
}
30+
31+
fun_do_help() {
32+
echo "usage: $0 [-i install path] [-c <compiler> / <compiler path>] [-s <on> / <off>] "
33+
echo "[-r / --release] [-d / --debug] [-e] [--toolchanin <toolchanin file>] [--clean]"
34+
echo " [-i] install path: install wturs path"
35+
echo " [-c] compiler: specify the compiler you are using, default: g++"
36+
echo " [-c] compiler path: specify the compiler path you are using"
37+
echo " [-r] build release type: specify the release type, default: release "
38+
echo " [-d] build debug type: specify the build type, default: off "
39+
echo " [--toolchanin] specify toolchanin file"
1240
echo " eg:"
13-
echo " ./build.sh"
14-
echo " ./build.sh arm-linux-gnueabihf-gcc"
15-
echo " ./build.sh /usr/bin/arm-linux-gnueabihf-gcc"
16-
echo " ./build.sh arm-linux-gnueabihf-gcc /usr/bin"
17-
exit
18-
else
19-
if [ " $2" == " " ]; then
41+
echo " $0"
42+
echo " $0 -i"
43+
echo " $0 -i /usr/lib/"
44+
echo " $0 -carm-linux-gnueabihf-gcc"
45+
echo " $0 -c/usr/bin/arm-linux-gnueabihf-gcc"
46+
echo " $0 -r"
47+
echo " $0 -d"
48+
echo " $0 -soff"
49+
echo " $0 -son"
50+
echo " $0 --toolchanin [toolchanin file]"
51+
}
52+
53+
fun_do_install() {
54+
install="true"
55+
if [ " $1" != " " ]; then
56+
install_path=$1
57+
fi
58+
}
59+
60+
fun_do_compiler() {
61+
if [ " $1" != " " ]; then
2062
compiler=$1
21-
else
22-
compiler=$2/$1
2363
fi
24-
fi
64+
}
65+
66+
fun_do_toolchanin() {
67+
if [ " $1" != " " ]; then
68+
toolchanin=$1
69+
fi
70+
}
71+
72+
fun_do_example() {
73+
build_example="ON"
74+
}
75+
76+
fun_do_build_debug() {
77+
build_type="Debug"
78+
}
79+
80+
fun_do_build_release() {
81+
build_type="Release"
82+
}
83+
84+
fun_do_config_shared() {
85+
if [ " $1" != " " ]; then
86+
build_shared=$1
87+
fi
88+
}
89+
90+
fun_do_check() {
91+
if [ " $compiler" != " " ]; then
92+
compiler_path=$(which $compiler)
93+
if [ " $compiler_path" == " " ]; then
94+
echo -e "\033[31mNo $compiler compiler found in the system\033[0m"
95+
exit
96+
fi
97+
fi
98+
99+
echo "compiler : $compiler"
100+
echo "compiler path : $compiler_path"
101+
echo "install : $install"
102+
echo "install path : $install_path"
103+
echo "build type : $build_type"
104+
echo "build example : $build_example"
105+
}
106+
107+
fun_cmake_arg_init() {
108+
if [ " $compiler_path" != " " ]; then
109+
cmake_arg="-DCMAKE_C_COMPILER=$compiler_path $cmake_arg"
110+
fi
111+
112+
if [ " $install_path" != " " ]; then
113+
cmake_arg="-DCMAKE_INSTALL_PREFIX=$install_path $cmake_arg"
114+
fi
115+
116+
if [ " $build_type" != " " ]; then
117+
cmake_arg="-DCMAKE_BUILD_TYPE=$build_type $cmake_arg"
118+
fi
119+
120+
if [ " $build_shared" != " " ]; then
121+
cmake_arg="-DBUILD_SHARED_LIBS=$build_shared $cmake_arg"
122+
fi
123+
124+
if [ " $build_example" != " " ]; then
125+
cmake_arg="-DBUILD_EXAMPLES=$build_example $cmake_arg"
126+
fi
127+
128+
if [ " $toolchanin" != " " ]; then
129+
cmake_arg="-DCMAKE_TOOLCHAIN_FILE=$toolchanin $cmake_arg"
130+
fi
131+
132+
cmake .. $cmake_arg
133+
}
134+
135+
fun_do_make() {
136+
fun_cmake_arg_init
137+
138+
make -j $cpu_core
139+
140+
if [ " $install" != " " ]; then
141+
sudo make install
142+
fi
143+
}
144+
145+
146+
main() {
147+
fun_do_config
148+
149+
# [-h] [-e] [-i install path] [-c compiler path]
150+
ARGS=$(getopt -o hdrei::c::s:: --long help,clean,debug,release,example,install::,compiler::,shared::,toolchanin: -- "$@")
151+
if [ $? != 0 ]; then
152+
echo "Terminating..." >&2
153+
exit 1
154+
fi
155+
eval set -- "$ARGS"
156+
157+
while true; do
158+
case "$1" in
159+
-i | --install)
160+
fun_do_install $2
161+
shift 2
162+
;;
163+
-c | --compiler)
164+
fun_do_compiler $2
165+
shift 2
166+
;;
167+
-s | --shared)
168+
fun_do_config_shared $2
169+
shift 2
170+
;;
171+
-r | --release)
172+
fun_do_build_release
173+
shift
174+
;;
175+
-d | --debug)
176+
fun_do_build_debug
177+
shift
178+
;;
179+
-e | --example)
180+
fun_do_example
181+
shift
182+
;;
183+
-h | --help)
184+
fun_do_help
185+
shift
186+
exit 0
187+
;;
188+
--clean)
189+
fun_do_clean;
190+
shift
191+
exit 0
192+
;;
193+
--toolchanin)
194+
fun_do_toolchanin $2
195+
shift
196+
exit 0
197+
;;
198+
--)
199+
shift
200+
break
201+
;;
202+
*)
203+
echo "unknow : {$1}"
204+
fun_do_help
205+
exit 1
206+
;;
207+
esac
208+
done
209+
210+
fun_do_check
211+
fun_do_make
212+
}
213+
214+
main "$@"
215+
216+
217+
# mkdir -p build build/bin build/lib
218+
# cd build
219+
220+
# if [ " $1" == " " ]; then
221+
# compiler="gcc"
222+
# elif [ $1 == "--help" -o $1 == "-help" -o $1 == "--h" -o $1 == "-h" ]; then
223+
# echo "usage: $0 [compiler] [compiler path]"
224+
# echo " compiler: specify the compiler you are using, default: gcc"
225+
# echo " compiler path: specify the compiler path you are using"
226+
# echo " eg:"
227+
# echo " ./build.sh"
228+
# echo " ./build.sh arm-linux-gnueabihf-gcc"
229+
# echo " ./build.sh /usr/bin/arm-linux-gnueabihf-gcc"
230+
# echo " ./build.sh arm-linux-gnueabihf-gcc /usr/bin"
231+
# exit
232+
# else
233+
# if [ " $2" == " " ]; then
234+
# compiler=$1
235+
# else
236+
# compiler=$2/$1
237+
# fi
238+
# fi
25239

26-
path=$(which $compiler)
240+
# path=$(which $compiler)
27241

28-
if [ " $path" == " " ]; then
29-
echo -e "\033[31mNo $compiler compiler found in the system\033[0m"
30-
exit
31-
fi
242+
# if [ " $path" == " " ]; then
243+
# echo -e "\033[31mNo $compiler compiler found in the system\033[0m"
244+
# exit
245+
# fi
32246

33-
cmake .. "-DCMAKE_C_COMPILER=$path"
247+
# cmake .. "-DCMAKE_C_COMPILER=$path"
34248

35-
make
249+
# make

0 commit comments

Comments
 (0)