以接口库的方式导入预编译库
cmake_minimum_required(VERSION 3.9) project(test) set(CMAKE_BUILD_TYPE Debug) set(CMAKE_C_FLAGS "$ENV{CFLAGS} -O2 -Wall -pthread ") set(CMAKE_CXX_FLAGS "$ENV{CFLAGS} -O2 -Wall -pthread -std=c++11 -std=gnu++11") #设置module的查找路径 #list(APPEND CMAKE_MODULE_PATH "/your/module/path") #找module,找不到报错 #find_package(ffmpeg REQUIRED) #######################################接口库设置####################################### #设置预编译库的路径 set(FFMPEG_LIB_PATH ${PROJECT_SOURCE_DIR}/external/ffmpeg/prebuild/lib/${CMAKE_SYSTEM_PROCESSOR}/linux/lib64) #添加需要的库 set(FFMPEG_LIBS "\ ${FFMPEG_LIB_PATH}/libavfilter.so;\ ${FFMPEG_LIB_PATH}/libavformat.so;\ ${FFMPEG_LIB_PATH}/libavcodec.so;\ ${FFMPEG_LIB_PATH}/libavutil.so;\ ${FFMPEG_LIB_PATH}/libswresample.so;\ ${FFMPEG_LIB_PATH}/libswscale.so;\ ${FFMPEG_LIB_PATH}/libavdevice.so\ ") #x86_64平台编译的ffmpeg依赖libx264-dev libx265-dev库 string(FIND "${CMAKE_SYSTEM_PROCESSOR}" "x86_64" NEED_X264) if(NEED_X264 GREATER -1) string(APPEND FFMPEG_LIBS ";${FFMPEG_LIB_PATH}/libx264.so;${FFMPEG_LIB_PATH}/libx265.so") endif() #指定接口库的名字 add_library(ffmpeg INTERFACE IMPORTED GLOBAL) #设置接口库指向哪些预编译库 set_target_properties(ffmpeg PROPERTIES INTERFACE_LINK_LIBRARIES "${FFMPEG_LIBS}" ) #设置接口库包含的头文件 set_target_properties(ffmpeg PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/external/ffmpeg/prebuild/include" ) #######################################接口库设置####################################### add_definitions(-fpermissive) add_executable(haha main.cpp) target_link_libraries(haha ffmpeg)
标签:CMakeLists,set,FFMPEG,LIB,---,so,PATH,txt,ffmpeg From: https://www.cnblogs.com/linxisuo/p/18172197