mirror of
https://github.com/opencv/opencv.git
synced 2024-11-23 18:50:21 +08:00
cmake: fix pkg-config handling
Avoid non-intentional call of "include(FindPkgConfig)" It should be handled in the root CMakeLists.txt (safely for cross-compiling)
This commit is contained in:
parent
d0032b0717
commit
c9f3f4d1d3
@ -698,7 +698,7 @@ ocv_cmake_hook(POST_COMPILER_OPTIONS)
|
||||
# ----------------------------------------------------------------------------
|
||||
if(UNIX)
|
||||
if(NOT APPLE_FRAMEWORK OR OPENCV_ENABLE_PKG_CONFIG)
|
||||
if(CMAKE_CROSSCOMPILING AND NOT DEFINED ENV{PKG_CONFIG_LIBDIR}
|
||||
if(CMAKE_CROSSCOMPILING AND NOT DEFINED ENV{PKG_CONFIG_LIBDIR} AND NOT DEFINED ENV{PKG_CONFIG_SYSROOT_DIR}
|
||||
AND NOT OPENCV_ENABLE_PKG_CONFIG
|
||||
)
|
||||
if(NOT PkgConfig_FOUND)
|
||||
|
@ -743,7 +743,7 @@ macro(ocv_check_modules define)
|
||||
endif()
|
||||
unset(${define}_${__modname}_FOUND)
|
||||
endforeach()
|
||||
if(COMMAND pkg_check_modules)
|
||||
if(PKG_CONFIG_FOUND OR PkgConfig_FOUND)
|
||||
pkg_check_modules(${define} ${ARGN})
|
||||
endif()
|
||||
if(${define}_FOUND)
|
||||
|
@ -19,8 +19,6 @@ function(ocv_add_external_target name inc link def)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
include(FindPkgConfig)
|
||||
|
||||
add_backend("ffmpeg" WITH_FFMPEG)
|
||||
add_backend("gstreamer" WITH_GSTREAMER)
|
||||
add_backend("v4l" WITH_V4L)
|
||||
|
@ -1,7 +1,3 @@
|
||||
#=============================================
|
||||
# build with OpenCV
|
||||
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVUtils.cmake")
|
||||
|
||||
function(ocv_create_builtin_videoio_plugin name target videoio_src_file)
|
||||
|
||||
ocv_debug_message("ocv_create_builtin_videoio_plugin(${ARGV})")
|
||||
@ -36,71 +32,3 @@ function(ocv_create_builtin_videoio_plugin name target videoio_src_file)
|
||||
add_dependencies(opencv_videoio_plugins ${name})
|
||||
|
||||
endfunction()
|
||||
|
||||
#=============================================
|
||||
# standalone build
|
||||
|
||||
function(ocv_create_videoio_plugin default_name target target_desc videoio_src_file)
|
||||
|
||||
set(OPENCV_PLUGIN_NAME ${default_name} CACHE STRING "")
|
||||
set(OPENCV_PLUGIN_DESTINATION "" CACHE PATH "")
|
||||
project(${OPENCV_PLUGIN_NAME} LANGUAGES CXX)
|
||||
|
||||
set(BUILD_SHARED_LIBS ON CACHE BOOL "")
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "Static plugin build does not make sense")
|
||||
endif()
|
||||
|
||||
if(NOT OpenCV_SOURCE_DIR)
|
||||
message(FATAL_ERROR "OpenCV_SOURCE_DIR must be set to build the plugin!")
|
||||
endif()
|
||||
|
||||
include("${OpenCV_SOURCE_DIR}/modules/videoio/cmake/init.cmake")
|
||||
|
||||
if(NOT TARGET ${target})
|
||||
message(FATAL_ERROR "${target_desc} was not found!")
|
||||
endif()
|
||||
|
||||
set(modules_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../..")
|
||||
set(videoio_ROOT "${modules_ROOT}/videoio")
|
||||
set(core_ROOT "${modules_ROOT}/core")
|
||||
set(imgproc_ROOT "${modules_ROOT}/imgproc")
|
||||
set(imgcodecs_ROOT "${modules_ROOT}/imgcodecs")
|
||||
|
||||
add_library(${OPENCV_PLUGIN_NAME} MODULE "${videoio_ROOT}/src/${videoio_src_file}")
|
||||
target_include_directories(${OPENCV_PLUGIN_NAME} PRIVATE
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"${videoio_ROOT}/src"
|
||||
"${videoio_ROOT}/include"
|
||||
"${core_ROOT}/include"
|
||||
"${imgproc_ROOT}/include"
|
||||
"${imgcodecs_ROOT}/include"
|
||||
)
|
||||
target_compile_definitions(${OPENCV_PLUGIN_NAME} PRIVATE BUILD_PLUGIN)
|
||||
|
||||
# Fixes for build
|
||||
target_compile_definitions(${OPENCV_PLUGIN_NAME} PRIVATE __OPENCV_BUILD)
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cvconfig.h" "#pragma once")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cv_cpu_config.h" "#pragma once")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/opencv2/opencv_modules.hpp" "#pragma once")
|
||||
|
||||
target_link_libraries(${OPENCV_PLUGIN_NAME} PRIVATE ${target})
|
||||
set_target_properties(${OPENCV_PLUGIN_NAME} PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
CXX_VISIBILITY_PRESET hidden
|
||||
)
|
||||
|
||||
# Hack for Windows
|
||||
if(WIN32)
|
||||
find_package(OpenCV REQUIRED core imgproc videoio)
|
||||
target_link_libraries(${OPENCV_PLUGIN_NAME} ${OpenCV_LIBS})
|
||||
endif()
|
||||
|
||||
if(OPENCV_PLUGIN_DESTINATION)
|
||||
set_target_properties(${OPENCV_PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${OPENCV_PLUGIN_DESTINATION}")
|
||||
message(STATUS "Output destination: ${OPENCV_PLUGIN_DESTINATION}")
|
||||
endif()
|
||||
|
||||
message(STATUS "Library name: ${OPENCV_PLUGIN_NAME}")
|
||||
|
||||
endfunction()
|
||||
|
73
modules/videoio/cmake/plugin_standalone.cmake
Normal file
73
modules/videoio/cmake/plugin_standalone.cmake
Normal file
@ -0,0 +1,73 @@
|
||||
#=============================================
|
||||
# standalone build
|
||||
|
||||
include(FindPkgConfig)
|
||||
|
||||
#=============================================
|
||||
# build with OpenCV
|
||||
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVUtils.cmake")
|
||||
|
||||
function(ocv_create_videoio_plugin default_name target target_desc videoio_src_file)
|
||||
|
||||
set(OPENCV_PLUGIN_NAME ${default_name} CACHE STRING "")
|
||||
set(OPENCV_PLUGIN_DESTINATION "" CACHE PATH "")
|
||||
project(${OPENCV_PLUGIN_NAME} LANGUAGES CXX)
|
||||
|
||||
set(BUILD_SHARED_LIBS ON CACHE BOOL "")
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "Static plugin build does not make sense")
|
||||
endif()
|
||||
|
||||
if(NOT OpenCV_SOURCE_DIR)
|
||||
message(FATAL_ERROR "OpenCV_SOURCE_DIR must be set to build the plugin!")
|
||||
endif()
|
||||
|
||||
include("${OpenCV_SOURCE_DIR}/modules/videoio/cmake/init.cmake")
|
||||
|
||||
if(NOT TARGET ${target})
|
||||
message(FATAL_ERROR "${target_desc} was not found!")
|
||||
endif()
|
||||
|
||||
set(modules_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../..")
|
||||
set(videoio_ROOT "${modules_ROOT}/videoio")
|
||||
set(core_ROOT "${modules_ROOT}/core")
|
||||
set(imgproc_ROOT "${modules_ROOT}/imgproc")
|
||||
set(imgcodecs_ROOT "${modules_ROOT}/imgcodecs")
|
||||
|
||||
add_library(${OPENCV_PLUGIN_NAME} MODULE "${videoio_ROOT}/src/${videoio_src_file}")
|
||||
target_include_directories(${OPENCV_PLUGIN_NAME} PRIVATE
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"${videoio_ROOT}/src"
|
||||
"${videoio_ROOT}/include"
|
||||
"${core_ROOT}/include"
|
||||
"${imgproc_ROOT}/include"
|
||||
"${imgcodecs_ROOT}/include"
|
||||
)
|
||||
target_compile_definitions(${OPENCV_PLUGIN_NAME} PRIVATE BUILD_PLUGIN)
|
||||
|
||||
# Fixes for build
|
||||
target_compile_definitions(${OPENCV_PLUGIN_NAME} PRIVATE __OPENCV_BUILD)
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cvconfig.h" "#pragma once")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cv_cpu_config.h" "#pragma once")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/opencv2/opencv_modules.hpp" "#pragma once")
|
||||
|
||||
target_link_libraries(${OPENCV_PLUGIN_NAME} PRIVATE ${target})
|
||||
set_target_properties(${OPENCV_PLUGIN_NAME} PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
CXX_VISIBILITY_PRESET hidden
|
||||
)
|
||||
|
||||
# Hack for Windows
|
||||
if(WIN32)
|
||||
find_package(OpenCV REQUIRED core imgproc videoio)
|
||||
target_link_libraries(${OPENCV_PLUGIN_NAME} ${OpenCV_LIBS})
|
||||
endif()
|
||||
|
||||
if(OPENCV_PLUGIN_DESTINATION)
|
||||
set_target_properties(${OPENCV_PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${OPENCV_PLUGIN_DESTINATION}")
|
||||
message(STATUS "Output destination: ${OPENCV_PLUGIN_DESTINATION}")
|
||||
endif()
|
||||
|
||||
message(STATUS "Library name: ${OPENCV_PLUGIN_NAME}")
|
||||
|
||||
endfunction()
|
@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5)
|
||||
set(OpenCV_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../..")
|
||||
set(WITH_FFMPEG ON)
|
||||
set(OPENCV_FFMPEG_SKIP_BUILD_CHECK ON)
|
||||
include("${OpenCV_SOURCE_DIR}/modules/videoio/cmake/plugin.cmake")
|
||||
include("${OpenCV_SOURCE_DIR}/modules/videoio/cmake/plugin_standalone.cmake")
|
||||
ocv_create_videoio_plugin("opencv_videoio_ffmpeg" "ocv.3rdparty.ffmpeg" "FFmpeg" "cap_ffmpeg.cpp")
|
||||
|
||||
message(STATUS "FFMPEG_libavcodec_VERSION=${FFMPEG_libavcodec_VERSION}")
|
||||
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(OpenCV_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../..")
|
||||
set(WITH_GSTREAMER ON)
|
||||
include("${OpenCV_SOURCE_DIR}/modules/videoio/cmake/plugin.cmake")
|
||||
include("${OpenCV_SOURCE_DIR}/modules/videoio/cmake/plugin_standalone.cmake")
|
||||
ocv_create_videoio_plugin("opencv_videoio_gstreamer" "ocv.3rdparty.gstreamer" "GStreamer" "cap_gstreamer.cpp")
|
||||
|
||||
message(STATUS "Using GStreamer: ${GSTREAMER_VERSION}")
|
||||
|
Loading…
Reference in New Issue
Block a user