Skip to content

Commit

Permalink
更新子项目引用,删除不再使用的依赖,优化头文件包含,重构 CMake 配置,改进代码结构和异常处理
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroAir committed Nov 23, 2024
1 parent 247a896 commit 4b9ceff
Show file tree
Hide file tree
Showing 55 changed files with 1,014 additions and 1,253 deletions.
45 changes: 4 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,53 +123,16 @@ add_subdirectory(modules)

add_subdirectory(${atom_module})

add_subdirectory(${lithium_src_dir}/config)
add_subdirectory(${lithium_src_dir}/task)
add_subdirectory(${lithium_src_dir}/server)
add_subdirectory(${lithium_src_dir}/utils)
add_subdirectory(${lithium_src_dir}/addon)
add_subdirectory(${lithium_src_dir}/client)
add_subdirectory(${lithium_src_dir}/target)
add_subdirectory(${lithium_src_dir}/device)
add_subdirectory(${lithium_src_dir}/script)
add_subdirectory(tests)

# Set source files
set(component_module
${lithium_component_dir}/addons.cpp
${lithium_component_dir}/compiler.cpp
${lithium_component_dir}/dependency.cpp
${lithium_component_dir}/loader.cpp
${lithium_component_dir}/manager.cpp
${lithium_component_dir}/sandbox.cpp
)

set(config_module
${lithium_src_dir}/config/configor.cpp
)
foreach(dir config task server utils addon client target device script debug tools)
add_subdirectory(${lithium_src_dir}/${dir})
endforeach()

set(debug_module
${lithium_src_dir}/debug/terminal.cpp
${lithium_src_dir}/debug/suggestion.cpp
${lithium_src_dir}/debug/command.cpp
${lithium_src_dir}/debug/console.cpp
${lithium_src_dir}/debug/history.cpp
${lithium_src_dir}/debug/progress.cpp
${lithium_src_dir}/debug/output_style.cpp
${lithium_src_dir}/debug/check.cpp
)
add_subdirectory(tests)

set(device_module
${lithium_src_dir}/device/template/device.cpp
)

set(script_module
${lithium_src_dir}/script/manager.cpp
${lithium_src_dir}/script/pycaller.cpp
${lithium_src_dir}/script/pycaller.hpp
${lithium_src_dir}/script/sheller.cpp
)

set(Lithium_module
${lithium_src_dir}/LithiumApp.cpp
${lithium_src_dir}/utils/constant.cpp
Expand Down
55 changes: 55 additions & 0 deletions cmake/FindLibGit2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# FindLibGit2.cmake
# This module looks for the libgit2 library and sets the following variables:
# LIBGIT2_FOUND - True if libgit2 was found
# LIBGIT2_INCLUDE_DIRS - Directories containing libgit2 headers
# LIBGIT2_LIBRARIES - Libraries to link against libgit2
# LIBGIT2_VERSION - Version of libgit2 found

# Use pkg-config if available (usually on Linux and macOS)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_LIBGIT2 libgit2)
endif()

# Try to find libgit2 using the CMake find_path/find_library functions
find_path(LIBGIT2_INCLUDE_DIR
NAMES git2.h
PATHS ${PC_LIBGIT2_INCLUDEDIR} ${PC_LIBGIT2_INCLUDE_DIRS} ENV INCLUDE
PATH_SUFFIXES libgit2
)

find_library(LIBGIT2_LIBRARY
NAMES git2
PATHS ${PC_LIBGIT2_LIBDIR} ${PC_LIBGIT2_LIBRARY_DIRS} ENV LIB
)

# Check if both the include path and library were found
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibGit2 REQUIRED_VARS LIBGIT2_LIBRARY LIBGIT2_INCLUDE_DIR
VERSION_VAR PC_LIBGIT2_VERSION)

# Set output variables
if(LIBGIT2_FOUND)
set(LIBGIT2_INCLUDE_DIRS ${LIBGIT2_INCLUDE_DIR})
set(LIBGIT2_LIBRARIES ${LIBGIT2_LIBRARY})

# Try to extract the version if not provided by pkg-config
if(NOT LIBGIT2_VERSION AND EXISTS "${LIBGIT2_INCLUDE_DIR}/git2/version.h")
file(READ "${LIBGIT2_INCLUDE_DIR}/git2/version.h" _version_header)
string(REGEX MATCHALL "#define[ \t]+LIBGIT2_VER_[A-Z]+[ \t]+([0-9]+)" _version_matches ${_version_header})
list(GET _version_matches 0 _major_match)
list(GET _version_matches 1 _minor_match)
list(GET _version_matches 2 _patch_match)
string(REGEX REPLACE ".*([0-9]+).*" "\\1" LIBGIT2_VERSION_MAJOR ${_major_match})
string(REGEX REPLACE ".*([0-9]+).*" "\\1" LIBGIT2_VERSION_MINOR ${_minor_match})
string(REGEX REPLACE ".*([0-9]+).*" "\\1" LIBGIT2_VERSION_PATCH ${_patch_match})
set(LIBGIT2_VERSION "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_PATCH}")
endif()

