0

I am trying write CMakeLists with FFmpeg package, with compile on Windows and Linux. First downloaded from FFmpeg-Builds shared releases

I imagine the structure of the project like this:

<project root>
deps/
  ffmpeg/
    win-x64/
      incluve/
      lib/
      bin/
    linux-x64/
      incluve/
      lib/
      bin/
src/
CMakeLists.txt

How to help CMake find libraries: avcodec, avformat, avutil, etc? Maybe in the folder lib/pkgconfig using PkgConfig it is possible to specify the path. But I dont know how

zerpico
  • 103
  • 3
  • My expectation is you want to start reading here: [https://cmake.org/cmake/help/v3.23/command/find_package.html](https://cmake.org/cmake/help/v3.23/command/find_package.html) – drescherjm Mar 18 '22 at 18:48
  • It didn't help. I still didn't understand how to specify the local path to the library – zerpico Mar 18 '22 at 20:00
  • Related: [https://stackoverflow.com/questions/49816206/cmake-find-package-specify-path](https://stackoverflow.com/questions/49816206/cmake-find-package-specify-path) – drescherjm Mar 18 '22 at 20:22

1 Answers1

1

The following worked well for me on Linux with cmake. You will have to find the equivalents for Windows. I used ffmpeg on Windows, but without cmake (i.e. directly in a Visual Studio project).

  1. Install pkg-config, nasm:
    sudo apt-get install -y pkg-config

    sudo apt-get install nasm 
  1. Download ffmpeg source code:

    https://ffmpeg.org/download.html

  2. Build ffmpeg and install it:

    tar -xvf <downloaded_filename>
    cd /root/folder/with/ffmpeg/src
    ./configure
    make
    sudo make install 
    
  3. Add the following to your CMakeLists.txt:

    In the beginning:

     find_package(PkgConfig REQUIRED)
     pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
         libavdevice
         libavfilter
         libavformat
         libavcodec
         libswresample
         libswscale
         libavutil
     )
    
     set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
    

    In the linker area:

     target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::LIBAV)
    
wohlstad
  • 12,661
  • 10
  • 26
  • 39
  • Can I download already compiled libraries from the link in the question? Besides, I need support for compiling under Windows. Isn't it easier to use already compiled libraries? – zerpico Mar 21 '22 at 05:51
  • For Linux I found it easier to build from source. For Windows I believe the pre-built libraries are easier to use. This is indeed what I did myself. But as I wrote I used them directly in the VisualStudio project (added include and library paths, and link with appropriate libs). – wohlstad Mar 21 '22 at 06:23