From b21b131ccecfb9ce3c3c7d23bf64db34f79f2a7e Mon Sep 17 00:00:00 2001 From: Milosz Linkiewicz Date: Mon, 23 Sep 2024 08:46:31 +0000 Subject: [PATCH] Build dependencies and linker fixes 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 --- CMakeLists.txt | 5 ++++- ffmpeg-plugin/configure-ffmpeg.sh | 7 ++++++- media-proxy/CMakeLists.txt | 11 ++++++++--- media-proxy/tests/CMakeLists.txt | 12 ++++++++---- sdk/3rdparty/libmemif/src/CMakeLists.txt | 10 ++++++++-- sdk/CMakeLists.txt | 24 ++++++++++++++++++++---- sdk/libmcm_dp.pc.in | 4 ++-- sdk/libmcm_dp_dyn.pc.in | 14 ++++++++++++++ sdk/samples/CMakeLists.txt | 9 +++++---- tests/unit/CMakeLists.txt | 4 ++++ 10 files changed, 79 insertions(+), 21 deletions(-) create mode 100644 sdk/libmcm_dp_dyn.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f8bf11a2..f74e5bac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}) diff --git a/ffmpeg-plugin/configure-ffmpeg.sh b/ffmpeg-plugin/configure-ffmpeg.sh index 0a6c5db6..6cf9bb0a 100755 --- a/ffmpeg-plugin/configure-ffmpeg.sh +++ b/ffmpeg-plugin/configure-ffmpeg.sh @@ -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." diff --git a/media-proxy/CMakeLists.txt b/media-proxy/CMakeLists.txt index a6faa77b..bc36818e 100644 --- a/media-proxy/CMakeLists.txt +++ b/media-proxy/CMakeLists.txt @@ -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) @@ -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) @@ -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) diff --git a/media-proxy/tests/CMakeLists.txt b/media-proxy/tests/CMakeLists.txt index a52249c3..89241dc8 100644 --- a/media-proxy/tests/CMakeLists.txt +++ b/media-proxy/tests/CMakeLists.txt @@ -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) diff --git a/sdk/3rdparty/libmemif/src/CMakeLists.txt b/sdk/3rdparty/libmemif/src/CMakeLists.txt index a3a523c7..6fc237b6 100644 --- a/sdk/3rdparty/libmemif/src/CMakeLists.txt +++ b/sdk/3rdparty/libmemif/src/CMakeLists.txt @@ -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) @@ -53,4 +53,10 @@ foreach(file ${MEMIF_HEADERS}) ) endforeach() -install(TARGETS memif DESTINATION lib COMPONENT libmemif) +add_library(memif_shared SHARED $) +add_library(memif_static STATIC $) +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) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 94fbddf6..691cda72 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -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}) @@ -69,6 +69,7 @@ include(CPack) list(APPEND SDK_HEADERS include/mcm_dp.h + ${MEMIF_DIR}/src/libmemif.h ) foreach(file ${SDK_HEADERS}) @@ -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 $) +add_library(mcm_dp_static STATIC $) +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") diff --git a/sdk/libmcm_dp.pc.in b/sdk/libmcm_dp.pc.in index 84912981..9207641c 100644 --- a/sdk/libmcm_dp.pc.in +++ b/sdk/libmcm_dp.pc.in @@ -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 diff --git a/sdk/libmcm_dp_dyn.pc.in b/sdk/libmcm_dp_dyn.pc.in new file mode 100644 index 00000000..f37d96bb --- /dev/null +++ b/sdk/libmcm_dp_dyn.pc.in @@ -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 diff --git a/sdk/samples/CMakeLists.txt b/sdk/samples/CMakeLists.txt index 40fc55de..5f2b634c 100644 --- a/sdk/samples/CMakeLists.txt +++ b/sdk/samples/CMakeLists.txt @@ -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}) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index bc39dc72..429aa592 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -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}) @@ -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/ )