message(STATUS "Found libgit2: ${LIBGIT2_LIBRARY} (include: ${LIBGIT2_INCLUDE_DIR}, version: ${LIBGIT2_VERSION})")
else()
message(STATUS "Could not find libgit2")
endif()

# Provide variables for consumers of this module
mark_as_advanced(LIBGIT2_INCLUDE_DIR LIBGIT2_LIBRARY)
1 change: 0 additions & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[requires]
cfitsio/4.3.1
cpython/3.12.2
opencv/4.9.0
openssl/3.2.1
pybind11/2.12.0
tinyxml2/10.0.0
Expand Down
2 changes: 1 addition & 1 deletion libs
Submodule libs updated 40 files
+3 −0 CMakeLists.txt
+4 −14 pocketpy/include/pocketpy/common/vector.h
+1 −4 pocketpy/include/pocketpy/compiler/lexer.h
+2 −2 pocketpy/include/pocketpy/config.h
+1 −1 pocketpy/include/pocketpy/interpreter/generator.h
+2 −1 pocketpy/include/pocketpy/interpreter/modules.h
+5 −0 pocketpy/include/pocketpy/pocketpy.h
+3 −0 pocketpy/include/pocketpy/xmacros/magics.h
+3 −0 pocketpy/include/typings/array2d.pyi
+2 −0 pocketpy/include/typings/conio.pyi
+25 −1 pocketpy/include/typings/linalg.pyi
+0 −10 pocketpy/include/typings/line_profiler.pyi
+13 −0 pocketpy/include/typings/pkpy.pyi
+0 −4 pocketpy/include/typings/win32.pyi
+1 −0 pocketpy/python/typing.py
+1 −1 pocketpy/src/common/_generated.c
+3 −3 pocketpy/src/common/sstream.c
+7 −8 pocketpy/src/common/str.c
+3 −24 pocketpy/src/common/vector.c
+62 −40 pocketpy/src/compiler/compiler.c
+3 −97 pocketpy/src/compiler/lexer.c
+65 −14 pocketpy/src/interpreter/ceval.c
+5 −3 pocketpy/src/interpreter/dll.c
+6 −5 pocketpy/src/interpreter/generator.c
+8 −5 pocketpy/src/interpreter/vm.c
+16 −9 pocketpy/src/modules/array2d.c
+129 −0 pocketpy/src/modules/conio.c
+54 −31 pocketpy/src/modules/linalg.c
+69 −0 pocketpy/src/modules/pkpy.c
+19 −13 pocketpy/src/modules/time.c
+0 −47 pocketpy/src/modules/win32.c
+20 −12 pocketpy/src/public/internal.c
+14 −15 pocketpy/src/public/modules.c
+0 −3 pocketpy/src/public/py_array.c
+4 −3 pocketpy/src/public/py_list.c
+20 −19 pocketpy/src/public/py_number.c
+0 −1 pocketpy/src/public/py_object.c
+10 −10 pocketpy/src/public/py_ops.c
+8 −4 pocketpy/src/public/py_str.c
+11 −0 pocketpy/src/public/values.c
4 changes: 2 additions & 2 deletions modules/atom.algorithm/pymodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ PYBIND11_MODULE(algorithm, m) {
"Generate Huffman codes", py::arg("root"), py::arg("code"),
py::arg("huffman_codes"));

