diff --git a/CMakeLists.txt b/CMakeLists.txt index b96825b06..ede3bb83e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -438,130 +438,83 @@ else() message(FATAL_ERROR "ZoneMinder requires mysqlclient but it was not found on your system") endif() -set(PATH_FFMPEG "") -set(OPT_FFMPEG "no") -# avformat (using find_library and find_path) -find_library(AVFORMAT_LIBRARIES avformat) -if(AVFORMAT_LIBRARIES) +find_package(FFMPEG COMPONENTS avformat) +if(FFMPEG_avformat_FOUND) set(HAVE_LIBAVFORMAT 1) - list(APPEND ZM_BIN_LIBS "${AVFORMAT_LIBRARIES}") - find_path(AVFORMAT_INCLUDE_DIR "libavformat/avformat.h" /usr/include/ffmpeg) - if(AVFORMAT_INCLUDE_DIR) - include_directories("${AVFORMAT_INCLUDE_DIR}") - set(CMAKE_REQUIRED_INCLUDES "${AVFORMAT_INCLUDE_DIR}") - endif() - mark_as_advanced(FORCE AVFORMAT_LIBRARIES AVFORMAT_INCLUDE_DIR) - check_include_file("libavformat/avformat.h" HAVE_LIBAVFORMAT_AVFORMAT_H) + set(HAVE_LIBAVFORMAT_AVFORMAT_H 1) + list(APPEND ZM_BIN_LIBS "FFMPEG::avformat") set(optlibsfound "${optlibsfound} AVFormat") else() set(optlibsnotfound "${optlibsnotfound} AVFormat") endif() -# avcodec (using find_library and find_path) -find_library(AVCODEC_LIBRARIES avcodec) -if(AVCODEC_LIBRARIES) +find_package(FFMPEG COMPONENTS avcodec) +if(FFMPEG_avcodec_FOUND) set(HAVE_LIBAVCODEC 1) - list(APPEND ZM_BIN_LIBS "${AVCODEC_LIBRARIES}") - find_path(AVCODEC_INCLUDE_DIR "libavcodec/avcodec.h" /usr/include/ffmpeg) - if(AVCODEC_INCLUDE_DIR) - include_directories("${AVCODEC_INCLUDE_DIR}") - set(CMAKE_REQUIRED_INCLUDES "${AVCODEC_INCLUDE_DIR}") - endif() - mark_as_advanced(FORCE AVCODEC_LIBRARIES AVCODEC_INCLUDE_DIR) - check_include_file("libavcodec/avcodec.h" HAVE_LIBAVCODEC_AVCODEC_H) + set(HAVE_LIBAVCODEC_AVCODEC_H 1) + list(APPEND ZM_BIN_LIBS "${FFMPEG_avcodec_LIBRARIES}") set(optlibsfound "${optlibsfound} AVCodec") else() message(WARNING "\nWhile it should be possible to build ZM without AVCODEC the result will pretty useless.") set(optlibsnotfound "${optlibsnotfound} AVCodec") endif() -# avdevice (using find_library and find_path) -find_library(AVDEVICE_LIBRARIES avdevice) -if(AVDEVICE_LIBRARIES) +find_package(FFMPEG COMPONENTS avdevice) +if(FFMPEG_avdevice_FOUND) set(HAVE_LIBAVDEVICE 1) - list(APPEND ZM_BIN_LIBS "${AVDEVICE_LIBRARIES}") - find_path(AVDEVICE_INCLUDE_DIR "libavdevice/avdevice.h" /usr/include/ffmpeg) - if(AVDEVICE_INCLUDE_DIR) - include_directories("${AVDEVICE_INCLUDE_DIR}") - set(CMAKE_REQUIRED_INCLUDES "${AVDEVICE_INCLUDE_DIR}") - endif() - mark_as_advanced(FORCE AVDEVICE_LIBRARIES AVDEVICE_INCLUDE_DIR) - check_include_file("libavdevice/avdevice.h" HAVE_LIBAVDEVICE_AVDEVICE_H) + set(HAVE_LIBAVDEVICE_AVDEVICE_H 1) + list(APPEND ZM_BIN_LIBS "${FFMPEG_avdevice_LIBRARIES}") set(optlibsfound "${optlibsfound} AVDevice") else() set(optlibsnotfound "${optlibsnotfound} AVDevice") endif() -# avutil (using find_library and find_path) -find_library(AVUTIL_LIBRARIES avutil) -if(AVUTIL_LIBRARIES) +find_package(FFMPEG COMPONENTS avutil) +if(FFMPEG_avutil_FOUND) set(HAVE_LIBAVUTIL 1) - list(APPEND ZM_BIN_LIBS "${AVUTIL_LIBRARIES}") - find_path(AVUTIL_INCLUDE_DIR "libavutil/avutil.h" /usr/include/ffmpeg) - if(AVUTIL_INCLUDE_DIR) - include_directories("${AVUTIL_INCLUDE_DIR}") - set(CMAKE_REQUIRED_INCLUDES "${AVUTIL_INCLUDE_DIR}") - endif() - mark_as_advanced(FORCE AVUTIL_LIBRARIES AVUTIL_INCLUDE_DIR) - check_include_file("libavutil/avutil.h" HAVE_LIBAVUTIL_AVUTIL_H) + set(HAVE_LIBAVUTIL_AVUTIL_H 1) + set(CMAKE_REQUIRED_INCLUDES ${FFMPEG_avutil_INCLUDE_DIRS}) check_include_file("libavutil/mathematics.h" HAVE_LIBAVUTIL_MATHEMATICS_H) check_include_file("libavutil/hwcontext.h" HAVE_LIBAVUTIL_HWCONTEXT_H) + list(APPEND ZM_BIN_LIBS "${FFMPEG_avutil_LIBRARIES}") set(optlibsfound "${optlibsfound} AVUtil") else() set(optlibsnotfound "${optlibsnotfound} AVUtil") endif() -# swscale (using find_library and find_path) -find_library(SWSCALE_LIBRARIES swscale) -if(SWSCALE_LIBRARIES) +find_package(FFMPEG COMPONENTS swscale) +if(FFMPEG_swscale_FOUND) set(HAVE_LIBSWSCALE 1) - list(APPEND ZM_BIN_LIBS "${SWSCALE_LIBRARIES}") - find_path(SWSCALE_INCLUDE_DIR "libswscale/swscale.h" /usr/include/ffmpeg) - if(SWSCALE_INCLUDE_DIR) - include_directories("${SWSCALE_INCLUDE_DIR}") - set(CMAKE_REQUIRED_INCLUDES "${SWSCALE_INCLUDE_DIR}") - endif() - mark_as_advanced(FORCE SWSCALE_LIBRARIES SWSCALE_INCLUDE_DIR) - check_include_file("libswscale/swscale.h" HAVE_LIBSWSCALE_SWSCALE_H) + set(HAVE_LIBSWSCALE_SWSCALE_H 1) + list(APPEND ZM_BIN_LIBS "${FFMPEG_swscale_LIBRARIES}") set(optlibsfound "${optlibsfound} SWScale") else() set(optlibsnotfound "${optlibsnotfound} SWScale") endif() -# SWresample (using find_library and find_path) -find_library(SWRESAMPLE_LIBRARIES swresample) -if(SWRESAMPLE_LIBRARIES) +find_package(FFMPEG COMPONENTS swresample) +if(FFMPEG_swresample_FOUND) set(HAVE_LIBSWRESAMPLE 1) - list(APPEND ZM_BIN_LIBS "${SWRESAMPLE_LIBRARIES}") - find_path(SWRESAMPLE_INCLUDE_DIR "libswresample/swresample.h" /usr/include/ffmpeg) - if(SWRESAMPLE_INCLUDE_DIR) - include_directories("${SWRESAMPLE_INCLUDE_DIR}") - set(CMAKE_REQUIRED_INCLUDES "${SWRESAMPLE_INCLUDE_DIR}") - endif() - mark_as_advanced(FORCE SWRESAMPLE_LIBRARIES SWRESAMPLE_INCLUDE_DIR) - check_include_file("libswresample/swresample.h" HAVE_LIBSWRESAMPLE_SWRESAMPLE_H) + set(HAVE_LIBSWRESAMPLE_SWRESAMPLE_H 1) + list(APPEND ZM_BIN_LIBS "${FFMPEG_swresample_LIBRARIES}") set(optlibsfound "${optlibsfound} SWResample") else() set(optlibsnotfound "${optlibsnotfound} SWResample") - # AVresample (using find_library and find_path) - find_library(AVRESAMPLE_LIBRARIES avresample) - if(AVRESAMPLE_LIBRARIES) + find_package(FFMPEG COMPONENTS avresample) + if(FFMPEG_avresample_FOUND) set(HAVE_LIBAVRESAMPLE 1) - list(APPEND ZM_BIN_LIBS "${AVRESAMPLE_LIBRARIES}") - find_path(AVRESAMPLE_INCLUDE_DIR "libavresample/avresample.h" /usr/include/ffmpeg) - if(AVRESAMPLE_INCLUDE_DIR) - include_directories("${AVRESAMPLE_INCLUDE_DIR}") - set(CMAKE_REQUIRED_INCLUDES "${AVRESAMPLE_INCLUDE_DIR}") - endif() - mark_as_advanced(FORCE AVRESAMPLE_LIBRARIES AVRESAMPLE_INCLUDE_DIR) - check_include_file("libavresample/avresample.h" HAVE_LIBAVRESAMPLE_AVRESAMPLE_H) + set(HAVE_LIBAVRESAMPLE_AVRESAMPLE_H 1) + list(APPEND ZM_BIN_LIBS "${FFMPEG_avresample_LIBRARIES}") set(optlibsfound "${optlibsfound} AVResample") else() set(optlibsnotfound "${optlibsnotfound} AVResample") endif() endif() +set(PATH_FFMPEG "") +set(OPT_FFMPEG "no") + # Find the path to the ffmpeg executable find_program(FFMPEG_EXECUTABLE NAMES ffmpeg avconv diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1eb24a7fc..b6d3ce1fb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,6 +80,7 @@ target_link_libraries(zm libbcrypt::bcrypt RtspServer::RtspServer martinmoene::span-lite + ${ZM_BIN_LIBS} PRIVATE zm-core-interface) @@ -102,7 +103,6 @@ target_link_libraries(zmc zm-core-interface zm ${ZM_EXTRA_LIBS} - ${ZM_BIN_LIBS} ${CMAKE_DL_LIBS}) target_link_libraries(zms @@ -110,7 +110,6 @@ target_link_libraries(zms zm-core-interface zm ${ZM_EXTRA_LIBS} - ${ZM_BIN_LIBS} ${CMAKE_DL_LIBS}) target_link_libraries(zmu @@ -118,9 +117,7 @@ target_link_libraries(zmu zm-core-interface zm ${ZM_EXTRA_LIBS} - ${ZM_BIN_LIBS} - ${CMAKE_DL_LIBS} - bcrypt) + ${CMAKE_DL_LIBS}) # Generate man files for the binaries destined for the bin folder if(BUILD_MAN) @@ -141,8 +138,6 @@ if(HAVE_RTSP_SERVER) zm-core-interface zm ${ZM_EXTRA_LIBS} - ${ZM_BIN_LIBS} - ${CMAKE_DL_LIBS} - bcrypt) + ${CMAKE_DL_LIBS}) install(TARGETS zm_rtsp_server RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endif()