Skip to content

Commit

Permalink
Merge pull request #80 from liufang-robot/master
Browse files Browse the repository at this point in the history
refactor: 优化代码格式和构建
  • Loading branch information
liufang-robot authored Jun 16, 2024
2 parents 525a441 + e71a194 commit 475b586
Show file tree
Hide file tree
Showing 857 changed files with 11,522 additions and 14,367 deletions.
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
Language: Cpp
BasedOnStyle: Google
SortIncludes: false

48 changes: 29 additions & 19 deletions .github/workflows/linux_cpp_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,8 @@ on:
workflow_dispatch:
pull_request:
jobs:
linux_cpp_build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: install components
run: sudo apt-get install -y build-essential doxygen graphviz python3-pip python3-dev

- name: install dependencies
run: pip3 install -r requirements.txt

- name: configure
run: cmake -S. -Bbuild -DBUILD_DEB=ON

- name: build
run: cmake --build build

linux_cpp_test:
needs: linux_cpp_build
# needs: linux_cpp_build
runs-on: ubuntu-latest
container: registry.cn-shanghai.aliyuncs.com/lebai/l-master:3.1.6
steps:
Expand Down Expand Up @@ -52,3 +34,31 @@ jobs:

- name: test
run: cmake --build build --target test

linux_cpp_build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: install components
run: sudo apt-get install -y build-essential doxygen graphviz python3-pip python3-dev

- name: install dependencies
run: |
pip3 install -r requirements.txt
pip3 install clang-format
- name: configure
run: cmake -S. -Bbuild -DBUILD_DEB=ON -DCLANG_FORMAT_CHECK=ON

- name: build
run: |
cmake --build build
cd build && cpack && cd ..
# - name: Upload deb
# uses: actions/upload-artifact@v4
# id: artifact
# with:
# name: lebai-deb-package
# path: build/*.deb
11 changes: 8 additions & 3 deletions .github/workflows/linux_cpp_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ jobs:
run: cpack --config ./build/CPackConfig.cmake

