Skip to content

Commit e66f881

Browse files
committed
refactor: clean redundant link lib
1 parent 3aa5675 commit e66f881

File tree

7 files changed

+57
-65
lines changed

7 files changed

+57
-65
lines changed

CMakeLists.txt

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ else()
2121
endif()
2222

2323
set(WEBRTC_INCLUDE_DIR /usr/local/include/webrtc)
24-
set(WEBRTC_LIBRARY /usr/local/lib/libwebrtc.a)
25-
set(WEBRTC_LINK_LIBS dl)
24+
set(WEBRTC_LIBRARY
25+
/usr/local/lib/libwebrtc.a
26+
avcodec
27+
)
28+
2629
set(THREADS_PREFER_PTHREAD_FLAG ON)
27-
find_package(Threads REQUIRED)
2830

2931
message(STATUS "BUILD_TEST: ${BUILD_TEST}")
3032
message(STATUS "WEBRTC_INCLUDE_DIR: ${WEBRTC_INCLUDE_DIR}")
@@ -35,7 +37,6 @@ add_compile_definitions(
3537
WEBRTC_POSIX
3638
WEBRTC_LINUX
3739
WEBRTC_USE_H264
38-
USE_CPPRESTSDK
3940
OPENSSL_IS_BORINGSSL
4041
)
4142

@@ -53,105 +54,75 @@ include_directories(
5354
${WEBRTC_INCLUDE_DIR}/tools/json_schema_compiler
5455
)
5556

57+
add_subdirectory(src/capturer)
58+
add_subdirectory(src/codecs/h264)
59+
add_subdirectory(src/codecs/v4l2)
60+
add_subdirectory(src/common)
61+
add_subdirectory(src/recorder)
62+
add_subdirectory(src/rtc)
63+
add_subdirectory(src/signaling)
64+
add_subdirectory(src/track)
65+
5666
if(BUILD_TEST STREQUAL "http_server")
5767
add_executable(test_http_server test/test_http_server.cpp)
68+
target_link_libraries(test_http_server
69+
signaling
70+
)
5871
elseif(BUILD_TEST STREQUAL "pulseaudio")
5972
add_executable(test_pulseaudio test/test_pulseaudio.cpp)
60-
6173
target_link_libraries(test_pulseaudio
6274
pulse-simple pulse
6375
)
6476
elseif(BUILD_TEST STREQUAL "recorder")
65-
add_subdirectory(src/common)
66-
add_subdirectory(src/capturer)
67-
add_subdirectory(src/recorder)
68-
add_subdirectory(src/v4l2_codecs)
6977
add_executable(test_recorder test/test_recorder.cpp)
7078
target_link_libraries(test_recorder
71-
capturer
7279
recorder
7380
)
7481
elseif(BUILD_TEST STREQUAL "mqtt")
75-
add_subdirectory(src/signaling)
7682
add_executable(test_mqtt test/test_mqtt.cpp)
77-
7883
target_link_libraries(test_mqtt
7984
signaling
8085
)
81-
target_link_libraries(test_mqtt
82-
Threads::Threads
83-
${MOSQUITTO_LIBS}
84-
)
8586
elseif(BUILD_TEST STREQUAL "websocket")
8687
add_executable(test_websocket test/test_websocket.cpp)
87-
8888
target_link_libraries(test_websocket
89-
ssl
90-
crypto
89+
signaling
9190
)
9291
elseif(BUILD_TEST STREQUAL "openh264")
9392
add_executable(test_openh264 test/test_openh264.cpp)
93+
# Use the OpenH264 library in libwebrtc.a
9494
target_link_libraries(test_openh264
95-
${WEBRTC_LINK_LIBS}
9695
${WEBRTC_LIBRARY}
9796
)
9897
elseif(BUILD_TEST STREQUAL "v4l2_capturer")
99-
add_subdirectory(src/capturer)
100-
add_subdirectory(src/common)
101-
add_subdirectory(src/v4l2_codecs)
10298
add_executable(test_v4l2_capturer test/test_v4l2_capturer.cpp)
10399
target_link_libraries(test_v4l2_capturer
104100
capturer
105-
v4l2_codecs
106101
)
107102
elseif(BUILD_TEST STREQUAL "v4l2_encoder")
108-
add_subdirectory(src/capturer)
109-
add_subdirectory(src/common)
110-
add_subdirectory(src/v4l2_codecs)
111103
add_executable(test_v4l2_encoder test/test_v4l2_encoder.cpp)
112104
target_link_libraries(test_v4l2_encoder
113105
capturer
114-
v4l2_codecs
115106
)
116107
elseif(BUILD_TEST STREQUAL "v4l2_decoder")
117-
add_subdirectory(src/capturer)
118-
add_subdirectory(src/common)
119-
add_subdirectory(src/v4l2_codecs)
120108
add_executable(test_v4l2_decoder test/test_v4l2_decoder.cpp)
121109
target_link_libraries(test_v4l2_decoder
122110
capturer
123-
v4l2_codecs
124111
)
125112
elseif(BUILD_TEST STREQUAL "v4l2_scaler")
126-
add_subdirectory(src/capturer)
127-
add_subdirectory(src/common)
128-
add_subdirectory(src/v4l2_codecs)
129113
add_executable(test_v4l2_scaler test/test_v4l2_scaler.cpp)
130114
target_link_libraries(test_v4l2_scaler
131115
capturer
132-
v4l2_codecs
133116
)
134117
elseif(BUILD_TEST STREQUAL "libcamera")
135-
add_subdirectory(src/capturer)
136-
add_subdirectory(src/common)
137118
add_executable(test_libcamera test/test_libcamera.cpp)
138119
target_link_libraries(test_libcamera
139120
capturer
140-
common
141-
)
142-
target_link_libraries(test_libcamera
143-
${WEBRTC_LINK_LIBS}
144-
Threads::Threads
145-
${WEBRTC_LIBRARY}
146121
)
147122
else()
148123
add_subdirectory(src)
149124
add_executable(${PROJECT_NAME} src/main.cpp)
150125
target_link_libraries(${PROJECT_NAME}
151126
src
152-
${WEBRTC_LINK_LIBS}
153-
boost_program_options
154-
Threads::Threads
155-
${WEBRTC_LIBRARY}
156127
)
157128
endif()

