Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24m11a #43

Merged
merged 17 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5430382
添加新的测试文件和更新推荐引擎类以支持隐式反馈和评估功能
AstroAir Nov 2, 2024
2a9a892
添加网络管理器和进程信息结构,更新字符串处理函数,增强配置管理功能
AstroAir Nov 3, 2024
6ae3365
更新头文件引用,修复类成员类型,添加新的 TCP 代理功能,优化组件管理器
AstroAir Nov 4, 2024
c82e365
重构命名空间,优化代码结构,添加 SHA1 算法实现,更新 CMake 配置以支持 Python 模块
AstroAir Nov 6, 2024
f6238e6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 6, 2024
09efb50
Fix code scanning alert no. 242: Clear-text logging of sensitive info…
AstroAir Nov 6, 2024
bff073e
添加 MimeTypes 类以支持 MIME 类型处理,重构 LCG 类以内联最小和最大值函数,优化 XML 头文件包含,更新插件管理器中…
AstroAir Nov 6, 2024
cecaaad
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2024
c961407
重构代码结构,优化依赖管理,新增 Preloader 类及其功能,添加 Python 支持,更新存储监控类,增强 JSON 处理能力
AstroAir Nov 7, 2024
eab1e33
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2024
4d09888
新增多个模块的 CMakeLists.txt 文件,重命名项目以统一命名规范,添加 atom.async、atom.algorithm、a…
AstroAir Nov 8, 2024
7873e97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 8, 2024
fcf1577
新增 CMake 配置文件以支持多个依赖项,重构模块扫描功能,更新安装路径设置,删除过时的 CMake 模块
AstroAir Nov 9, 2024
ebd9ec5
Merge branch 'dev' of https://github.com/ElementAstro/Lithium into dev
AstroAir Nov 9, 2024
13c671f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2024
a49a6ef
新增 GPIO 类,添加任务等待功能,重命名波特率枚举,更新相机和配置管理器接口,优化打印格式,增加 INDI 服务器中间件功能
AstroAir Nov 9, 2024
7df7c23
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
190 changes: 17 additions & 173 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,10 @@ cmake_minimum_required(VERSION 3.20)
project(Lithium VERSION 1.0.0 LANGUAGES C CXX)

# Set project options
option(ENABLE_ASYNC "Enable Async Server Mode" ON)
option(ENABLE_NATIVE_SERVER "Enable to use INDI native server" OFF)
option(ENABLE_DEBUG "Enable Debug Mode" OFF)
option(ENABLE_FASHHASH "Enable Using emhash8 as fast hash map" OFF)
option(ENABLE_WEB_SERVER "Enable Web Server" ON)
option(ENABLE_WEB_CLIENT "Enable Web Client" ON)

# Set compile definitions based on options
if(ENABLE_ASYNC)
add_compile_definitions(ENABLE_ASYNC_FLAG=1)
endif()
if(ENABLE_DEBUG)
add_compile_definitions(ENABLE_DEBUG_FLAG=1)
endif()
if(ENABLE_NATIVE_SERVER)
add_compile_definitions(ENABLE_NATIVE_SERVER_FLAG=1)
endif()
if(ENABLE_FASHHASH)
add_compile_definitions(ENABLE_FASHHASH_FLAG=1)
endif()
if(ENABLE_WEB_SERVER)
add_compile_definitions(ENABLE_WEB_SERVER_FLAG=1)
endif()
if(ENABLE_WEB_CLIENT)
add_compile_definitions(ENABLE_WEB_CLIENT_FLAG=1)
endif()
include(cmake/options.cmake)

# Set policies
if(POLICY CMP0003)
cmake_policy(SET CMP0003 NEW)
endif()
if(POLICY CMP0043)
cmake_policy(SET CMP0043 NEW)
endif()
include(cmake/policies.cmake)

# Set project directories
set(Lithium_PROJECT_ROOT_DIR ${CMAKE_SOURCE_DIR})
Expand All @@ -55,15 +25,15 @@ set(lithium_task_dir ${lithium_src_dir}/task)

add_custom_target(CmakeAdditionalFiles
SOURCES
${lithium_src_dir}/../cmake_modules/compiler_options.cmake)
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules/")
include(cmake_modules/compiler_options.cmake)
${lithium_src_dir}/../cmake/compiler_options.cmake)
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/")
include(cmake/compiler_options.cmake)

# ------------------ CPM Begin ------------------

set(CPM_DOWNLOAD_VERSION 0.35.6)
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake_modules/CPM.cmake")
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM.cmake")

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake")
Expand Down Expand Up @@ -137,131 +107,10 @@ include_directories(${CMAKE_SOURCE_DIR}/libs/oatpp-websocket/oatpp-websocket)
include_directories(${CMAKE_SOURCE_DIR}/libs/oatpp-openssl/oatpp-openssl)

