@@ -10,40 +10,10 @@ cmake_minimum_required(VERSION 3.20)
10
10
project (Lithium VERSION 1.0.0 LANGUAGES C CXX )
11
11
12
12
# Set project options
13
- option (ENABLE_ASYNC "Enable Async Server Mode" ON )
14
- option (ENABLE_NATIVE_SERVER "Enable to use INDI native server" OFF )
15
- option (ENABLE_DEBUG "Enable Debug Mode" OFF )
16
- option (ENABLE_FASHHASH "Enable Using emhash8 as fast hash map" OFF )
17
- option (ENABLE_WEB_SERVER "Enable Web Server" ON )
18
- option (ENABLE_WEB_CLIENT "Enable Web Client" ON )
19
-
20
- # Set compile definitions based on options
21
- if (ENABLE_ASYNC )
22
- add_compile_definitions (ENABLE_ASYNC_FLAG=1 )
23
- endif ()
24
- if (ENABLE_DEBUG )
25
- add_compile_definitions (ENABLE_DEBUG_FLAG=1 )
26
- endif ()
27
- if (ENABLE_NATIVE_SERVER )
28
- add_compile_definitions (ENABLE_NATIVE_SERVER_FLAG=1 )
29
- endif ()
30
- if (ENABLE_FASHHASH )
31
- add_compile_definitions (ENABLE_FASHHASH_FLAG=1 )
32
- endif ()
33
- if (ENABLE_WEB_SERVER )
34
- add_compile_definitions (ENABLE_WEB_SERVER_FLAG=1 )
35
- endif ()
36
- if (ENABLE_WEB_CLIENT )
37
- add_compile_definitions (ENABLE_WEB_CLIENT_FLAG=1 )
38
- endif ()
13
+ include (cmake/options.cmake )
39
14
40
15
# Set policies
41
- if (POLICY CMP0003 )
42
- cmake_policy (SET CMP0003 NEW )
43
- endif ()
44
- if (POLICY CMP0043 )
45
- cmake_policy (SET CMP0043 NEW )
46
- endif ()
16
+ include (cmake/policies.cmake )
47
17
48
18
# Set project directories
49
19
set (Lithium_PROJECT_ROOT_DIR ${CMAKE_SOURCE_DIR} )
@@ -55,15 +25,15 @@ set(lithium_task_dir ${lithium_src_dir}/task)
55
25
56
26
add_custom_target (CmakeAdditionalFiles
57
27
SOURCES
58
- ${lithium_src_dir} /../cmake_modules /compiler_options.cmake )
59
- LIST (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake_modules /" )
60
- LIST (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /../cmake_modules /" )
61
- include (cmake_modules /compiler_options.cmake )
28
+ ${lithium_src_dir} /../cmake /compiler_options.cmake )
29
+ LIST (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake /" )
30
+ LIST (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /../cmake /" )
31
+ include (cmake /compiler_options.cmake )
62
32
63
33
# ------------------ CPM Begin ------------------
64
34
65
35
set (CPM_DOWNLOAD_VERSION 0.35.6 )
66
- set (CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR} /cmake_modules /CPM.cmake" )
36
+ set (CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR} /cmake /CPM.cmake" )
67
37
68
38
if (NOT (EXISTS ${CPM_DOWNLOAD_LOCATION} ))
69
39
message (STATUS "Downloading CPM.cmake" )
@@ -137,131 +107,10 @@ include_directories(${CMAKE_SOURCE_DIR}/libs/oatpp-websocket/oatpp-websocket)
137
107
include_directories (${CMAKE_SOURCE_DIR} /libs/oatpp-openssl/oatpp-openssl )
138
108
139
109
# Find packages
140
- find_package (OpenSSL REQUIRED )
141
- find_package (ZLIB REQUIRED )
142
- find_package (SQLite3 REQUIRED )
143
- find_package (fmt REQUIRED )
144
- find_package (Readline REQUIRED )
145
-
146
- find_package (Python COMPONENTS Interpreter REQUIRED )
147
-
148
- # Specify the path to requirements.txt
149
- set (REQUIREMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR} /requirements.txt" )
150
-
151
- # Define a function to check if a Python package is installed
152
- function (check_python_package package version )
153
- # Replace hyphens with underscores for the import statement
154
- string (REPLACE "-" "_" import_name ${package} )
155
-
156
- # Check if the package can be imported
157
- execute_process (
158
- COMMAND ${Python_EXECUTABLE} -c "import ${import_name} "
159
- RESULT_VARIABLE result
160
- )
161
-
162
- if (NOT result EQUAL 0 )
163
- set (result FALSE PARENT_SCOPE )
164
- return ()
165
- endif ()
166
-
167
- # Get the installed package version
168
- execute_process (
169
- COMMAND ${Python_EXECUTABLE} -m pip show ${package}
170
- OUTPUT_VARIABLE package_info
171
- )
172
-
173
- # Extract version information from the output
174
- string (FIND "${package_info} " "Version:" version_pos )
175
-
176
- if (version_pos EQUAL -1 )
177
- set (result FALSE PARENT_SCOPE )
178
- return () # Return false if version not found
179
- endif ()
180
-
181
- # Extract the version string
182
- string (SUBSTRING "${package_info} " ${version_pos} 1000 version_string )
183
- string (REGEX REPLACE "Version: ([^ ]+).*" "\\ 1" installed_version "${version_string} " )
184
-
185
- # Compare versions
186
- if ("${installed_version} " VERSION_LESS "${version} " )
187
- set (result FALSE PARENT_SCOPE ) # Return false if installed version is less than required
188
- return ()
189
- endif ()
190
-
191
- set (result TRUE PARENT_SCOPE )
192
- endfunction ()
193
-
194
- if (EXISTS "${CMAKE_BINARY_DIR} /check_marker.txt" )
195
- message (STATUS "Check marker file found, skipping the checks." )
196
- else ()
197
- # Create a virtual environment
198
- set (VENV_DIR "${CMAKE_BINARY_DIR} /venv" )
199
- execute_process (
200
- COMMAND ${Python_EXECUTABLE} -m venv ${VENV_DIR}
201
- )
202
-
203
- set (PYTHON_EXECUTABLE "${VENV_DIR} /bin/python" )
204
- set (PIP_EXECUTABLE "${VENV_DIR} /bin/pip" )
205
-
206
- # Upgrade pip in the virtual environment
207
- execute_process (
208
- COMMAND ${PIP_EXECUTABLE} install --upgrade pip
209
- )
210
-
211
- # Read the requirements.txt file and install missing packages
212
- file (READ ${REQUIREMENTS_FILE} requirements_content )
213
-
214
- # Split the requirements file content into lines
215
- string (REPLACE "\n " ";" requirements_list "${requirements_content} " )
110
+ include (cmake/find_packages.cmake )
216
111
217
- # Check and install each package
218
- foreach (requirement ${requirements_list} )
219
- # Skip empty lines
220
- string (STRIP ${requirement} trimmed_requirement )
221
- if (trimmed_requirement STREQUAL "" )
222
- continue ()
223
- endif ()
224
-
225
- # Get the package name and version (without the version number)
226
- if (${trimmed_requirement} MATCHES "==" )
227
- string (REPLACE "==" ";" parts ${trimmed_requirement} )
228
- elseif (${trimmed_requirement} MATCHES ">=" )
229
- string (REPLACE ">=" ";" parts ${trimmed_requirement} )
230
- else ()
231
- message (WARNING "Could not parse requirement '${trimmed_requirement} '. Skipping..." )
232
- continue ()
233
- endif ()
234
-
235
- list (GET parts 0 package_name )
236
- list (GET parts 1 package_version )
237
-
238
- # If the package name or version could not be parsed, output a warning and skip
239
- if (NOT package_name OR NOT package_version )
240
- message (WARNING "Could not parse requirement '${trimmed_requirement} '. Skipping..." )
241
- continue ()
242
- endif ()
243
-
244
- # Check if the package is installed
245
- message (STATUS "Checking if Python package '${package_name} ' is installed..." )
246
- check_python_package (${package_name} ${package_version} )
247
- if (NOT result )
248
- message (STATUS "Package '${package_name} ' is not installed or needs an upgrade. Installing..." )
249
- execute_process (
250
- COMMAND ${PIP_EXECUTABLE} install ${trimmed_requirement}
251
- RESULT_VARIABLE install_result
252
- )
253
- if (NOT install_result EQUAL 0 )
254
- message (FATAL_ERROR "Failed to install Python package '${package_name} '." )
255
- endif ()
256
- else ()
257
- message (STATUS "Package '${package_name} ' is already installed with a suitable version." )
258
- endif ()
259
- endforeach ()
260
- execute_process (
261
- COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_BINARY_DIR} /check_marker.txt"
262
- RESULT_VARIABLE result
263
- )
264
- endif ()
112
+ # Configure Python environment
113
+ include (cmake/python_environment.cmake )
265
114
266
115
# Configure config.h
267
116
configure_file (${lithium_src_dir} /config.h.in ${CMAKE_CURRENT_BINARY_DIR} /config.h )
@@ -271,13 +120,16 @@ set(BUILD_SHARED_LIBS ON)
271
120
# Add subdirectories
272
121
add_subdirectory (libs )
273
122
add_subdirectory (modules )
123
+
274
124
add_subdirectory (${lithium_module_dir} )
125
+
275
126
add_subdirectory (${lithium_src_dir} /config )
276
127
add_subdirectory (${lithium_src_dir} /task )
277
128
add_subdirectory (${lithium_src_dir} /server )
278
129
add_subdirectory (${lithium_src_dir} /utils )
279
130
add_subdirectory (${lithium_src_dir} /addon )
280
131
add_subdirectory (${lithium_src_dir} /client )
132
+ add_subdirectory (${lithium_src_dir} /target )
281
133
add_subdirectory (${lithium_src_dir} /device )
282
134
add_subdirectory (tests )
283
135
@@ -308,12 +160,13 @@ set(debug_module
308
160
309
161
set (device_module
310
162
${lithium_src_dir} /device/manager.cpp
311
-
312
163
${lithium_src_dir} /device/template/device.cpp
313
164
)
314
165
315
166
set (script_module
316
167
${lithium_src_dir} /script/manager.cpp
168
+ ${lithium_src_dir} /script/pycaller.cpp
169
+ ${lithium_src_dir} /script/pycaller.hpp
317
170
${lithium_src_dir} /script/sheller.cpp
318
171
)
319
172
@@ -364,6 +217,7 @@ target_link_libraries(lithium_server
364
217
tinyxml2
365
218
pocketpy
366
219
${Readline_LIBRARIES}
220
+ pybind11::embed
367
221
)
368
222
369
223
if (WIN32 )
@@ -395,17 +249,7 @@ target_compile_definitions(lithium_server PRIVATE LOGURU_DEBUG_LOGGING)
395
249
set_target_properties (lithium_server PROPERTIES OUTPUT_NAME lithium_server )
396
250
397
251
# Set install paths
398
- if (UNIX AND NOT APPLE )
399
- if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
400
- set (CMAKE_INSTALL_PREFIX /usr CACHE PATH "Lithium install path" FORCE )
401
- endif ()
402
- endif ()
403
-
404
- if (WIN32 )
405
- set (CMAKE_INSTALL_PREFIX "C:/Program Files/LithiumServer" )
406
- elseif (LINUX )
407
- set (CMAKE_INSTALL_PREFIX "/usr/lithium" )
408
- endif ()
252
+ include (cmake/install_paths.cmake )
409
253
410
254
# Enable folder grouping in IDEs
411
255
set_property (GLOBAL PROPERTY USE_FOLDERS ON )
0 commit comments