src/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
project(src)
22

3-
add_subdirectory(common)
4-
add_subdirectory(track)
5-
add_subdirectory(capturer)
6-
add_subdirectory(codecs/h264)
7-
add_subdirectory(codecs/v4l2)
8-
add_subdirectory(signaling)
9-
add_subdirectory(recorder)
10-
add_subdirectory(rtc)
11-
123
add_library(${PROJECT_NAME}
134
parser.cpp
145
)
156

16-
target_link_libraries(${PROJECT_NAME} PUBLIC rtc signaling recorder common)
7+
target_link_libraries(${PROJECT_NAME} PUBLIC rtc signaling recorder common boost_program_options)

src/capturer/CMakeLists.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,27 @@ message(STATUS " version: ${LIBCAMERA_VERSION}")
77
message(STATUS " libraries: ${LIBCAMERA_LINK_LIBRARIES}")
88
message(STATUS " include path: ${LIBCAMERA_INCLUDE_DIRS}")
99

10+
pkg_check_modules(PULSE REQUIRED IMPORTED_TARGET libpulse)
11+
pkg_check_modules(PULSE_SIMPLE REQUIRED IMPORTED_TARGET libpulse-simple)
12+
message(STATUS "PulseAudio library found:")
13+
message(STATUS " PULSE libs: ${PULSE_LINK_LIBRARIES}")
14+
message(STATUS " PULSE_SIMPLE libs: ${PULSE_SIMPLE_LINK_LIBRARIES}")
15+
1016
aux_source_directory(${PROJECT_SOURCE_DIR} CAPTURE_FILES)
1117

1218
add_library(${PROJECT_NAME} ${CAPTURE_FILES})
1319

14-
target_include_directories(${PROJECT_NAME} PUBLIC ${LIBCAMERA_INCLUDE_DIRS})
15-
target_link_libraries(${PROJECT_NAME} PUBLIC common ${WEBRTC_LIBRARY} pulse-simple pulse ${LIBCAMERA_LINK_LIBRARIES})
20+
target_include_directories(${PROJECT_NAME} PUBLIC
21+
${LIBCAMERA_INCLUDE_DIRS}
22+
${PULSE_INCLUDE_DIRS}
23+
${PULSE_SIMPLE_INCLUDE_DIRS}
24+
)
25+
26+
target_link_libraries(${PROJECT_NAME} PUBLIC
27+
common
28+
v4l2_codecs
29+
${WEBRTC_LIBRARY}
30+
${LIBCAMERA_LINK_LIBRARIES}
31+
${PULSE_LINK_LIBRARIES}
32+
${PULSE_SIMPLE_LINK_LIBRARIES}
33+
)

src/codecs/h264/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ aux_source_directory(${PROJECT_SOURCE_DIR} H264_FILES)
44

55
add_library(${PROJECT_NAME} ${H264_FILES})
66

7-
target_link_libraries(${PROJECT_NAME} ${WEBRTC_LINK_LIBS} ${WEBRTC_LIBRARY})
7+
# Use the OpenH264 library in libwebrtc.a
8+
target_link_libraries(${PROJECT_NAME} ${WEBRTC_LIBRARY})

src/common/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@ aux_source_directory(${PROJECT_SOURCE_DIR} COMMON_FILES)
77

88
add_library(${PROJECT_NAME} ${COMMON_FILES})
99

10-
target_link_libraries(${PROJECT_NAME} ${JPEG_LIBRARIES} ${WEBRTC_LINK_LIBS}
11-
${WEBRTC_LIBRARY} Threads::Threads avformat uuid)
10+
# Use libyuv in libwebrtc.a
11+
target_link_libraries(${PROJECT_NAME}
12+
avutil
13+
avformat
14+
uuid
15+
${JPEG_LIBRARIES}
16+
${WEBRTC_LIBRARY}
17+
)

src/recorder/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
project(recorder)
22

3-
set(FFMPEG_LINK_LIBS avformat avcodec swscale avutil)
3+
set(FFMPEG_LINK_LIBS avformat)
44

55
aux_source_directory(${PROJECT_SOURCE_DIR} RECORDER_FILES)
66

src/signaling/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ add_library(${PROJECT_NAME}
1111
websocket_service.cpp
1212
)
1313

14-
target_link_libraries(${PROJECT_NAME} PRIVATE ${MOSQUITTO_LIBS})
14+
# Use boringssl in libwebrtc.a
15+
target_link_libraries(${PROJECT_NAME} PUBLIC
16+
rtc
17+
${MOSQUITTO_LIBS}
18+
${WEBRTC_LIBRARY}
19+
)

0 commit comments

Comments
 (0)