m.def("compress_text", &compressText, "Compress text", py::arg("text"),
m.def("compress_data", &compressData, "Compress text", py::arg("text"),
py::arg("huffman_codes"));

m.def("decompress_text", &decompressText, "Decompress text",
m.def("decompress_data", &decompressData, "Decompress text",
py::arg("compressed_text"), py::arg("root"));

m.def("mul_div64", &mulDiv64,
Expand Down
6 changes: 5 additions & 1 deletion modules/lithium.config/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Description: Config Component for Atom Addon

#include "config/configor.hpp"

#include "atom/function/overload.hpp"
#include "atom/log/loguru.hpp"
#include "atom/tests/test.hpp"
#include "atom/type/json.hpp"
Expand All @@ -27,7 +28,10 @@ ATOM_MODULE(lithium_config, [](Component& com) {
DLOG_F(INFO, "Loading module {}", com.getName());

com.def("getConfig", &lithium::ConfigManager::getValue, mConfigManager);
com.def("setConfig", &lithium::ConfigManager::setValue, mConfigManager);
com.def("setConfig",
atom::meta::overload_cast<const std::string&, const json&>(
&lithium::ConfigManager::setValue),
mConfigManager);
com.def("hasConfig", &lithium::ConfigManager::hasValue, mConfigManager);
com.def("deleteConfig", &lithium::ConfigManager::deleteValue,
mConfigManager);
Expand Down
34 changes: 8 additions & 26 deletions modules/lithium.cxxtools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
# CMakeLists.txt for lithium.cxxtools
# This project is licensed under the terms of the GPL3 license.
#
# Author: Max Qian
# License: GPL3

cmake_minimum_required(VERSION 3.20)
project(lithium.cxxtools)

set(CMAKE_LITHIUM_CXXTOOLS_VERSION_MAJOR 1)
set(CMAKE_LITHIUM_CXXTOOLS_VERSION_MINOR 0)
set(CMAKE_LITHIUM_CXXTOOLS_VERSION_RELEASE 0)

set(LITHIUM_CXXTOOLS_SOVERSION ${CMAKE_LITHIUM_CXXTOOLS_VERSION_MAJOR})
set(CMAKE_LITHIUM_CXXTOOLS_VERSION_STRING "${CMAKE_LITHIUM_CXXTOOLS_VERSION_MAJOR}.${CMAKE_LITHIUM_CXXTOOLS_VERSION_MINOR}.${CMAKE_LITHIUM_CXXTOOLS_VERSION_RELEASE}")
set(LITHIUM_CXXTOOLS_VERSION ${CMAKE_LITHIUM_CXXTOOLS_VERSION_MAJOR}.${CMAKE_LITHIUM_CXXTOOLS_VERSION_MINOR}.${CMAKE_LITHIUM_CXXTOOLS_VERSION_RELEASE})

# Set the C++ standard
set(CMAKE_CXX_STANDARD 20)
project(lithium.cxxtools VERSION 1.0.0)

# Add source files
set(SOURCE_FILES
Expand All @@ -26,12 +9,11 @@ set(SOURCE_FILES
src/json2xml.cpp
src/xml2json.cpp
src/pci_generator.cpp

_component.cpp
_main.cpp
component.cpp
)

set(${PROJECT_NAME}_LIBS
# Libraries to link
set(LIBS
atom-component
atom-utils
atom-error
Expand All @@ -41,10 +23,10 @@ set(${PROJECT_NAME}_LIBS
)

# Create the module library
add_library(lithium.cxxtools SHARED ${SOURCE_FILES})
target_link_libraries(lithium.cxxtools ${${PROJECT_NAME}_LIBS})
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${LIBS})

# Include directories
target_include_directories(lithium.cxxtools PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_subdirectory(tests)
add_subdirectory(tests)
53 changes: 0 additions & 53 deletions modules/lithium.cxxtools/_component.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions modules/lithium.cxxtools/_component.hpp

This file was deleted.

29 changes: 0 additions & 29 deletions modules/lithium.cxxtools/_main.cpp

This file was deleted.

56 changes: 56 additions & 0 deletions modules/lithium.cxxtools/component.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* _component.cpp
*
* Copyright (C) 2023-2024 Max Qian
*/

/*************************************************
Date: 2024-05-26
Description: Some useful tools written in c++
**************************************************/

#include "atom/components/component.hpp"
#include "atom/components/registry.hpp"

#include "atom/log/loguru.hpp"

#include "csv2json.hpp"
#include "ini2json.hpp"
#include "json2csv.hpp"
#include "json2ini.hpp"
#include "json2xml.hpp"
#include "json2yaml.hpp"
#include "pci_generator.hpp"
#include "xml2json.hpp"
#include "yaml2json.hpp"

using namespace lithium::cxxtools::detail;
using namespace lithium::cxxtools::converters;

ATOM_MODULE(lithium_image, [](Component& com) {
LOG_F(INFO, "Lithium Image Component Constructed");

com.def("csv2json", &Csv2Json::convert, "utils",
"Convert a CSV file to JSON format");
com.def("json2csv", &JsonToCsvConverter::convert, "utils",
"Convert a JSON file to CSV format");
com.def("ini2json", &Ini2Json::convert, "utils",
"Convert an INI file to JSON format");
com.def("json2ini", &JsonToIniConverter::convert, "utils",
"Convert a JSON file to INI format");
com.def("json2xml", &JsonToXmlConverter::convert, "utils",
"Convert a JSON file to XML format");
com.def("xml2json", &Xml2Json::convert, "utils",
"Convert an XML file to JSON format");
com.def("yaml2json", &Yaml2Json::convert, "utils",
"Convert a YAML file to JSON format");
com.def("json2yaml", &JsonToYamlConverter::convert, "utils",

"Convert a JSON file to YAML format");

com.def("generate_pci", &parseAndGeneratePCIInfo, "utils",
"Generate PCI device ID");
});
Loading

0 comments on commit 4b9ceff

Please sign in to comment.