# Find packages
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
find_package(SQLite3 REQUIRED)
find_package(fmt REQUIRED)
find_package(Readline REQUIRED)

find_package(Python COMPONENTS Interpreter REQUIRED)

# Specify the path to requirements.txt
set(REQUIREMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt")

# Define a function to check if a Python package is installed
function(check_python_package package version)
# Replace hyphens with underscores for the import statement
string(REPLACE "-" "_" import_name ${package})

# Check if the package can be imported
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import ${import_name}"
RESULT_VARIABLE result
)

if(NOT result EQUAL 0)
set(result FALSE PARENT_SCOPE)
return()
endif()

# Get the installed package version
execute_process(
COMMAND ${Python_EXECUTABLE} -m pip show ${package}
OUTPUT_VARIABLE package_info
)

# Extract version information from the output
string(FIND "${package_info}" "Version:" version_pos)

if(version_pos EQUAL -1)
set(result FALSE PARENT_SCOPE)
return() # Return false if version not found
endif()

# Extract the version string
string(SUBSTRING "${package_info}" ${version_pos} 1000 version_string)
string(REGEX REPLACE "Version: ([^ ]+).*" "\\1" installed_version "${version_string}")

# Compare versions
if("${installed_version}" VERSION_LESS "${version}")
set(result FALSE PARENT_SCOPE) # Return false if installed version is less than required
return()
endif()

set(result TRUE PARENT_SCOPE)
endfunction()

if (EXISTS "${CMAKE_BINARY_DIR}/check_marker.txt")
message(STATUS "Check marker file found, skipping the checks.")
else()
# Create a virtual environment
set(VENV_DIR "${CMAKE_BINARY_DIR}/venv")
execute_process(
COMMAND ${Python_EXECUTABLE} -m venv ${VENV_DIR}
)

set(PYTHON_EXECUTABLE "${VENV_DIR}/bin/python")
set(PIP_EXECUTABLE "${VENV_DIR}/bin/pip")

# Upgrade pip in the virtual environment
execute_process(
COMMAND ${PIP_EXECUTABLE} install --upgrade pip
)

# Read the requirements.txt file and install missing packages
file(READ ${REQUIREMENTS_FILE} requirements_content)

# Split the requirements file content into lines
string(REPLACE "\n" ";" requirements_list "${requirements_content}")
include(cmake/find_packages.cmake)

# Check and install each package
foreach(requirement ${requirements_list})
# Skip empty lines
string(STRIP ${requirement} trimmed_requirement)
if(trimmed_requirement STREQUAL "")
continue()
endif()

# Get the package name and version (without the version number)
if(${trimmed_requirement} MATCHES "==")
string(REPLACE "==" ";" parts ${trimmed_requirement})
elseif(${trimmed_requirement} MATCHES ">=")
string(REPLACE ">=" ";" parts ${trimmed_requirement})
else()
message(WARNING "Could not parse requirement '${trimmed_requirement}'. Skipping...")
continue()
endif()

list(GET parts 0 package_name)
list(GET parts 1 package_version)

# If the package name or version could not be parsed, output a warning and skip
if(NOT package_name OR NOT package_version)
message(WARNING "Could not parse requirement '${trimmed_requirement}'. Skipping...")
continue()
endif()

# Check if the package is installed
message(STATUS "Checking if Python package '${package_name}' is installed...")
check_python_package(${package_name} ${package_version})
if(NOT result)
message(STATUS "Package '${package_name}' is not installed or needs an upgrade. Installing...")
execute_process(
COMMAND ${PIP_EXECUTABLE} install ${trimmed_requirement}
RESULT_VARIABLE install_result
)
if(NOT install_result EQUAL 0)
message(FATAL_ERROR "Failed to install Python package '${package_name}'.")
endif()
else()
message(STATUS "Package '${package_name}' is already installed with a suitable version.")
endif()
endforeach()
execute_process(
COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_BINARY_DIR}/check_marker.txt"
RESULT_VARIABLE result
)
endif()
# Configure Python environment
include(cmake/python_environment.cmake)

