Skip to content

Commit

Permalink
Build dependencies and linker fixes
Browse files Browse the repository at this point in the history
Build dependencies and linker fixes focus is on:
- building all dependencies for mcm as a pre-build phase
- address linker issues that required passing specific paths for libraries to be found under debian
- lots of minor changes is between.

Signed-off-by: Milosz Linkiewicz <[email protected]>
  • Loading branch information
Mionsz committed Sep 27, 2024
1 parent 213ce27 commit b21b131
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 21 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ set(SDK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk)
set(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests/unit)
set(SDK_INCLUDE_DIR ${SDK_DIR}/include)

find_library(LIB_BSD bsd)
add_compile_definitions(HAS_LIB_BSD)

# Setup output folder
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand All @@ -42,4 +45,4 @@ if (BUILD_UNIT_TESTS)
endif()

target_include_directories(media_proxy_lib PUBLIC ${SDK_INCLUDE_DIR})
target_link_libraries(media_proxy_lib PUBLIC mcm_dp)
target_link_libraries(media_proxy_lib PRIVATE mcm_dp_static ${LIB_BSD})
7 changes: 6 additions & 1 deletion ffmpeg-plugin/configure-ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" pkg-config --exists --print-errors li
# copy source files to allow the configure tool to find them
#cp -f ../mcm_* ./libavdevice/

"${BUILD_DIR}/FFmpeg/configure" --enable-shared --enable-mcm $@
"${BUILD_DIR}/FFmpeg/configure" \
--disable-doc \
--disable-shared \
--enable-static \
--enable-mcm \
--enable-cross-compile
popd

prompt "FFmpeg MCM plugin configuration completed."
Expand Down
11 changes: 8 additions & 3 deletions media-proxy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")

set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED)
find_library(LIBBPF libbpf.a PATHS /usr/lib64)
message(STATUS "Using protobuf ${Protobuf_VERSION}")

set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
Expand Down Expand Up @@ -46,6 +47,10 @@ set(target media_proxy)
set(MTL_LIB mtl)
set(MEMIF_LIB memif)