- name: upload .deb
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: DebForCPP
path: ./*.deb
name: lebai-deb-package
path: *.deb
- name: release
uses: ncipollo/release-action@v1
with:
artifacts: *.deb
allowUpdates: true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ out
.vscode
.vs
sdk/include/lebai/config.hh
CMakeSettings.json
CMakeSettings.json
.cache
184 changes: 112 additions & 72 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
cmake_minimum_required(VERSION 3.18)
if (POLICY CMP0122)
cmake_minimum_required(VERSION 3.15)
if(POLICY CMP0122)
cmake_policy(SET CMP0122 NEW)
endif()
if (POLICY CMP0135)
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()

project(lebai VERSION 1.1.24 LANGUAGES CXX)
project(
lebai
VERSION 1.1.25
LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile command" TRUE)

set(PROJECT_NAMESPACE lebai)
message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}")
# message(STATUS "major: ${PROJECT_VERSION_MAJOR}")
# message(STATUS "minor: ${PROJECT_VERSION_MINOR}")
# message(STATUS "patch: ${PROJECT_VERSION_PATCH}")


get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(isMultiConfig)
if(NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING
"Choose the type of builds, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release;Debug)"
FORCE)
set(CMAKE_CONFIGURATION_TYPES
"Release;Debug"
CACHE
STRING
"Choose the type of builds, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release;Debug)"
FORCE)
endif()
message(STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
else()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release)"
FORCE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE
STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release)"
FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
endif()
Expand All @@ -41,37 +45,48 @@ include(GNUInstallDirs)
if(UNIX)
option(BUILD_SHARED_LIBS "Build shared libraries (.so or .dyld)." ON)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
# for multi-config build system (e.g. Xcode, Ninja Multi-Config)
foreach(OutputConfig IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${OutputConfig} OUTPUTCONFIG)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
endforeach()
else()
# Currently Only support static build for windows
option(BUILD_SHARED_LIBS "Build shared libraries (.dll)." OFF)
add_compile_definitions(_USE_MATH_DEFINES)
add_compile_definitions(_WEBSOCKETPP_CPP11_RANDOM_DEVICE_)
# add_compile_definitions(NOMINMAX)
# add_compile_definitions(_DEBUG)
# add_compile_definitions(NOMINMAX) add_compile_definitions(_DEBUG)
if(WIN32)
add_definitions(-D_WIN32_WINNT=0x0601)
endif()
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
# for multi-config builds (e.g. msvc)
foreach(OutputConfig IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${OutputConfig} OUTPUTCONFIG)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
endforeach()
endif()

Expand Down Expand Up @@ -101,44 +116,46 @@ message(STATUS "Build Java: ${BUILD_JAVA}")
if(BUILD_PYTHON AND BUILD_PYTHON2)
message(FATAL_ERROR "Can only build one of python2 and python3.")
endif()
#if(UNIX)
if(BUILD_PYTHON)
option(FETCH_PYTHON_DEPS "Install python required modules if not available" ON)
message(STATUS "Python fetch dependencies: ${FETCH_PYTHON_DEPS}")
if(DEFINED PYTHONPATH)
message(STATUS "Python path: ${PYTHONPATH}")
set(Python3_ROOT_DIR ${PYTHONPATH})
endif()
include(python)
endif()

if(BUILD_PYTHON2)
if(DEFINED PYTHONPATH)
message(STATUS "Python path: ${PYTHON2PATH}")
set(Python2_ROOT_DIR ${PYTHONPATH})
endif()
include(python2)
endif()
#endif()
# Disable CTest targets
# if(UNIX)
if(BUILD_PYTHON)
option(FETCH_PYTHON_DEPS "Install python required modules if not available"
ON)
message(STATUS "Python fetch dependencies: ${FETCH_PYTHON_DEPS}")
if(DEFINED PYTHONPATH)
message(STATUS "Python path: ${PYTHONPATH}")
set(Python3_ROOT_DIR ${PYTHONPATH})
endif()
include(python)
endif()

if(BUILD_PYTHON2)
if(DEFINED PYTHONPATH)
message(STATUS "Python path: ${PYTHON2PATH}")
set(Python2_ROOT_DIR ${PYTHONPATH})
endif()
include(python2)
endif()
# endif() Disable CTest targets
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
include(CTest)
include(cpp)

if(WIN32 AND (BUILD_DOTNET OR BUILD_JAVA OR BUILD_PYTHON))
if(WIN32
AND (BUILD_DOTNET
OR BUILD_JAVA
OR BUILD_PYTHON))
message(STATUS "Getting SWIG: ...")
#add_definitions(-DSWIG_PYTHON_INTERPRETER_NO_DEBUG)
# add_definitions(-DSWIG_PYTHON_INTERPRETER_NO_DEBUG)
include(swig)
message(STATUS "Getting SWIG: ...DONE")
endif()


if(BUILD_PYTHON)
option(FETCH_PYTHON_DEPS "Install python required modules if not available" ON)
option(FETCH_PYTHON_DEPS "Install python required modules if not available"
ON)
message(STATUS "Python fetch dependencies: ${FETCH_PYTHON_DEPS}")
endif()


if(BUILD_DOTNET)
# .Net Core 3.1 LTS is not available for osx arm64
if(APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)")
Expand All @@ -159,36 +176,59 @@ if(BUILD_JAVA)
endif()
include(java)


# add_subdirectory(tests)

option(BUILD_EXAMPLES "Build examples" ON)
message(STATUS "Build examples: ${BUILD_EXAMPLES}")
add_subdirectory(examples)

set(SDK_DIR "${CMAKE_SOURCE_DIR}/sdk")
# Get all .cc, .c, .cpp, .h, .hh, .hpp files in the SDK directory
file(
GLOB_RECURSE
SDK_CXX_FILES
"${SDK_DIR}/*.cc"
"${SDK_DIR}/*.c"
"${SDK_DIR}/*.cpp"
"${SDK_DIR}/*.h"
"${SDK_DIR}/*.hh"
"${SDK_DIR}/*.hpp")
option(CLANG_FORMAT_CHECK "Run clang-format in check mode" OFF)
message(STATUS "Clang format check: ${CLANG_FORMAT_CHECK}")

list(FILTER SDK_CXX_FILES EXCLUDE REGEX "${SDK_DIR}/include/lebai/config.hh")

# Create the clang-format target
if(CLANG_FORMAT_CHECK)
message(STATUS "Add custom target clang-format")
add_custom_target(clang-format ALL COMMAND clang-format -style=file --Werror
--dry-run ${SDK_CXX_FILES})
else()
add_custom_target(clang-format COMMAND clang-format -style=file -i ${SDK_CXX_FILES})
endif()

find_package(Doxygen)
option(BUILD_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ON)
option(BUILD_DOCUMENTATION
"Create and install the HTML based API documentation (requires Doxygen)"
ON)

if(BUILD_DOCUMENTATION AND DOXYGEN_FOUND)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()

set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile )
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile)
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

configure_file(${doxyfile_in} ${doxyfile} @ONLY)
configure_file(${doxyfile_in} ${doxyfile} @ONLY)

add_custom_target(doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
add_custom_target(
doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc/${PROJECT_NAME})
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
DESTINATION share/doc/${PROJECT_NAME})
endif()




4 changes: 2 additions & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "lebai sdk"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.1.24
PROJECT_NUMBER = 1.1.25

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down Expand Up @@ -885,7 +885,7 @@ EXCLUDE_PATTERNS = */cmake/* \
*/python/* \
*/sdk/python/* \
*/sdk/src/* \
*/sdk/third/* \
*/third/* \
*/sdk/test/* \
*/examples/*

Expand Down
Loading

0 comments on commit 475b586

Please sign in to comment.