@@ -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,133 +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
- find_package (pybind11 CONFIG REQUIRED)
110
+ include (cmake/find_packages.cmake)
146
111
147
- find_package (Python COMPONENTS Interpreter REQUIRED)
148
- include_directories (${pybind11_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} )
149
-
150
- # Specify the path to requirements.txt
151
- set (REQUIREMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR} /requirements.txt" )
152
-
153
- # Define a function to check if a Python package is installed
154
- function (check_python_package package version )
155
- # Replace hyphens with underscores for the import statement
156
- string (REPLACE "-" "_" import_name ${package} )
157
-
158
- # Check if the package can be imported
159
- execute_process (
160
- COMMAND ${Python_EXECUTABLE} -c "import ${import_name} "
161
- RESULT_VARIABLE result
162
- )
163
-
164
- if (NOT result EQUAL 0)
165
- set (result FALSE PARENT_SCOPE)
166
- return ()
167
- endif ()
168
-
169
- # Get the installed package version
170
- execute_process (
171
- COMMAND ${Python_EXECUTABLE} -m pip show ${package}
172
- OUTPUT_VARIABLE package_info
173
- )
174
-
175
- # Extract version information from the output
176
- string (FIND "${package_info} " "Version:" version_pos)
177
-
178
- if (version_pos EQUAL -1)
179
- set (result FALSE PARENT_SCOPE)
180
- return () # Return false if version not found
181
- endif ()
182
-
183
- # Extract the version string
184
- string (SUBSTRING "${package_info} " ${version_pos} 1000 version_string)
185
- string (REGEX REPLACE "Version: ([^ ]+).*" "\\ 1" installed_version "${version_string} " )
186
-
187
- # Compare versions
188
- if ("${installed_version} " VERSION_LESS "${version} " )
189
- set (result FALSE PARENT_SCOPE) # Return false if installed version is less than required
190
- return ()
191
- endif ()
192
-
193
- set (result TRUE PARENT_SCOPE)
194
- endfunction ()
195
-
196
- if (EXISTS "${CMAKE_BINARY_DIR} /check_marker.txt" )
197
- message (STATUS "Check marker file found, skipping the checks." )
198
- else ()
199
- # Create a virtual environment
200
- set (VENV_DIR "${CMAKE_BINARY_DIR} /venv" )
201
- execute_process (
202
- COMMAND ${Python_EXECUTABLE} -m venv ${VENV_DIR}
203
- )
204
-
205
- set (PYTHON_EXECUTABLE "${VENV_DIR} /bin/python" )
206
- set (PIP_EXECUTABLE "${VENV_DIR} /bin/pip" )
207
-
208
- # Upgrade pip in the virtual environment
209
- execute_process (
210
- COMMAND ${PIP_EXECUTABLE} install --upgrade pip
211
- )
212
-
213
- # Read the requirements.txt file and install missing packages
214
- file (READ ${REQUIREMENTS_FILE} requirements_content)
215
-
216
- # Split the requirements file content into lines
217
- string (REPLACE "\n " ";" requirements_list "${requirements_content} " )
218
-
219
- # Check and install each package
220
- foreach (requirement ${requirements_list} )
221
- # Skip empty lines
222
- string (STRIP ${requirement} trimmed_requirement)
223
- if (trimmed_requirement STREQUAL "" )
224
- continue ()
225
- endif ()
226
-
227
- # Get the package name and version (without the version number)
228
- if (${trimmed_requirement} MATCHES "==" )
229
- string (REPLACE "==" ";" parts ${trimmed_requirement} )
230
- elseif (${trimmed_requirement} MATCHES ">=" )
231
- string (REPLACE ">=" ";" parts ${trimmed_requirement} )
232
- else ()
233
- message (WARNING "Could not parse requirement '${trimmed_requirement} '. Skipping..." )
234
- continue ()
235
- endif ()
236
-
237
- list (GET parts 0 package_name)
238
- list (GET parts 1 package_version )
239
-
240
- # If the package name or version could not be parsed, output a warning and skip
241
- if (NOT package_name OR NOT package_version )
242
- message (WARNING "Could not parse requirement '${trimmed_requirement} '. Skipping..." )
243
- continue ()
244
- endif ()
245
-
246
- # Check if the package is installed
247
- message (STATUS "Checking if Python package '${package_name} ' is installed..." )
248
- check_python_package(${package_name} ${package_version} )
249
- if (NOT result)
250
- message (STATUS "Package '${package_name} ' is not installed or needs an upgrade. Installing..." )
251
- execute_process (
252
- COMMAND ${PIP_EXECUTABLE} install ${trimmed_requirement}
253
- RESULT_VARIABLE install_result
254
- )
255
- if (NOT install_result EQUAL 0)
256
- message (FATAL_ERROR "Failed to install Python package '${package_name} '." )
257
- endif ()
258
- else ()
259
- message (STATUS "Package '${package_name} ' is already installed with a suitable version." )
260
- endif ()
261
- endforeach ()
262
- execute_process (
263
- COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_BINARY_DIR} /check_marker.txt"
264
- RESULT_VARIABLE result
265
- )
266
- endif ()
112
+ # Configure Python environment
113
+ include (cmake/python_environment.cmake)
267
114
268
115
# Configure config.h
269
116
configure_file (${lithium_src_dir} /config.h.in ${CMAKE_CURRENT_BINARY_DIR} /config.h)
@@ -273,13 +120,16 @@ set(BUILD_SHARED_LIBS ON)
273
120
# Add subdirectories
274
121
add_subdirectory (libs)
275
122
add_subdirectory (modules)
123
+
276
124
add_subdirectory (${lithium_module_dir} )
125
+
277
126
add_subdirectory (${lithium_src_dir} /config)
278
127
add_subdirectory (${lithium_src_dir} /task)
279
128
add_subdirectory (${lithium_src_dir} /server)
280
129
add_subdirectory (${lithium_src_dir} /utils)
281
130
add_subdirectory (${lithium_src_dir} /addon)
282
131
add_subdirectory (${lithium_src_dir} /client)
132
+ add_subdirectory (${lithium_src_dir} /target )
283
133
add_subdirectory (${lithium_src_dir} /device)
284
134
add_subdirectory (tests)
285
135
@@ -399,17 +249,7 @@ target_compile_definitions(lithium_server PRIVATE LOGURU_DEBUG_LOGGING)
399
249
set_target_properties (lithium_server PROPERTIES OUTPUT_NAME lithium_server)
400
250
401
251
# Set install paths
402
- if (UNIX AND NOT APPLE )
403
- if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
404
- set (CMAKE_INSTALL_PREFIX /usr CACHE PATH "Lithium install path" FORCE)
405
- endif ()
406
- endif ()
407
-
408
- if (WIN32 )
409
- set (CMAKE_INSTALL_PREFIX "C:/Program Files/LithiumServer" )
410
- elseif (LINUX)
411
- set (CMAKE_INSTALL_PREFIX "/usr/lithium" )
412
- endif ()
252
+ include (cmake/install_paths.cmake)
413
253
414
254
# Enable folder grouping in IDEs
415
255
set_property (GLOBAL PROPERTY USE_FOLDERS ON )
0 commit comments