# setup components folders
set(MCM_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SDK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../sdk)
set(MEMIF_DIR ${SDK_DIR}/3rdparty/libmemif)
# Get proto files
get_filename_component(proto "./protos/${proto_name}.proto" ABSOLUTE)
get_filename_component(proto_dir "${proto}" DIRECTORY)
Expand Down Expand Up @@ -83,14 +88,14 @@ ADD_DEFINITIONS(-DIMTL_CONFIG_PATH=\"${CMAKE_INSTALL_PREFIX}/etc/imtl.json\")
ADD_DEFINITIONS(-D_GNU_SOURCE)

# Include generated *.pb.h files
include_directories(${CMAKE_CURRENT_BINARY_DIR} ./include ${LIBFABRIC_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR} ./include ${LIBFABRIC_INCLUDE_DIR} ${MEMIF_DIR}/src)

add_library(media_proxy_lib ${proto_srcs} ${grpc_srcs} ${proxy_srcs})
add_library(media_proxy_lib STATIC ${proto_srcs} ${grpc_srcs} ${proxy_srcs})
target_link_libraries(media_proxy_lib PUBLIC m ${MTL_LIB} ${_REFLECTION}
${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF} ${MEMIF_LIB} ${LIBFABRIC})

add_executable(media_proxy ${proxy_srcs})
target_link_libraries(media_proxy PRIVATE media_proxy_lib)
target_link_libraries(media_proxy PRIVATE media_proxy_lib -static-libgcc -static-libstdc++ -pthread -ldl ${LIBBPF})

install(TARGETS media_proxy DESTINATION ${CMAKE_INSTALL_PATH} COMPONENT media_proxy)
install(FILES imtl.json DESTINATION ${CMAKE_CONFIG_PATH} COMPONENT config)
12 changes: 8 additions & 4 deletions media-proxy/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ project(McmMeifTests VERSION 0.1.0 LANGUAGES CXX C)

set(CMAKE_C_STANDARD 11)

set(MCM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(SDK_DIR ${MCM_DIR}/../sdk)
set(MEMIF_DIR ${SDK_DIR}/3rdparty/libmemif)

add_executable(memif_test_rx memif_test_rx.c)
target_include_directories(memif_test_rx PRIVATE ../include)
target_link_libraries(memif_test_rx PRIVATE mcm_dp)
target_include_directories(memif_test_rx PRIVATE ../include ${MEMIF_DIR}/src)
target_link_libraries(memif_test_rx PRIVATE mcm_dp_static)

add_executable(memif_test_tx memif_test_tx.c)
target_include_directories(memif_test_tx PRIVATE ../include)
target_link_libraries(memif_test_tx PRIVATE mcm_dp)
target_include_directories(memif_test_tx PRIVATE ../include ${MEMIF_DIR}/src)
target_link_libraries(memif_test_tx PRIVATE mcm_dp_static)
10 changes: 8 additions & 2 deletions sdk/3rdparty/libmemif/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ list(APPEND MEMIF_SOURCES

include_directories(${HEADERS_DIR})

add_library(memif SHARED ${MEMIF_SOURCES})
add_library(memif OBJECT ${MEMIF_SOURCES})
target_link_libraries(memif ${CMAKE_THREAD_LIBS_INIT})

set_target_properties(memif PROPERTIES POSITION_INDEPENDENT_CODE ON)
Expand All @@ -53,4 +53,10 @@ foreach(file ${MEMIF_HEADERS})
)
endforeach()

install(TARGETS memif DESTINATION lib COMPONENT libmemif)
add_library(memif_shared SHARED $<TARGET_OBJECTS:memif>)
add_library(memif_static STATIC $<TARGET_OBJECTS:memif>)
set_target_properties(memif_shared PROPERTIES OUTPUT_NAME memif)
set_target_properties(memif_static PROPERTIES OUTPUT_NAME memif)

install(TARGETS memif_shared DESTINATION lib COMPONENT libmemif)
install(TARGETS memif_static DESTINATION lib COMPONENT libmemif)
24 changes: 20 additions & 4 deletions sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
set(CMAKE_INSTALL_IPATH ${CMAKE_INSTALL_PREFIX}/include)

aux_source_directory(${MCMDP_SRC_DIR} sdk_srcs)
add_library(mcm_dp SHARED ${sdk_srcs})
add_library(mcm_dp OBJECT ${sdk_srcs})
set_target_properties(mcm_dp PROPERTIES VERSION ${VERSION})
set_target_properties(mcm_dp PROPERTIES POSITION_INDEPENDENT_CODE ON)
# set_target_properties(mcm_dp PROPERTIES C_VISIBILITY_PRESET hidden)

target_include_directories(mcm_dp PUBLIC
target_include_directories(mcm_dp PRIVATE
${MCMDP_INCLUDE_DIR}
${MEMIF_DIR}/src)
target_link_libraries(mcm_dp PUBLIC memif)
target_link_libraries(mcm_dp PRIVATE memif_static ${LIB_BSD})

add_subdirectory(${MCMDP_SAMPLE_DIR})

Expand All @@ -69,6 +69,7 @@ include(CPack)

list(APPEND SDK_HEADERS
include/mcm_dp.h
${MEMIF_DIR}/src/libmemif.h
)

foreach(file ${SDK_HEADERS})
Expand All @@ -88,8 +89,23 @@ if (BUILD_SHARED_LIBS)
set(LIB_PKG_CONFIG_EXTRA_CFLAGS " -DDEF_DLL")
endif()

configure_file(${MCM_TARGET}_dyn.pc.in ${CMAKE_BINARY_DIR}/${MCM_TARGET}_dyn.pc @ONLY)
configure_file(${MCM_TARGET}.pc.in ${CMAKE_BINARY_DIR}/${MCM_TARGET}.pc @ONLY)

# include(CMakePackageConfigHelpers)
install(TARGETS mcm_dp DESTINATION ${CMAKE_INSTALL_RPATH} COMPONENT ${MCM_TARGET})
add_library(mcm_dp_shared SHARED $<TARGET_OBJECTS:mcm_dp>)
add_library(mcm_dp_static STATIC $<TARGET_OBJECTS:mcm_dp>)
set_target_properties(mcm_dp_shared PROPERTIES OUTPUT_NAME mcm_dp)
set_target_properties(mcm_dp_static PROPERTIES OUTPUT_NAME mcm_dp)

# Set the VERSION and SOVERSION properties for the shared library
set_target_properties(mcm_dp_shared PROPERTIES VERSION ${VERSION} SOVERSION ${MCM_VER_MAJOR})

# Link dependencies to the shared and static libraries
target_link_libraries(mcm_dp_shared PRIVATE memif_static ${LIB_BSD})
target_link_libraries(mcm_dp_static PRIVATE memif_static ${LIB_BSD})

install(TARGETS mcm_dp_shared LIBRARY DESTINATION ${CMAKE_INSTALL_RPATH} COMPONENT ${MCM_TARGET})
install(TARGETS mcm_dp_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${MCM_TARGET})
install(FILES "${CMAKE_BINARY_DIR}/${MCM_TARGET}_dyn.pc" DESTINATION "${CMAKE_INSTALL_RPATH}/pkgconfig")
install(FILES "${CMAKE_BINARY_DIR}/${MCM_TARGET}.pc" DESTINATION "${CMAKE_INSTALL_RPATH}/pkgconfig")
4 changes: 2 additions & 2 deletions sdk/libmcm_dp.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Version: @VERSION@
Requires: libbsd @pc_req_public@
Requires.private: @pc_req_private@
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -lmcm_dp
Libs.private: -L"${libdir}" -lmcm_dp
Libs: -L"${libdir}" -l:libmcm_dp.a -l:libmemif.a
Libs.private: -static
14 changes: 14 additions & 0 deletions sdk/libmcm_dp_dyn.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix="${prefix}"
libdir="${prefix}/lib"
includedir="${prefix}/include"

Name: @PROJECT_NAME@
Description: @CMAKE_PROJECT_DESCRIPTION@
URL: @CMAKE_PROJECT_HOMEPAGE_URL@
Version: @VERSION@
Requires: libbsd @pc_req_public@
Requires.private: @pc_req_private@
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -lmcm_dp -lmemif
Libs.private: -L"${libdir}" -lmcm_dp -lmemif -static
9 changes: 5 additions & 4 deletions sdk/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ project(McmDPSdk_Samples VERSION 0.1.0
)

set(CMAKE_C_STANDARD 11)
set(LIBMEMIF_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/libmemif/src)

add_executable(sender_app sender_app.c)
target_include_directories(sender_app PRIVATE ../include)
target_link_libraries(sender_app PRIVATE mcm_dp)
target_include_directories(sender_app PRIVATE ../include ${LIBMEMIF_INCLUDE_DIR})
target_link_libraries(sender_app PRIVATE mcm_dp_static ${LIB_BSD})

add_executable(recver_app recver_app.c)
target_include_directories(recver_app PRIVATE ../include)
target_link_libraries(recver_app PRIVATE mcm_dp)
target_include_directories(recver_app PRIVATE ../include ${LIBMEMIF_INCLUDE_DIR})
target_link_libraries(recver_app PRIVATE mcm_dp_static ${LIB_BSD})
4 changes: 4 additions & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
file(GLOB TEST_SOURCES "*.cc")

set(MP_LIB media_proxy_lib)
set(MCM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../media-proxy)
set(SDK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk)
set(MEMIF_DIR ${SDK_DIR}/3rdparty/libmemif)

# Add an executable for tests
add_executable(mcm_unit_tests ${TEST_SOURCES})
Expand All @@ -10,6 +13,7 @@ add_executable(mcm_unit_tests ${TEST_SOURCES})
target_link_libraries(mcm_unit_tests PRIVATE gtest gtest_main ${MP_LIB})
target_include_directories(mcm_unit_tests PUBLIC
${CMAKE_SOURCE_DIR}/media-proxy/include
${MEMIF_DIR}/src
# Include generated *.pb.h files
${CMAKE_BINARY_DIR}/media-proxy/
)
Expand Down

0 comments on commit b21b131

Please sign in to comment.