以介面庫的方式匯入預編譯庫
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)