# Configure config.h
configure_file(${lithium_src_dir}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
Expand All @@ -271,13 +120,16 @@ set(BUILD_SHARED_LIBS ON)
# Add subdirectories
add_subdirectory(libs)
add_subdirectory(modules)

add_subdirectory(${lithium_module_dir})

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(tests)

Expand Down Expand Up @@ -308,12 +160,13 @@ set(debug_module

set(device_module
${lithium_src_dir}/device/manager.cpp

${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
)

Expand Down Expand Up @@ -364,6 +217,7 @@ target_link_libraries(lithium_server
tinyxml2
pocketpy
${Readline_LIBRARIES}
pybind11::embed
)

if(WIN32)
Expand Down Expand Up @@ -395,17 +249,7 @@ target_compile_definitions(lithium_server PRIVATE LOGURU_DEBUG_LOGGING)
set_target_properties(lithium_server PROPERTIES OUTPUT_NAME lithium_server)

# Set install paths
if(UNIX AND NOT APPLE)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr CACHE PATH "Lithium install path" FORCE)
endif()
endif()

if(WIN32)
set(CMAKE_INSTALL_PREFIX "C:/Program Files/LithiumServer")
elseif(LINUX)
set(CMAKE_INSTALL_PREFIX "/usr/lithium")
endif()
include(cmake/install_paths.cmake)

# Enable folder grouping in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ Alternatively, utilize the provided quick-build scripts to streamline the proces
### Intellectual Inspiration

Embarking on the journey with Lithium, we embrace curiosity and an unwavering pursuit of knowledge, echoing the adapted verse which reminds us that every attempt, though fraught with challenges and setbacks, is a necessary step toward wisdom and understanding. Together, let us navigate the vast cosmos of astronomical imaging, our technology the vessel, innovation our sail, advancing relentlessly forward.

<figure><embed src="https://wakatime.com/share/@018d39f0-57c9-4a13-aedb-90454b61e6cc/e1b2b694-2ecc-4cfd-9c75-2d01b8581e4d.svg"></embed></figure>
<figure><embed src="https://wakatime.com/share/@018d39f0-57c9-4a13-aedb-90454b61e6cc/d6c29fb7-c5b3-4ffc-8e17-16634c7b669a.svg"></embed></figure>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions cmake/FindGlib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# - Try to find Glib-2.0 (with gobject)
# Once done, this will define
#
# Glib_FOUND - system has Glib
# Glib_INCLUDE_DIRS - the Glib include directories
# Glib_LIBRARIES - link these to use Glib

include(LibFindMacros)

# Use pkg-config to get hints about paths
libfind_pkg_check_modules(Glib_PKGCONF glib-2.0>=2.16)

# Main include dir
find_path(Glib_INCLUDE_DIR
NAMES glib.h
PATHS ${Glib_PKGCONF_INCLUDE_DIRS}
PATH_SUFFIXES glib-2.0
)

# Glib-related libraries also use a separate config header, which is in lib dir
find_path(GlibConfig_INCLUDE_DIR
NAMES glibconfig.h
PATHS ${Glib_PKGCONF_INCLUDE_DIRS} /usr
PATH_SUFFIXES lib/glib-2.0/include
)

# Finally the library itself
find_library(Glib_LIBRARY
NAMES glib-2.0
PATHS ${Glib_PKGCONF_LIBRARY_DIRS}
)

# Find gobject library
find_library(GObject_LIBRARY
NAMES gobject-2.0
PATHS ${Glib_PKGCONF_LIBRARY_DIRS}
)

# Find gthread library
find_library(GThread_LIBRARY
NAMES gthread-2.0
PATHS ${Glib_PKGCONF_LIBRARY_DIRS}
)

# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
set(Glib_PROCESS_INCLUDES Glib_INCLUDE_DIR GlibConfig_INCLUDE_DIR)
set(Glib_PROCESS_LIBS Glib_LIBRARY GObject_LIBRARY GThread_LIBRARY)
libfind_process(Glib)

# Redefine variables for backward compatibility
set(GLIB_INCLUDE_DIRS ${Glib_INCLUDE_DIRS})
set(GLIB_LIBRARIES ${Glib_LIBRARIES})
set(GLIB_FOUND ${Glib_FOUND})

# Provide a summary of the found libraries
if(Glib_FOUND)
message(STATUS "Found Glib: ${Glib_LIBRARIES}")
message(STATUS "Glib include directories: ${Glib_INCLUDE_DIRS}")
else()
message(WARNING "Glib not found")
endif()
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions cmake/FindLibSecret.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# - Try to find LIBSECRET-1
# Once done, this will define
#
# LIBSECRET_FOUND - system has LIBSECRET
# LIBSECRET_INCLUDE_DIRS - the LIBSECRET include directories
# LIBSECRET_LIBRARIES - link these to use LIBSECRET

include(LibFindMacros)

# Use pkg-config to get hints about paths
libfind_pkg_check_modules(LIBSECRET_PKGCONF LIBSECRET-1)

# Main include dir
find_path(LIBSECRET_INCLUDE_DIR
NAMES LIBSECRET/secret.h
PATHS ${LIBSECRET_PKGCONF_INCLUDE_DIRS}
)

# Finally the library itself
find_library(LIBSECRET_LIBRARY
NAMES secret-1
PATHS ${LIBSECRET_PKGCONF_LIBRARY_DIRS}
)

# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
set(LIBSECRET_PROCESS_INCLUDES LIBSECRET_INCLUDE_DIR)
set(LIBSECRET_PROCESS_LIBS LIBSECRET_LIBRARY)
libfind_process(LIBSECRET)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading