Commit c784f610 by ZhongJianfu

update:添加easylogging 日志

parent e1211e78
...@@ -59,5 +59,6 @@ ...@@ -59,5 +59,6 @@
"string_view": "cpp", "string_view": "cpp",
"memory": "cpp", "memory": "cpp",
"string": "cpp" "string": "cpp"
} },
"C_Cpp.errorSquiggles": "Disabled"
} }
\ No newline at end of file
#include <stdio.h>
#include "test.h"
/**
* @brief 测试函数
* @return int
*/
int test1()
{
printf( "Hello test 1\n\r" );
return 0;
}
/**
* @file test2.cpp
* @brief
* @author 钟建福 (983851264@qq.com)
* @version 1.0
* @date 2021-09-14
*
* @copyright Copyright (c) 2021 杭州林克信息科技有限公司
*
* @par 修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-09-14 <td>1.0 <td>钟建福 <td>内容
* </table>
*/
#include <stdio.h>
#include "test2.h"
#include "test.h"
/**
* @brief test2测试函数
* @return int
*/
int test2()
{
test1();
printf("Hello test 2\n\r");
return 0;
}
...@@ -3,17 +3,32 @@ cmake_minimum_required ( VERSION 3.10 ) ...@@ -3,17 +3,32 @@ cmake_minimum_required ( VERSION 3.10 )
project ( helloworld CXX C) project ( helloworld CXX C)
#reset output path #reset output path
set ( EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin ) set ( EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin )
set ( LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib ) set ( LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib )
set ( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS ) set ( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS )
message(STATUS "CMake Info")
message(STATUS "=======================================================")
message(STATUS " Operation System : ${CMAKE_SYSTEM}")
message(STATUS " CPU Architecture : ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS " Build Type : ${CMAKE_BUILD_TYPE}${CMAKE_CONFIGURATION_TYPES}")
message(STATUS " Shared Library : ${BUILD_SHARED_LIBS}")
message(STATUS " Build Examples : ${CSERIALPORT_BUILD_EXAMPLES}")
message(STATUS " Build Test : ${CSERIALPORT_BUILD_TEST}")
message(STATUS "=======================================================")
#set include file #set include file
include_directories (./include) include_directories (./inc)
include_directories ( $ENV{XPL_FEATURE_DIR}/easylogging)
include_directories ( $ENV{XPL_FEATURE_DIR}/easylogging/inc)
#set source file #set source file
aux_source_directory ( . DIR_USR_SOURCE ) aux_source_directory ( . DIR_USR_SOURCE )
aux_source_directory ( $ENV{XPL_FEATURE_DIR}/easylogging/src DIR_USR_SOURCE )
aux_source_directory ( $ENV{XPL_FEATURE_DIR}/easylogging DIR_USR_SOURCE )
# aux_source_directory ( ./src DIR_USR_SOURCE )
#set CC AR LD AS #set CC AR LD AS
set ( CMAKE_C_COMPILER $ENV{CC} ) set ( CMAKE_C_COMPILER $ENV{CC} )
...@@ -41,10 +56,19 @@ if(CMAKE_BUILD_TYPE STREQUAL Debug) ...@@ -41,10 +56,19 @@ if(CMAKE_BUILD_TYPE STREQUAL Debug)
endif() endif()
#添加静态库
add_library ( libtest2 STATIC IMPORTED )
add_library ( libtest1 STATIC IMPORTED )
# #静态库的路径
set_property (TARGET libtest1 PROPERTY IMPORTED_LOCATION $ENV{XPL_THIRDPARTY_DIR}/test1/libtest1.a)
set_property (TARGET libtest2 PROPERTY IMPORTED_LOCATION $ENV{XPL_THIRDPARTY_DIR}/test2/libtest2.a)
MESSAGE( STATUS "There are source files : ${DIR_USR_SOURCE}.") MESSAGE( STATUS "There are source files : ${DIR_USR_SOURCE}.")
#generate target #generate target
add_executable ( ${CMAKE_PROJECT_NAME} ${DIR_USR_SOURCE} ) add_executable ( ${CMAKE_PROJECT_NAME} ${DIR_USR_SOURCE} )
target_link_libraries ( ${CMAKE_PROJECT_NAME} pthread libtest1 libtest2 )
#add custom #add custom
add_custom_target ( clean-all COMMAND rm -rf {CMAKE_BINARY_DIR}/* ) add_custom_target ( clean-all COMMAND rm -rf {CMAKE_BINARY_DIR}/* )
...@@ -56,13 +56,13 @@ then ...@@ -56,13 +56,13 @@ then
echo "====================================....clean Success....=========================================" echo "====================================....clean Success....========================================="
else else
echo "====================================....Build start....===============================================" echo "====================================....Build start....==============================================="
make -j 4 make -j8
echo "generate helloworld at ./Build/bin/" echo "generate helloworld at ./Build/bin/"
echo "====================================....Build Success....=========================================" echo "====================================....Build Success....========================================="
echo "press anykey to running helloworld!" echo "press anykey to running helloworld!"
read input read input
cd $project_path/Build/bin cd $project_path
./helloworld ./Build/bin/helloworld
fi fi
...@@ -2,6 +2,7 @@ export XPL_OBJECT_TYPE="LINUX-X86" ...@@ -2,6 +2,7 @@ export XPL_OBJECT_TYPE="LINUX-X86"
export XPL_PROJECT_DIR=$(pwd) export XPL_PROJECT_DIR=$(pwd)
export XPL_FEATURE_DIR=$XPL_PROJECT_DIR/feature export XPL_FEATURE_DIR=$XPL_PROJECT_DIR/feature
export XPL_PROTOCOL_DIR=$XPL_PROJECT_DIR/protocol export XPL_PROTOCOL_DIR=$XPL_PROJECT_DIR/protocol
export XPL_THIRDPARTY_DIR=$XPL_PROJECT_DIR/thirdparty
export CCACHE_PATH=/usr/bin:$CCACHE_PATH export CCACHE_PATH=/usr/bin:$CCACHE_PATH
export CC="gcc" export CC="gcc"
export AR="gcc-ar" export AR="gcc-ar"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
#include "my_easylogging.h"
using namespace std;
INT32 G_LOG_ENABLE = 0; //调试中的变量,写0就好了。写1则开启相应打印
INT32 G_DEBUG_LOG_ENABLE = 0; //调试中的变量,写0就好了。
INT32 G_DEBUG_PRINT_SOCKET_BUFF = 0; //调试中的变量,写0就好了。启用的话会打印很长的数据包的。
INT32 G_LOG_INIT_INFO = 1; //初始化信息打印进log文件 启动后,都是一次性信息。默认打开
//这两个可以由上层应用控制 开关
INT32 G_LOG_DEBUG_INFO = 1; //调试用的化信息打印进log文件
INT32 G_DEBUG_TERMINAL_LOG = 1; //把调试信息打印到终端
// #define LogInfoDump(info, size, buff) logDump(info, buff, size, LEVEL::MY_Info)
// #define LogTraceDump(info, size, buff) logDump(info, buff, size, LEVEL::MY_Trace)
// #define LogWarnDump(info, size, buff) logDump(info, buff, size, LEVEL::MY_Warn)
// #define LogErrorDump(info, size, buff) logDump(info, buff, size, LEVEL::MY_ERR)
// #define LogDebugDump(info, size, buff) logDump(info, buff, size, LEVEL::MY_Debug)
// easylogging 相关内容
INITIALIZE_EASYLOGGINGPP
#if ELPP_FEATURE_CRASH_LOG
/**
* @brief myCrashHandler
* 程序奔溃前的回调函数,发出最后的呐喊,写下最后的log
* @param sig
*/
void myCrashHandler(int sig)
{
LOG(ERROR) << "Woops! Crashed!";
// FOLLOWING LINE IS ABSOLUTELY NEEDED AT THE END IN ORDER TO ABORT APPLICATION
el::Helpers::crashAbort(sig);
}
#endif
/**
* @brief rolloutHandler
* 日志备份,当文件超过一定大小后,就生成一个bak文件
* @param filename
* @param size
*/
void rolloutHandler(const char *filename, std::size_t size)
{
/// 备份日志
static unsigned int idx;
#if defined(_WIN32)
cout << "###########LOG SIZE FULL#############" << endl;
std::stringstream ss;
string cc;
ss << "ren " << filename << " log_backup_" << ++idx;
cc = ss.str();
replace(cc.begin(), cc.end(), '/', '\\');
system(cc.c_str());
#else
/*下面这段没有测试过*/
system("mkdir bin");
std::stringstream ss;
ss << "move " << filename << " bin\\log_backup_" << ++idx;
system(ss.str().c_str());
#endif
}
/**
* @brief easylogginginit
* easylogging初始化函数,加载配置文件,注册回调函数都在这里。
*/
void easylogginginit()
{
/*
必须设置标记 LoggingFlag::StrictLogFileSizeCheck
否则,配置文件中MAX_LOG_FILE_SIZE = 1048576不生效
*/
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
const string log_conf_file = R"(./log/log.conf)";
// const string log_conf_file = R"(/root/gitlab/xdevice-platform/doc/log.conf)";
// 加载配置文件,构造一个配置器对象
el::Configurations conf(log_conf_file.data());
// 用配置文件配置所有的日志记录器
el::Loggers::reconfigureAllLoggers(conf);
#if ELPP_FEATURE_CRASH_LOG
el::Helpers::setCrashHandler(myCrashHandler); //配置程序闪退的时候,再log中记录一下
#endif
/// 注册回调函数
el::Helpers::installPreRollOutCallback(rolloutHandler);
}
/**
* @brief
* @param size 日志长度
* @param str 日志内容
* @param logLevel 当前日志等级
*/
void logStrOut(int size, std::string str, LEVEL logLevel)
{
switch (logLevel)
{
case MY_ERR:
// LOG(ERROR) << "[Arr Count:" << size << "]" << str;
LOG(ERROR) << str;
break;
case MY_Debug:
// LOG(DEBUG) << "[Arr Count:" << size << "]" << str;
LOG(DEBUG) << str;
break;
case MY_Info:
// LOG(INFO) << "[Arr Count:" << size << "]" << str;
LOG(INFO) << str;
break;
case MY_Trace:
// LOG(TRACE) << "[Arr Count:" << size << "]" << str;
LOG(TRACE) << str;
break;
case MY_Warn:
// LOG(WARNING) << "[Arr Count:" << size << "]" << str;
LOG(WARNING) << str;
break;
default:
break;
}
}
/**
* @brief
* 对char *型特例化
* @tparam
* @param info My Param doc
* @param buff My Param doc
* @param size My Param doc
* @param logLevel My Param doc
*/
template <>
void logDump(char *info, char *buff, int size, LEVEL logLevel)
{
std::string str(info);
str += "(ASCII): ";
if (buff == NULL || size <= 0)
str += "buff is null!";
else
{
std::stringstream ss;
for (int _dumpArrSize = 0; _dumpArrSize < size; ++_dumpArrSize)
ss << static_cast<int>(buff[_dumpArrSize]) << " ";
str += ss.str();
}
logStrOut(size, str, logLevel);
}
/**
* @brief
* 对UINT8 *型特例化 安装16进制打印
* @tparam
* @param info My Param doc
* @param buff My Param doc
* @param size My Param doc
* @param logLevel My Param doc
*/
template <>
void logDump(char *info, UINT8 *buff, int size, LEVEL logLevel)
{
std::string str(info);
str += "(HEX): ";
if (buff == NULL || size <= 0)
str += "buff is null!";
else
{
std::stringstream ss, s1;
for (int _dumpArrSize = 0; _dumpArrSize < size; ++_dumpArrSize)
// s1 =(buff[_dumpArrSize];
ss << std::hex << static_cast<uint>(buff[_dumpArrSize]) << " ";
str += ss.str();
}
logStrOut(size, str, logLevel);
}
// template <typename T>
// void fun(T a)
// {
// cout << "The main template fun(): " << a << endl;
// }
// template <> // 对int型特例化
// void fun(int a)
// {
// cout << "Specialized template for int type: " << a << endl;
// }
/**
* @brief
* 测试函数
*/
void log_test()
{
char aa = 4;
// char *cc = "12345";
UINT8 cc[] = {0X31, 0X31, 0X31};
char buf[3] = {5, 6, 7};
LOG(INFO) << "》》》》》》》》》》打印测试《《《《《《《《";
LOG(INFO) << " UINT8 cc[] = {0X31, 0X31, 0X31};";
LOG(INFO) << " char buf[3] = {5, 6, 7};";
LOG(INFO) << "#################封装之前###########";
LOG(INFO) << "打印cc :" << cc;
LOG(INFO) << "打印buf[3]:"
<< "buf = " << buf << " buf[0] = " << buf[0] << " buf[1] = " << buf[1] << " (INT8)buf[2] = " << (UINT8)(buf[2]);
LOG(INFO) << "####################封装之后##########";
LogInfoDump("打印cc", cc, 3);
LogInfoDump("打印buf[3]", buf, 3);
}
/**
* @brief En_G_LOG_DEBUG_INFO
* 配置是否将debug信息写入log文本
* @param is_en
*/
void En_G_LOG_DEBUG_INFO(int is_en)
{
if (is_en == 1)
{
G_LOG_DEBUG_INFO = 1;
}
else
{
G_LOG_DEBUG_INFO = 0;
}
}
/**
* @brief En_G_DEBUG_TERMINAL_LOG
* 配置是否将debug信息打印到terminal
* @param is_en
*/
void En_G_DEBUG_TERMINAL_LOG(int is_en)
{
if (is_en == 1)
{
G_DEBUG_TERMINAL_LOG = 1;
}
else
{
G_DEBUG_TERMINAL_LOG = 0;
}
}
/**
* @brief printf_init_log
* 印初始化log 适配了QT可以在终端显示出来
* @param log_info
*/
void printf_init_log(char *log_info)
{
LOG_IF(G_LOG_INIT_INFO, INFO) << log_info;
#if defined(_WIN32)
if (G_DEBUG_TERMINAL_LOG)
{
qDebug() << log_info;
}
#else
if (G_DEBUG_TERMINAL_LOG)
{
cout << log_info << endl;
}
#endif
}
/**
* @brief printf_debug_log
* 打印调试log
* @param log_info
*/
void printf_debug_log(char *log_info)
{
LOG_IF(G_LOG_DEBUG_INFO, INFO) << log_info;
#if defined(_WIN32)
if (G_DEBUG_TERMINAL_LOG)
{
qDebug() << log_info;
}
#else
if (G_DEBUG_TERMINAL_LOG)
{
cout << log_info << endl;
}
#endif
}
\ No newline at end of file
#ifndef _MY_EASYLOGGING_H_
#define _MY_EASYLOGGING_H_
#include "inc/easylogging++.h"
#include "normal_typedef.h"
enum LEVEL
{
MY_ERR = 0,
MY_Warn,
MY_Debug,
MY_Trace,
MY_Info
};
void myCrashHandler(int sig);
void rolloutHandler(const char *filename, std::size_t size);
void easylogginginit();
void logStrOut(int size, std::string str, LEVEL logLevel);
#define LogInfoDump(info, buff, size) logDump(info, buff, size, LEVEL::MY_Info)
#define LogTraceDump(info, buff, size) logDump(info, buff, size, LEVEL::MY_Trace)
#define LogWarnDump(info, buff, size) logDump(info, buff, size, LEVEL::MY_Warn)
#define LogErrorDump(info, buff, size) logDump(info, buff, size, LEVEL::MY_ERR)
#define LogDebugDump(info, buff, size) logDump(info, buff, size, LEVEL::MY_Debug)
/**
* @brief
* 能方便输出:char buf[len] , int buf[lend]等数组,
* 而无需区分数组元素是字符类型还是整数类型。
* 能方便输出数据包。
* @tparam _TYPE
* @param info 日志头
* @param buff 日志内容
* @param size buff的size
* @param logLevel 日志等级
*/
template <typename T1>
void logDump(char *info, T1 *buff, int size, LEVEL logLevel)
{
std::string str(info);
str += ": ";
if (buff == NULL || size <= 0)
str += "buff is null!";
else
{
std::stringstream ss;
for (int _dumpArrSize = 0; _dumpArrSize < size; ++_dumpArrSize)
ss << (buff[_dumpArrSize]) << ",";
str += ss.str();
}
logStrOut(size, str, logLevel);
}
template <>
void logDump(char *info, char *buff, int size, LEVEL logLevel);
template <>
void logDump(char *info, UINT8 *buff, int size, LEVEL logLevel);
void log_test();
// template <typename T>
// void fun(T a)
// {
// std::cout << "The main template fun(): " << a << std::endl;
// }
// template <> // 对int型特例化
// void fun(int a);
void printf_init_log(char *log_info);
void printf_debug_log(char *log_info);
void En_G_LOG_DEBUG_INFO(int is_en);
void En_G_DEBUG_TERMINAL_LOG(int is_en);
#endif
// template <>
// void logDump(char *info, unsigned char *buff, int size, LEVEL logLevel);
// template <>
// void logDump(char *info, const char *buff, int size, LEVEL logLevel);
// template <>
// void logDump(char *info, const unsigned char *buff, int size, LEVEL logLevel);
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* @file normal_typedef.h
* @brief common typedef
* @author Fan Chuanlin, fanchuanlin@aliyun.com
* @version 1.0
* @date 2021-01-29
* @attention
* @brief History:
* <table>
* <tr><th> Date <th> Version <th> Author <th> Description
* <tr><td> xxx-xx-xx <td> 1.0 <td> Fan Chuanlin <td> Create
* </table>
*
*/
#ifndef _NORMAL_TYPEDEF_H_
#define _NORMAL_TYPEDEF_H_
#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <math.h>
#include <sys/time.h>
/// SOCKET
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/time.h>
#include <pthread.h>
#if defined(_WIN32)
#include <WinSock2.h> //WindowsSocket
#include <ws2tcpip.h>
#include <windows.h>
// typedef struct tagTHREADNAME_INFO
//{
// DWORD dwType; // must be 0x1000
// LPCSTR szName; // pointer to name (in user addr space)
// DWORD dwThreadID; // thread ID (-1=caller thread)
// DWORD dwFlags; // reserved for future use, must be zero
// } THREADNAME_INFO;
// void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName)
//{
// THREADNAME_INFO info;
// info.dwType = 0x1000;
// info.szName = szThreadName;
// info.dwThreadID = dwThreadID;
// info.dwFlags = 0;
// __try
// {
// RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info );
// }
// __catch(EXCEPTION_CONTINUE_EXECUTION){}
//}
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/prctl.h>
#endif
/// define c++11 std
#if 11
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#endif
/**
* @name define normal type;
*
** @} */
#if defined(_WIN32)
#else
typedef bool BOOLEAN;
typedef void VOID;
typedef int SOCKET;
#endif
typedef unsigned char UINT8;
typedef signed char INT8;
typedef unsigned char OCTET;
typedef char CHAR;
typedef unsigned short UINT16;
typedef signed short INT16;
typedef unsigned int UINT32;
typedef signed int INT32;
typedef unsigned long ULONG;
typedef signed long LONG;
typedef unsigned long long UINT64;
typedef long long INT64;
typedef float FLOAT;
typedef double DOUBLE;
typedef int SOCKET_FP;
/// for socket
#if defined(_WIN32)
#else
#define INVALID_SOCKET -1
typedef int SOCKET;
#endif
typedef int af_family;
typedef int in_port;
#define BACKLOG_LEN 10
#define SOCKET_SERVER_PORT 6666
#define SOCKET_CLIENT_PORT 9999
#define LOCAL_HOST "127.0.0.1" ///< 默认ip本地回环地址
///< 网络角色枚举
typedef enum
{
SOCKET_ROLE_SERVER = 0,
SOCKET_ROLE_CLIENT = 1
} SOCKET_ROLE_E;
///< 网络通讯协议的枚举
typedef enum
{
SOCKET_PROTO_TCP = 0,
SOCKET_PROTO_UDP = 1,
SOCKET_PROTO_UDP_MC = 2 ///< udp 组播通讯
} SOCKET_PROTO_E;
#if defined(_WIN32)
#else
#define TRUE true
#define FALSE false
#endif
///<记录返回状态
typedef enum
{
Lret_success = 0, ///< 成功
Lret_fail = 1, ///< 失败
Lret_timeout = 2, ///< 超时错误
Lret_accept_fail = 3, ///< accept失败
Lret_connet_fail = 4, ///< 连接失败
Lret_recv_fail = 5, ///< 接收失败
Lret_format_fail = 6, ///< 格式打包失败
Lret_param_check_error = 7, ///< 报文参数检查失败
Lret_max,
} Lret;
const char ret_str[][30] =
{
" success ",
" fail ",
" timeout ",
" accept_fail ",
" connet_fail ",
" recv_fail ",
" format_fail ",
" param_check_error "};
#endif
/**
* @file test.h
* @brief
* @author 钟建福 (983851264@qq.com)
* @version 1.0
* @date 2021-09-14
*
* @copyright Copyright (c) 2021 杭州林克信息科技有限公司
*
* @par 修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-09-14 <td>1.0 <td>钟建福 <td>内容
* </table>
*/
/**
* @brief 测试函数
* @return int
*/
int test1();
\ No newline at end of file
/**
* @file test2.h
* @brief
* @author 钟建福 (983851264@qq.com)
* @version 1.0
* @date 2021-09-14
*
* @copyright Copyright (c) 2021 杭州林克信息科技有限公司
*
* @par 修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-09-14 <td>1.0 <td>钟建福 <td>内容
* </table>
*/
/**
* @brief
* @return int
*/
int test2();
\ No newline at end of file
* GLOBAL:
FORMAT = "%datetime:[%level]%msg"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = false
PERFORMANCE_TRACKING = false
MAX_LOG_FILE_SIZE = 209715200
FILENAME = "./log/info_%datetime{%Y%M%d}.log"
* INFO:
FORMAT = "%datetime %msg"
ENABLED = true
TO_STANDARD_OUTPUT = true
* DEBUG:
FORMAT = "%datetime:[%level] %func[%line] %msg"
ENABLED = true
* WARNING:
ENABLED = true
* TRACE:
ENABLED = false
FILENAME = "./log/trace_%datetime{%Y%M%d}.log"
* VERBOSE:
FORMAT = "%datetime{%d/%M/%y} | %level-%vlevel | %msg"
ENABLED = true
* ERROR:
FORMAT = "%datetime:[%level] %msg"
ENABLED = true
TO_STANDARD_OUTPUT = true
* FATAL:
ENABLED = true
TO_STANDARD_OUTPUT = true
#include <stdio.h> #include <stdio.h>
#include "test.h"
#include "test2.h"
#include <iostream>
#include "my_easylogging.h"
int main() int main()
{ {
easylogginginit();
log_test();
printf( "Hello world\n\r" ); printf("Hello world\n\r");
test1();
test2();
try
{
throw 20;
}
catch (int e)
{
std::cout << "An exception occurred. Exception Nr. " << e << '\n';
}
return 0; return 0;
} }
cmake_minimum_required(VERSION 3.0.0)
#设置可执行文件的名字
project(test1 VERSION 0.1.0)
#reset output path 设置编译生成文件的存放路径
set ( EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin )
set ( LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib )
include(CTest)
enable_testing()
#set include file 配置头文件路径
include_directories (./inc)
#set source file 配置源文件路径
aux_source_directory ( . DIR_USR_SOURCE )
aux_source_directory ( ./src DIR_USR_SOURCE )
add_library(${CMAKE_PROJECT_NAME} ${DIR_USR_SOURCE})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
#!/bin/bash
echo "=======================Bulid helloworld Test================="
echo "$1"
echo "$2"
echo "$3"
project_path=$(cd `dirname $0`; pwd)
project_name="${project_path##*/}"
echo $project_path
echo $project_name
check_build_dir=`ls -l |grep "build"`
echo $check_build_dir
if [[ $check_build_dir =~ "Build/" ]]
then
echo "Has bulid Directroy!"
else
echo "Create Build Directory!"
mkdir -p Build
fi
#app build
cd $project_path/Build/
cmake -D CMAKE_BUILD_TYPE=$2 ..
if [[ "$1" =~ "clean" ]]
then
make clean-all
rm -rf ./*
#clear swp
cd $project_path
#python version
python -V
rtn="$?"
if [[ $rtn == "0" ]]
then
echo "python"
python cleartmp.py
else
echo "python3"
python3 cleartmp.py
fi
echo $check_python_ver
echo "====================================....clean Success....========================================="
else
echo "====================================....Build start....==============================================="
make -j4
echo "generate target at ./Build/bin/"
# echo "====================================....Build Success....========================================="
# read input
# cd $project_path/Build/bin
fi
export XPL_OBJECT_TYPE="LINUX-X86"
export XPL_PROJECT_DIR=$(pwd)
export XPL_FEATURE_DIR=$XPL_PROJECT_DIR/feature
export XPL_PROTOCOL_DIR=$XPL_PROJECT_DIR/protocol
export CCACHE_PATH=/usr/bin:$CCACHE_PATH
export CC="gcc"
export AR="gcc-ar"
export CXX="g++"
export CPP="gcc"
export AS="as"
export GDB=gdb
export STRIP=strip
export RANLIB=ranlib
export OBJCOPY=objcopy
export OBJDUMP=objdump
/**
* @file test.h
* @brief
* @author 钟建福 (983851264@qq.com)
* @version 1.0
* @date 2021-09-14
*
* @copyright Copyright (c) 2021 杭州林克信息科技有限公司
*
* @par 修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-09-14 <td>1.0 <td>钟建福 <td>内容
* </table>
*/
/**
* @brief 测试函数
* @return int
*/
int test1();
\ No newline at end of file
#include <stdio.h>
#include "test.h"
/**
* @brief 测试函数
* @return int
*/
int test1()
{
printf("Hello test 1\n\r");
return 0;
}
cmake_minimum_required(VERSION 3.0.0)
#设置可执行文件的名字
project(test2 VERSION 0.1.0)
#reset output path 设置编译生成文件的存放路径
set ( EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin )
set ( LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib )
include(CTest)
enable_testing()
#set include file 配置头文件路径
include_directories (./inc)
# include_directories (${XPL_THIRDPARTY_DIR}/test1/inc)
include_directories (./thirdparty/test1/inc)
#set source file 配置源文件路径
aux_source_directory ( . DIR_USR_SOURCE )
aux_source_directory ( ./src DIR_USR_SOURCE )
#添加静态库
# add_library ( libtest1 STATIC IMPORTED )
# #静态库的路径
# set_property (TARGET libtest1 PROPERTY IMPORTED_LOCATION ./thirdparty/test1/libtest1.a)
add_library(${CMAKE_PROJECT_NAME} ${DIR_USR_SOURCE})
# target_link_libraries ( ${CMAKE_PROJECT_NAME} libtest1)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
#!/bin/bash
echo "=======================Bulid helloworld Test================="
echo "$1"
echo "$2"
echo "$3"
project_path=$(cd `dirname $0`; pwd)
project_name="${project_path##*/}"
echo $project_path
echo $project_name
check_build_dir=`ls -l |grep "build"`
echo $check_build_dir
if [[ $check_build_dir =~ "Build/" ]]
then
echo "Has bulid Directroy!"
else
echo "Create Build Directory!"
mkdir -p Build
fi
#app build
cd $project_path/Build/
cmake -D CMAKE_BUILD_TYPE=$2 ..
if [[ "$1" =~ "clean" ]]
then
make clean-all
rm -rf ./*
#clear swp
cd $project_path
#python version
python -V
rtn="$?"
if [[ $rtn == "0" ]]
then
echo "python"
python cleartmp.py
else
echo "python3"
python3 cleartmp.py
fi
echo $check_python_ver
echo "====================================....clean Success....========================================="
else
echo "====================================....Build start....==============================================="
make -j4
echo "generate target at ./Build/bin/"
fi
export XPL_OBJECT_TYPE="LINUX-X86"
export XPL_PROJECT_DIR=$(pwd)
export XPL_FEATURE_DIR=$XPL_PROJECT_DIR/feature
export XPL_PROTOCOL_DIR=$XPL_PROJECT_DIR/protocol
export XPL_THIRDPARTY_DIR=$XPL_PROJECT_DIR/thirdparty
export CCACHE_PATH=/usr/bin:$CCACHE_PATH
export CC="gcc"
export AR="gcc-ar"
export CXX="g++"
export CPP="gcc"
export AS="as"
export GDB=gdb
export STRIP=strip
export RANLIB=ranlib
export OBJCOPY=objcopy
export OBJDUMP=objdump
/**
* @file test2.h
* @brief
* @author 钟建福 (983851264@qq.com)
* @version 1.0
* @date 2021-09-14
*
* @copyright Copyright (c) 2021 杭州林克信息科技有限公司
*
* @par 修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-09-14 <td>1.0 <td>钟建福 <td>内容
* </table>
*/
/**
* @brief
* @return int
*/
int test2();
\ No newline at end of file
/**
* @file test2.cpp
* @brief
* @author 钟建福 (983851264@qq.com)
* @version 1.0
* @date 2021-09-14
*
* @copyright Copyright (c) 2021 杭州林克信息科技有限公司
*
* @par 修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-09-14 <td>1.0 <td>钟建福 <td>内容
* </table>
*/
#include <stdio.h>
#include "test2.h"
#include "test.h"
/**
* @brief test2测试函数
* @return int
*/
int test2()
{
test1();
printf("Hello test 2\n\r");
return 0;
}
/**
* @file test.h
* @brief
* @author 钟建福 (983851264@qq.com)
* @version 1.0
* @date 2021-09-14
*
* @copyright Copyright (c) 2021 杭州林克信息科技有限公司
*
* @par 修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-09-14 <td>1.0 <td>钟建福 <td>内容
* </table>
*/
/**
* @brief 测试函数
* @return int
*/
int test1();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment