@@ -98,39 +98,19 @@ endif()
98
98
99
99
# Set up SOD library if enabled
100
100
if (ENABLE_SOD)
101
- # Only add the SOD subdirectory if we're doing static linking
102
- if ( NOT SOD_DYNAMIC_LINK)
103
- add_subdirectory (src/sod)
104
- endif ( )
101
+ # Add the SOD subdirectory regardless of linking method
102
+ # The CMakeLists.txt in the SOD directory will handle
103
+ # building as static or shared based on SOD_DYNAMIC_LINK
104
+ add_subdirectory (src/sod )
105
105
106
106
# Add the SOD_ENABLED define regardless of linking method
107
107
add_definitions (-DSOD_ENABLED)
108
108
109
109
# Always set the include directory
110
110
set (SOD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR} /src/sod" )
111
111
112
- # For dynamic linking, we need to find the SOD library in the system
112
+ # If dynamic linking is enabled, add the define
113
113
if (SOD_DYNAMIC_LINK)
114
- # First try pkg-config
115
- pkg_check_modules(SOD sod)
116
-
117
- # If not found via pkg-config, try find_library
118
- if (NOT SOD_FOUND)
119
- find_library (SOD_LIBRARY NAMES sod)
120
- if (SOD_LIBRARY)
121
- set (SOD_LIBRARIES ${SOD_LIBRARY} )
122
- set (SOD_FOUND TRUE )
123
- message (STATUS "Found SOD library: ${SOD_LIBRARY} " )
124
- endif ()
125
- endif ()
126
-
127
- # If still not found, warn but continue as the code will fall back to dynamic loading
128
- if (NOT SOD_FOUND)
129
- message (WARNING "SOD library not found for dynamic linking. "
130
- "The application will attempt to load it at runtime." )
131
- endif ()
132
-
133
- # Add a define to indicate dynamic linking should be used
134
114
add_definitions (-DSOD_DYNAMIC_LINK)
135
115
endif ()
136
116
endif ()
@@ -250,6 +230,11 @@ endif()
250
230
# Define the executable
251
231
add_executable (lightnvr ${SOURCES} )
252
232
233
+ # Set the output directory for the binary
234
+ set_target_properties (lightnvr PROPERTIES
235
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /bin"
236
+ )
237
+
253
238
# Link libraries
254
239
target_link_libraries (lightnvr
255
240
${FFMPEG_LIBRARIES}
@@ -268,17 +253,42 @@ endif()
268
253
269
254
# Link SOD library if enabled
270
255
if (ENABLE_SOD)
271
- if (SOD_DYNAMIC_LINK AND SOD_FOUND)
272
- # For dynamic linking, link against the found SOD library
273
- target_link_libraries (lightnvr ${SOD_LIBRARIES} )
274
- message (STATUS "Using dynamic linking for SOD library" )
275
- elseif (NOT SOD_DYNAMIC_LINK)
276
- # For static linking, link against our built SOD library
277
- target_link_libraries (lightnvr sod)
278
- message (STATUS "Using static linking for SOD library" )
256
+ # Always link to the sod target, whether it's built as static or shared
257
+ target_link_libraries (lightnvr sod)
258
+
259
+ # Log the linking method for clarity
260
+ if (SOD_DYNAMIC_LINK)
261
+ message (STATUS "Using dynamic linking for SOD library (built from source)" )
262
+
263
+ # Set proper RPATH settings for the main executable when using dynamic SOD
264
+ set_target_properties (lightnvr PROPERTIES
265
+ BUILD_WITH_INSTALL_RPATH TRUE
266
+ INSTALL_RPATH "$ORIGIN/../src/sod:$ORIGIN/../lib"
267
+ )
268
+
269
+ # Make sure the shared library gets installed to lib directory
270
+ install (TARGETS sod
271
+ LIBRARY DESTINATION lib
272
+ RUNTIME DESTINATION bin
273
+ )
274
+
275
+ # Copy the SOD shared library to a directory next to the executable
276
+ add_custom_command (TARGET lightnvr POST_BUILD
277
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR} /lib"
278
+ COMMAND ${CMAKE_COMMAND} -E copy
279
+ "$<TARGET_FILE:sod>"
280
+ "${CMAKE_BINARY_DIR} /lib/"
281
+ COMMENT "Copying SOD shared library to lib directory"
282
+ )
283
+
284
+ # Additional direct RPATH via linker flags for older systems
285
+ if (UNIX AND NOT APPLE )
286
+ set_target_properties (lightnvr PROPERTIES
287
+ LINK_FLAGS "-Wl,-rpath,\$ ORIGIN/../src/sod:\$ ORIGIN/../lib"
288
+ )
289
+ endif ()
279
290
else ()
280
- # SOD will be loaded at runtime
281
- message (STATUS "SOD will be loaded at runtime via dlopen()" )
291
+ message (STATUS "Using static linking for SOD library" )
282
292
endif ()
283
293
endif ()
284
294
@@ -293,9 +303,6 @@ if(BUILD_TESTS)
293
303
add_subdirectory (tests)
294
304
endif ()
295
305
296
- # Output binary to a 'bin' directory
297
- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin)
298
-
299
306
# Create a version.h file
300
307
configure_file (
301
308
${CMAKE_CURRENT_SOURCE_DIR} /include /core/version .h.in
@@ -317,4 +324,4 @@ message(STATUS "- Include directories:")
317
324
foreach (dir ${LIGHTNVR_INCLUDE_DIRS} )
318
325
message (STATUS " * ${dir} " )
319
326
endforeach ()
320
- message (STATUS "Ensure all dependencies are optimized for low memory usage" )
327
+ message (STATUS "Ensure all dependencies are optimized for low memory usage" )
0 commit comments