From 1f710d7ac059cecab5e862f8280afa710698b873 Mon Sep 17 00:00:00 2001 From: Oleksandr Ismailov Date: Wed, 24 Apr 2024 17:48:48 +0200 Subject: [PATCH] Added cmake improvements to build all needed dependencies and deliver installation as module only or mixed with dependencies. Everything now configured from cmake indepemdenctly. Signed-off-by: Oleksandr Ismailov --- .github/workflows/cmake.yml | 15 +++++---- .gitignore | 6 ++++ CMakeLists.txt | 60 +++++++++++++++++++-------------- dependencies/dependencies.cmake | 14 ++++++++ src/stdinc.h | 14 ++++---- 5 files changed, 70 insertions(+), 39 deletions(-) create mode 100644 dependencies/dependencies.cmake diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b237e96..0979f82 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -31,12 +31,15 @@ jobs: gcc --version cmake --version - - name: Build and install libxutils - run: cd libxutils && ./build.sh --tool=cmake --install + #- name: Build and install libxutils + # run: cd libxutils && ./build.sh --tool=cmake --install - name: Make build run: | - mkdir build - cd build - cmake .. - make + cd libxutils && cmake -Bbuild -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/libxmedia -DDEPENDENCIES_PREFIX_INSTALL=${{github.workspace}}/libxmedia && cmake --build build --target install + + - name: Uploading libxmedia + uses: actions/upload-artifact@v4 + with: + name: ubuntu_latest_libxmedia + path: ${{github.workspace}}/libxmedia diff --git a/.gitignore b/.gitignore index c6127b3..6e015a3 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,9 @@ modules.order Module.symvers Mkfile.old dkms.conf + +# IDE temporary files +.idea +cmake-build-debug +cmake-build-release +libxmedia diff --git a/CMakeLists.txt b/CMakeLists.txt index 18851bc..3ae7786 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,37 +1,45 @@ cmake_minimum_required(VERSION 3.10) - project(xmedia) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Wall -D_XUTILS_DEBUG") -include_directories(${PROJECT_SOURCE_DIR}/src) +option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) + +include(dependencies/dependencies.cmake) + +file(GLOB SOURCES src/*.c) +add_library(${PROJECT_NAME} + ${SOURCES}) -set(SOURCES - ${PROJECT_SOURCE_DIR}/src/codec.c - ${PROJECT_SOURCE_DIR}/src/decoder.c - ${PROJECT_SOURCE_DIR}/src/encoder.c - ${PROJECT_SOURCE_DIR}/src/frame.c - ${PROJECT_SOURCE_DIR}/src/meta.c - ${PROJECT_SOURCE_DIR}/src/mpegts.c - ${PROJECT_SOURCE_DIR}/src/nalu.c - ${PROJECT_SOURCE_DIR}/src/status.c - ${PROJECT_SOURCE_DIR}/src/stream.c - ${PROJECT_SOURCE_DIR}/src/version.c -) +add_dependencies(${PROJECT_NAME} dependencies) -add_library(${PROJECT_NAME} STATIC ${SOURCES}) -SET(DST_DIR "/usr/local/include/xmedia") +target_include_directories(${PROJECT_NAME} + PRIVATE + ${DEPENDENCIES_PREFIX_INSTALL}/include + ${DEPENDENCIES_PREFIX_INSTALL}/include/xutils # TODO: temporary inconvinient should be reduced usage "" in the xutils headers + src) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET + libavutil + libavcodec + libavformat + libavdevice + #libavfilter + libswscale + libswresample) target_link_libraries(${PROJECT_NAME} + PUBLIC + -L${DEPENDENCIES_PREFIX_INSTALL}/lib # TODO: expected all dependencies located here xutils pthread - avutil - avcodec - avformat - avdevice - swscale - swresample -) - -install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION /usr/local/lib) -install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ DESTINATION ${DST_DIR} FILES_MATCHING PATTERN "*.h") + PkgConfig::LIBAV) + +include(GNUInstallDirs) +install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} + ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}) + +install(DIRECTORY src/ DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/xmedia FILES_MATCHING PATTERN "*.h") diff --git a/dependencies/dependencies.cmake b/dependencies/dependencies.cmake new file mode 100644 index 0000000..4df4d93 --- /dev/null +++ b/dependencies/dependencies.cmake @@ -0,0 +1,14 @@ +if("${DEPENDENCIES_PREFIX_INSTALL}" STREQUAL "") + set(DEPENDENCIES_PREFIX_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/dependencies) +endif() + +set(dependencies_LIST) + +include(ExternalProject) +ExternalProject_Add(libxutils_external + GIT_REPOSITORY https://github.com/kala13x/libxutils + GIT_TAG feature/fixes-for-cmake-added-macos-support + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${DEPENDENCIES_PREFIX_INSTALL} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}) +list(APPEND dependencies_LIST libxutils_external) + +add_custom_target(dependencies DEPENDS ${dependencies_LIST}) diff --git a/src/stdinc.h b/src/stdinc.h index 8ae4ef5..97ea86f 100644 --- a/src/stdinc.h +++ b/src/stdinc.h @@ -10,14 +10,14 @@ #ifndef __XMEDIA_STDINC_H__ #define __XMEDIA_STDINC_H__ -#include -#include -#include +#include +#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include