Improve build for log.
This commit is contained in:
parent
cdccef76a7
commit
690522256a
|
@ -1 +1,2 @@
|
|||
add_subdirectory(main)
|
||||
add_subdirectory(MissionManager)
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
|
|
57
application/main/CMakeLists.txt
Normal file
57
application/main/CMakeLists.txt
Normal file
|
@ -0,0 +1,57 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
|
||||
set(MAIN_INCLUDE_PATH "${APPLICATION_SOURCE_PATH}/main/src" CACHE STRING INTERNAL FORCE)
|
||||
set(MAIN_INCLUDE_PATH "${MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/StatusCode/include" CACHE STRING INTERNAL FORCE)
|
||||
set(MAIN_INCLUDE_PATH "${MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/Log/include" CACHE STRING INTERNAL FORCE)
|
||||
include_directories(${MAIN_INCLUDE_PATH})
|
||||
|
||||
link_directories(
|
||||
${LIBS_OUTPUT_PATH}
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
aux_source_directory(./ SRC_FILES)
|
||||
# aux_source_directory(./src SRC_FILES)
|
||||
|
||||
# Mark src files for test.
|
||||
file(GLOB_RECURSE MAIN_SRC_FILE_THIS src/*.cpp src/*.c)
|
||||
set(MAIN_SRC_FILE "${MAIN_SRC_FILE_THIS}" CACHE STRING INTERNAL FORCE)
|
||||
|
||||
|
||||
set(TARGET_LIB MainLib)
|
||||
add_library(${TARGET_LIB} STATIC ${MAIN_SRC_FILE_THIS})
|
||||
set(TARGET_NAME ipc_x86)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
|
||||
set(LINK_LIB StatusCode Log pthread dl)
|
||||
set(MAIN_LINK_LIB "${LINK_LIB}" CACHE STRING INTERNAL FORCE)
|
||||
target_link_libraries(${TARGET_LIB} ${MAIN_LINK_LIB})
|
||||
target_link_libraries(${TARGET_NAME} ${TARGET_LIB})
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
ipc_x86_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${MAIN_SRC_FILE_THIS}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
-p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/main
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make ipc_x86_code_check
|
||||
WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
24
application/main/main.cpp
Normal file
24
application/main/main.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "MainThread.h"
|
||||
#include "ILog.h"
|
||||
#include <thread>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
MainThread::GetInstance()->Init();
|
||||
MainThread::GetInstance()->Runing();
|
||||
MainThread::GetInstance()->UnInit();
|
||||
return 0;
|
||||
}
|
65
application/main/src/MainThread.cpp
Normal file
65
application/main/src/MainThread.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "MainThread.h"
|
||||
#include "ILog.h"
|
||||
#include <thread>
|
||||
MainThread::MainThread()
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MainThread>();
|
||||
if (impl)
|
||||
{
|
||||
if (instance.use_count() == 1)
|
||||
{
|
||||
LogInfo("Instance changed succeed.\n");
|
||||
instance = *impl;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogError("Can't changing the instance becase of using by some one.\n");
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
StatusCode MainThread::Init(void)
|
||||
{
|
||||
mMainThreadRuning = true;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::UnInit(void)
|
||||
{
|
||||
DestoryAllModules();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::CreateAllModules(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MainThread::DestoryAllModules(void)
|
||||
{
|
||||
}
|
||||
void MainThread::ResetAllPtrMaker(void)
|
||||
{
|
||||
}
|
||||
void MainThread::Runing(void)
|
||||
{
|
||||
while (mMainThreadRuning)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
39
application/main/src/MainThread.h
Normal file
39
application/main/src/MainThread.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MAIN_THREAD_H
|
||||
#define MAIN_THREAD_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class MainThread
|
||||
{
|
||||
public:
|
||||
MainThread();
|
||||
virtual ~MainThread() = default;
|
||||
static std::shared_ptr<MainThread> &GetInstance(std::shared_ptr<MainThread> *impl = nullptr);
|
||||
virtual StatusCode Init(void);
|
||||
virtual StatusCode UnInit(void);
|
||||
void Runing(void);
|
||||
void Exit(void) { mMainThreadRuning = false; }
|
||||
virtual void CustomizationInit(void) {}
|
||||
|
||||
private:
|
||||
StatusCode CreateAllModules(void);
|
||||
void DestoryAllModules(void);
|
||||
void ResetAllPtrMaker(void);
|
||||
|
||||
private:
|
||||
bool mMainThreadRuning;
|
||||
};
|
||||
#endif // !MAIN_THREAD_H
|
|
@ -32,7 +32,7 @@ set(TOOLCHAIN_NAME arm-linux-gnueabihf)
|
|||
set(TARGET_PLATFORM "linux")
|
||||
set(SUBMODULE_PATH_OF_IPCSDK "")
|
||||
set(PLATFORM_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(COVERAGE_ON "true")
|
||||
set(TEST_COVERAGE "true")
|
||||
|
||||
# ------------ build curl + openssl ------------ start
|
||||
set(CURL_OPENSSL_LIB_SHARED_ENABLE "false")
|
||||
|
|
|
@ -13,6 +13,7 @@ set(HAL_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/hal")
|
|||
set(TEST_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/test")
|
||||
set(EXTERNAL_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/external")
|
||||
|
||||
# -------------------------- clang-tidy tools -------------------------- #
|
||||
set(CLANG_TIDY_CHECKS "-*,\
|
||||
llvm-else-after-return,\
|
||||
-llvm-include-order,\
|
||||
|
@ -43,4 +44,32 @@ readability-identifier-naming")
|
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-clang-diagnostic-error")
|
||||
|
||||
set(CLANG_TIDY_CONFIG "-header-filter=\'.*\'")
|
||||
set(CLANG_TIDY_CONFIG "${CLANG_TIDY_CONFIG} -p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell")
|
||||
set(CLANG_TIDY_CONFIG "${CLANG_TIDY_CONFIG} -p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell")
|
||||
# -------------------------- clang-tidy tools end -------------------------- #
|
||||
|
||||
# -------------------------- log setting -------------------------- #
|
||||
function(define_file_name target)
|
||||
get_target_property(source_files "${target}" SOURCES)
|
||||
foreach(source_file ${source_files})
|
||||
get_property(defs SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS)
|
||||
get_filename_component(file_name "${source_file}" NAME)
|
||||
list(APPEND defs "__F_FILE__=\"${file_name}\"")
|
||||
set_property(
|
||||
SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS ${defs})
|
||||
endforeach()
|
||||
endfunction()
|
||||
function(log_disable target)
|
||||
get_target_property(source_files "${target}" SOURCES)
|
||||
foreach(source_file ${source_files})
|
||||
get_property(defs SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS)
|
||||
get_filename_component(file_name "${source_file}" NAME)
|
||||
list(APPEND defs "LOG_DISABLE")
|
||||
set_property(
|
||||
SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS ${defs})
|
||||
endforeach()
|
||||
endfunction()
|
||||
# -------------------------- log setting end -------------------------- #
|
|
@ -15,7 +15,7 @@ else()
|
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os")
|
||||
endif()
|
||||
|
||||
if(${COVERAGE_ON} MATCHES "true")
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
message("you choose to build gcno file")
|
||||
add_definitions("-fprofile-arcs")
|
||||
add_definitions("-ftest-coverage")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
|
|
|
@ -30,6 +30,6 @@ aux_source_directory(${TEST_SOURCE_PATH}/middleware/IpcConfig/src SRC_FILES)
|
|||
set(TARGET_NAME AllTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} IpcConfig gtest gmock pthread)
|
||||
if(${COVERAGE_ON} MATCHES "true")
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
|
@ -27,6 +27,6 @@ aux_source_directory(./src SRC_FILES)
|
|||
set(TARGET_NAME IHalTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} gtest gmock pthread Hal)
|
||||
if(${COVERAGE_ON} MATCHES "true")
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
|
@ -31,7 +31,7 @@ aux_source_directory(./src SRC_FILES)
|
|||
set(TARGET_NAME IpcConfigTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} IpcConfig gtest gmock pthread)
|
||||
if(${COVERAGE_ON} MATCHES "true")
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||
|
@ -54,4 +54,5 @@ add_custom_command(
|
|||
COMMAND make IpcConfigTest_code_check
|
||||
WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
define_file_name(${TARGET_NAME})
|
|
@ -32,7 +32,7 @@ aux_source_directory(./src SRC_FILES)
|
|||
set(TARGET_NAME ConfigTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} Config gtest gmock pthread)
|
||||
if(${COVERAGE_ON} MATCHES "true")
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||
|
|
|
@ -29,7 +29,7 @@ aux_source_directory(./src SRC_FILES)
|
|||
set(TARGET_NAME LogTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} Log gtest gmock pthread)
|
||||
if(${COVERAGE_ON} MATCHES "true")
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||
|
|
|
@ -29,6 +29,6 @@ set(TARGET_NAME LogCTest)
|
|||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} gtest gmock pthread ReturnCode LogCAbstract)
|
||||
# target_link_libraries(${TARGET_NAME} gtest gmock pthread ReturnCode LogCAbstract LogCUb)
|
||||
if(${COVERAGE_ON} MATCHES "true")
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
|
@ -27,6 +27,6 @@ aux_source_directory(./src SRC_FILES)
|
|||
set(TARGET_NAME ReturnCodeTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} gtest gmock pthread Log)
|
||||
if(${COVERAGE_ON} MATCHES "true")
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
|
@ -60,4 +60,6 @@ add_custom_command(
|
|||
PRE_BUILD
|
||||
COMMAND make compile_libconfig
|
||||
WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell
|
||||
)
|
||||
)
|
||||
|
||||
define_file_name(${TARGET_NAME})
|
|
@ -26,12 +26,24 @@ extern "C"
|
|||
LOG_EASYLOGGING, // for easylogging++.
|
||||
LOG_INSTANCE_TYPE_END
|
||||
};
|
||||
#define LogVerbose(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_VERBOSE, __VA_ARGS__)
|
||||
#define LogDebug(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_DEBUG, __VA_ARGS__)
|
||||
#define LogInfo(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_INFORMATION, __VA_ARGS__)
|
||||
#define LogWarning(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_WARNING, __VA_ARGS__)
|
||||
#define LogError(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_ERROR, __VA_ARGS__)
|
||||
#define LogTrace(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_TRACE, __VA_ARGS__)
|
||||
#ifndef __F_FILE__
|
||||
#define __F_FILE__ "fancy"
|
||||
#endif
|
||||
#ifndef LOG_DISABLE
|
||||
#define LogVerbose(...) GetLogIntance()->printf(GetLogIntance(), __F_FILE__, __LINE__, LOG_TYPE_VERBOSE, __VA_ARGS__)
|
||||
#define LogDebug(...) GetLogIntance()->printf(GetLogIntance(), __F_FILE__, __LINE__, LOG_TYPE_DEBUG, __VA_ARGS__)
|
||||
#define LogInfo(...) GetLogIntance()->printf(GetLogIntance(), __F_FILE__, __LINE__, LOG_TYPE_INFORMATION, __VA_ARGS__)
|
||||
#define LogWarning(...) GetLogIntance()->printf(GetLogIntance(), __F_FILE__, __LINE__, LOG_TYPE_WARNING, __VA_ARGS__)
|
||||
#define LogError(...) GetLogIntance()->printf(GetLogIntance(), __F_FILE__, __LINE__, LOG_TYPE_ERROR, __VA_ARGS__)
|
||||
#define LogTrace(...) GetLogIntance()->printf(GetLogIntance(), __F_FILE__, __LINE__, LOG_TYPE_TRACE, __VA_ARGS__)
|
||||
#else
|
||||
#define LogVerbose(...)
|
||||
#define LogDebug(...)
|
||||
#define LogInfo(...)
|
||||
#define LogWarning(...)
|
||||
#define LogError(...)
|
||||
#define LogTrace(...)
|
||||
#endif
|
||||
#if 1 // For OpenHarmony log, should delete finally.// TODO:
|
||||
#define LOGD(...)
|
||||
#define LOGI(...)
|
||||
|
|
|
@ -19,7 +19,7 @@ static int LogPrintf(ILog *object, const char *function, const int line, const e
|
|||
// LogTypeToString(type);
|
||||
constexpr int SEND_TRACE_BUFF_SIZE = 2048;
|
||||
char buff[SEND_TRACE_BUFF_SIZE] = {0};
|
||||
snprintf(buff, SEND_TRACE_BUFF_SIZE, "[%s][line:%d]:", function, line);
|
||||
snprintf(buff, SEND_TRACE_BUFF_SIZE, "[%s:%d]:", function, line);
|
||||
// ILog::GetInstance()->Log(buff);
|
||||
const int headLen = strlen(buff);
|
||||
va_list vargs;
|
||||
|
|
|
@ -40,4 +40,5 @@ add_custom_command(
|
|||
COMMAND make StatusCode_code_check
|
||||
WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
define_file_name(${TARGET_NAME})
|
Loading…
Reference in New Issue
Block a user