mirror of
https://github.com/opencv/opencv.git
synced 2024-12-03 00:10:21 +08:00
c9f3f4d1d3
Avoid non-intentional call of "include(FindPkgConfig)" It should be handled in the root CMakeLists.txt (safely for cross-compiling)
74 lines
2.4 KiB
CMake
74 lines
2.4 KiB
CMake
#=============================================
|
|
# 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()
|